mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.3 KiB
53 lines
1.3 KiB
5 years ago
|
## Rectangle
|
||
5 years ago
|
|
||
5 years ago
|
### Instructions
|
||
5 years ago
|
|
||
![]()
4 years ago
|
Consider that a point is defined by its coordinates and that a rectangle is defined by the points of the upper left and lower right corners.
|
||
5 years ago
|
|
||
5 years ago
|
- Define two structures named, `point` and `rectangle`.
|
||
5 years ago
|
|
||
5 years ago
|
- The struct `point` has to have two variables, `x` and `y`, type `int`.
|
||
5 years ago
|
|
||
5 years ago
|
- The struct `rectangle` has to have two variables, `upLeft` and `downRight` type `point`.
|
||
5 years ago
|
|
||
5 years ago
|
- The goal is to make a program that:
|
||
|
- Given a slice of points of size `n` returns the smallest rectangle that contains all the points in the vector of points. The name of that function is `defineRectangle`.
|
||
|
- And which calculates and prints the area of that rectangle you define.
|
||
5 years ago
|
|
||
5 years ago
|
### Expected main and function for the program
|
||
5 years ago
|
|
||
|
```go
|
||
|
func defineRectangle(ptr *point, n int) *rectangle {
|
||
5 years ago
|
|
||
5 years ago
|
}
|
||
|
|
||
|
func calArea(ptr *rectangle) int {
|
||
5 years ago
|
|
||
5 years ago
|
}
|
||
|
|
||
|
func main() {
|
||
5 years ago
|
vPoint := []point{}
|
||
5 years ago
|
rectangle := &rectangle{}
|
||
|
n := 7
|
||
|
|
||
|
for i := 0; i < n; i++ {
|
||
|
val := point{
|
||
5 years ago
|
x: i%2 + 1,
|
||
5 years ago
|
y: i + 2,
|
||
|
}
|
||
|
vPoint = append(vPoint, val)
|
||
|
}
|
||
|
rectangle = defineRectangle(vPoint, n)
|
||
|
fmt.Println("area of the rectangle:", calArea(rectangle))
|
||
|
}
|
||
|
```
|
||
|
|
||
![]()
4 years ago
|
### Usage
|
||
5 years ago
|
|
||
|
```console
|
||
5 years ago
|
student@ubuntu:~/[[ROOT]]/test$ go build
|
||
|
student@ubuntu:~/[[ROOT]]/test$ ./test
|
||
5 years ago
|
area of the rectangle: 6
|
||
5 years ago
|
student@ubuntu:~/[[ROOT]]/test$
|
||
5 years ago
|
```
|