forked from RezaSi/go-interview-practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution-template.go
More file actions
136 lines (113 loc) · 3.37 KB
/
solution-template.go
File metadata and controls
136 lines (113 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Package challenge10 contains the solution for Challenge 10.
package challenge10
import (
"fmt"
// Add any necessary imports here
)
// Shape interface defines methods that all shapes must implement
type Shape interface {
Area() float64
Perimeter() float64
fmt.Stringer // Includes String() string method
}
// Rectangle represents a four-sided shape with perpendicular sides
type Rectangle struct {
Width float64
Height float64
}
// NewRectangle creates a new Rectangle with validation
func NewRectangle(width, height float64) (*Rectangle, error) {
// TODO: Implement validation and construction
return nil, nil
}
// Area calculates the area of the rectangle
func (r *Rectangle) Area() float64 {
// TODO: Implement area calculation
return 0
}
// Perimeter calculates the perimeter of the rectangle
func (r *Rectangle) Perimeter() float64 {
// TODO: Implement perimeter calculation
return 0
}
// String returns a string representation of the rectangle
func (r *Rectangle) String() string {
// TODO: Implement string representation
return ""
}
// Circle represents a perfectly round shape
type Circle struct {
Radius float64
}
// NewCircle creates a new Circle with validation
func NewCircle(radius float64) (*Circle, error) {
// TODO: Implement validation and construction
return nil, nil
}
// Area calculates the area of the circle
func (c *Circle) Area() float64 {
// TODO: Implement area calculation
return 0
}
// Perimeter calculates the circumference of the circle
func (c *Circle) Perimeter() float64 {
// TODO: Implement perimeter calculation
return 0
}
// String returns a string representation of the circle
func (c *Circle) String() string {
// TODO: Implement string representation
return ""
}
// Triangle represents a three-sided polygon
type Triangle struct {
SideA float64
SideB float64
SideC float64
}
// NewTriangle creates a new Triangle with validation
func NewTriangle(a, b, c float64) (*Triangle, error) {
// TODO: Implement validation and construction
return nil, nil
}
// Area calculates the area of the triangle using Heron's formula
func (t *Triangle) Area() float64 {
// TODO: Implement area calculation using Heron's formula
return 0
}
// Perimeter calculates the perimeter of the triangle
func (t *Triangle) Perimeter() float64 {
// TODO: Implement perimeter calculation
return 0
}
// String returns a string representation of the triangle
func (t *Triangle) String() string {
// TODO: Implement string representation
return ""
}
// ShapeCalculator provides utility functions for shapes
type ShapeCalculator struct{}
// NewShapeCalculator creates a new ShapeCalculator
func NewShapeCalculator() *ShapeCalculator {
// TODO: Implement constructor
return nil
}
// PrintProperties prints the properties of a shape
func (sc *ShapeCalculator) PrintProperties(s Shape) {
// TODO: Implement printing shape properties
}
// TotalArea calculates the sum of areas of all shapes
func (sc *ShapeCalculator) TotalArea(shapes []Shape) float64 {
// TODO: Implement total area calculation
return 0
}
// LargestShape finds the shape with the largest area
func (sc *ShapeCalculator) LargestShape(shapes []Shape) Shape {
// TODO: Implement finding largest shape
return nil
}
// SortByArea sorts shapes by area in ascending or descending order
func (sc *ShapeCalculator) SortByArea(shapes []Shape, ascending bool) []Shape {
// TODO: Implement sorting shapes by area
return nil
}