- Write a program that creates 2 custom struct types:
triangle
square
- The
square
type should be a struct with a field calledsideLength
of typefloat64
- The
triangle
type should be a struct with a field calledheight
of typefloat64
and a field calledbase
of typefloat64
- Both types should have function called
getArea
that returns the calculated area of the square or triangle- Area of Triangle = 0.5 base height
- Area of Square = sideLength * sideLength
- Add a
shape
interface that defines a function calledprintArea
- This function should calculate the area of the given shape and print out to the terminal
- Design the interface so that the
printArea
function can be called with either a triangle or a square
- Create a program that reads the contents of a text file then print its contents to the terminal
- The file to open should be provider as an argument to the program when it is executed at the terminal
- For example,
go run main.go myfile.txt
- To read-in the arguments provided to a program, you can reference the variable
os.Args
, which is a slice of strings - To open a file, check out the documentation for the
Open
function in theos
package - What interfaces does the
File
type implement? - If the
File
type implements theReader
interface, you might be able to reuse thatio.Copy
function