go代写 go代做 go程序作业代写 go程序代写

go代写 go编程代写 go语言assignment代写

                                                                                                                                               

Exercise 9

                                               

Download and extract the code skeleton for this exercise. As last week, the code includes an outline of how to organize your work and some tests.

                                                                                                                                                                                               

Go Get

                                               

The tests provided for this exercise use the assert package
excellent, but not part of the standard library. It will give us a chance to see how easily Go can install external dependencies:

                                               

    go get github.com/stretchr/testify/assert

                                               

Mutating Methods


which is Our Point class from last week was effectively immutable (from outside the package) since there were no exported members, and not methods that changed its state.


Let's add some methods that change the Point in place. In order to modify the struct, a method must
argument. Feel free to copy your Point implementation from last week,

                 

and in points.go, to exer9 and... Scale


Add a .Scale(f) method to the Point from last week. It should change an existing point in place and stretch it by a factor of f. For example:


p := Point{1, 2}    
p.Scale(5)    
fmt.Println(p)

  ... should print (5, 10).

                                               

Rotate

We can add another transformation to a Point: rotation. We would like to call .Rotate(angle) and have the point rotated by angle radians around the origin. For angle , the transformation is:                                                                                                                                                                            

The  result should be that this code:

                                               

p := Point{1, 0} 
p.Rotate(math.Pi / 2) 
fmt.Println(p) 
p.Rotate(math.Pi / 2) 
fmt.Println(p)

                                                                                                                                                            

... should print (0, 1) and (-1, 0) (but probably not exactly due to floating-point error, but the results will be close to these values).

           

Random Arrays

                    

We want to generate some random arrays. In array_stats.go, write a function that creates and returns an array with length integers and values from 0 to maxInt-1 with this signature:

                                                                                                                                                                                               

func RandomArray(length int, maxInt int) []int { ... }

                                                                                                               


京ICP备2025144562号-1
微信
程序代写,编程代写
使用微信扫一扫关注
在线客服
欢迎在线资讯
联系时间: 全天