In this homework you will write a series of programs using Go. The second will build on the first, etc. But submit
each part as if they were completely independent. Each part should be in a single .go file that is runnable
independent of any other .go file.
Through this assignment you will be building a series of programs that hold, and read, information about
aircraft takeoffs and landings. The information to hold is given in the following table.
||month 1==January, etc
||day of month. First day of month is 1
||departure time in 24 clock without a colon. So 715 is 7:15am and 2355 is 11:55pm
||as with departure time
||a short string giving the airline ID.
||the flight number
||in minutes. Negative number indicates early arrival.
||ID of the originating airport. If not PHL, then an arrival
||ID of the destination airport. If not PHL, then a departure.
||the length of the flight, in miles
||true if the flight was cancelled
Throughout this assignment, all printing should be done using fmt.Printf rather than fmt.Println. For the
String() method (below) use fmt.Sprintf.
Part 1 -- Structs: 33%
Write a program that does the following:
- Define a set of structs that holds the information in the table above. The set must consist of at least two
structs, one of which is used by the other.
- Construct instances of the struct with the following data.
Just hard code this data into your program. Store the instances of structs you created in 3 different
variables (ie, a, b and c)
- Test if the three instances are equal to each other (I know that they aren't. Show that they are not
programmatically.) You can do this with just ==.
- Create a copy of one of the instances. You can do this with just :=
- Test that copy has the same content as the original (it should be). You should be able to use a simple
equality thest for this.
- Change the value of a field in the copy
- Are the original and the copy still equal? Would the original and copy still be equal if you were using
- Write String methods for each struct. (String() methods in Go are equivalent to toString() in Java.) In your
String method use fmt.Sprintf. Your string method should prduce output similar to (but not identical) to
Part 2 -- Slices: 33%
Take the program from part 1 and adapt it so that the data is stored in a slice structure rather than 3 independent
variables. Create several more data items so you have a total of at least 10. Here is some more data.
With the slice, do the following
- Create a (sub)slice that has only the first 5 items. This should require one line of code
- Create a (sub)slice that has only the last 5 items. This should require one line of code.
- Create a slice that has the first 3 and the last 2 data items. This will require more than one line of code.
Part 3 -- Questions: 33%
Provide answers to the following questions (also provide an answer to the question posed in part 1). You answers may
be in your readme file, another text file, or a PDF. If not in the readme, be sure to say in the readme what file
contains the answers to the questions.
- From part 1: Explain your answer to "Are the original and the copy equal?" As a part of your explanation
discuss how a copy of a struct differs from a similarly made copy of an object in Java?
- From part 2: Consider the original slice and the slice with the first 5 items. Are the items in position 1
of the two slices equal (the answer should be yes)? If you change the value of a field in the struct in
position 1 of the original slice, is it still equal to the item in position 1 of the second slice? Explain
why the answer to this question makes sense with respect to your answer to the first question.
Your submission will be handed in using the submit script.
If you write your program on computers other than those in the lab, be aware that your program will
be graded based on how it runs on the
department’s Linux server, not how it runs on your computer. The most likely problem is not
submitting everything or hard coding file locations that are not correct on the Linux servers.
Make a README
Once you have finished coding (and fully commenting your code) make a README file. This file should follow the
format of this sample README. This is your opportunity to tell me what went well or
poorly, what is still broken and why, etc. I will read, and often respond to, everthing you write in the README.
The easiest place to write your readme is within VSC. Make a file just like a standard java file but name it
README.txt then just write in it. You should start by copying the sample readme.
If you developed this program on your own computer, you should be able to use the systems set up in lab to
help get files to Linux. If you did not get SFTP set up within VSC then do the following:
If the submission deadline is approaching and you cannot get this process to work, send email
firstname.lastname@example.org with all of your files attached. I will accept this for assignment 1 ONLY.
- Open a terminal window on your computer (a windows powershell or a Mac terminal)
- Connect to a linux lab machine. A full list of possibly available lab machines is at Machine list. I will assume you are using
184.108.40.206 -- you can use any machine. To connect:
Enter your Unix password if/when prompted
- On the linux computer:
You can change a1 to whatever you like, the directions below assume a1.
- Leave this terminal window open and connected to Linux, you will use it again in a couple of steps
- Within VSC open a terminal by going to the Terminal menu and selecting "new terminal"
- In the Terminal inside of VSC you should be in the directory containing your program. Enter
scp * YOURNAME@220.127.116.11:cs245/a1
- You should get messages on screen showing that each file in this directory has been copied. Make sure
you get all of the files you want to submit.
- Confirm that the copy was successful. Back in the Terminal you opened on the Linux machines (in the
This should show a list of of the files copied in your scp command.
- When all of the files are in the a1 directory and you are still in the cs245 directory
/home/gtowell/bin/submit -c 245 -p 1 -d a1
This says to submit for project 1 (-p) everything in the directory a1 (-d) for the class
245 (-c). You should see listing of all the files you submitted and a message that says "success".
- You can submit multiple times. I will grade only the last submission -- unless you tell me otherwise.
The submission process attaches a timestamp so I know when you submitted (down to the second). The
closest submission I have ever received to the deadline is 7 seconds.
The submission should include the following items:
- This file should follow the format of this sample README
- Source files
- All of them
- Question answers
- If separate from readme.
- Data files used:
- Be sure to include any non-standard data files uses. (Rare)
DO NOT INCLUDE:
- Data files that are read from the class site. Do include any of your own data
Again: Once you have everything you want to submit in the a1 directory within
If this worked you will get a message with the word "success". If you cannot achieve success and the deadline is
approaching, send me email. We can set up a meeting to work out your problems. The email will establish that you
intended to submit. Once you send the email, do not change the files that you were trying to submit.
- Go to the directory /home/YOU/cs245
- Enter /home/gtowell/bin/submit -c 245 -p 1 -d a1