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.
id |
type |
description |
year |
integer |
the year |
month |
integer |
month 1==January, etc |
day |
integer |
day of month. First day of month is 1 |
deptime |
integer |
departure time in 24 clock without a colon. So 715 is 7:15am and 2355 is 11:55pm |
arrtime |
integer |
as with departure time |
carrier |
string |
a short string giving the airline ID. |
flightnum |
integer |
the flight number |
arrdelay |
arrival delay |
in minutes. Negative number indicates early arrival. |
depdelay |
integer |
in minutes |
origin |
string |
ID of the originating airport. If not PHL, then an arrival |
destination |
string |
ID of the destination airport. If not PHL, then a departure. |
distance |
integer |
the length of the flight, in miles |
cancelled |
boolean |
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.
2008,1,3,1734,1941,WN,23,36,44,JAX,PHL,742,false
2008,1,3,712,926,WN,1232,11,12,JAX,PHL,742,false
2008,1,3,1127,1856,WN,1285,21,42,LAS,PHL,2176,true
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
Java?
- 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
"%+v"
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.
2008,12,12,1834,2149,DL,1687,86,69,PHL,SLC,1926,true
2008,12,12,944,1555,DL,1776,-10,-1,SLC,PHL,1926,true
2008,12,13,1221,1413,DL,692,-9,-4,ATL,PHL,665,true
2008,12,5,1523,1804,AA,1768,-21,3,ORD,PHL,678,true
2008,12,6,1628,1933,AA,1768,-7,-2,ORD,PHL,678,true
2008,12,7,1520,1804,AA,1768,-21,0,ORD,PHL,678,true
2008,12,22,545,839,CO,1677,19,10,PHL,IAH,1324,true
2008,12,22,1920,2314,CO,1776,-16,0,IAH,PHL,1324,true
2008,12,22,723,952,CO,1777,3,18,PHL,IAH,1324,true
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.
3
Electronic Submissions
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.
Submit
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:
- 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
165.106.10.186 -- you can use any machine. To connect:
ssh YOURNAME@165.106.10.186
or
ssh lab186
Enter your Unix password if/when prompted
- On the linux computer:
cd cs245
mkdir a1
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@165.106.10.186: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
first steps)
ls a1
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.
If the submission deadline is approaching and you cannot get this process to work, send email
gtowell245@cs.brynmawr.edu with all of your files attached. I will accept this for assignment 1 ONLY.
The submission should include the following items:
- README:
- 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
files.
Again: Once you have everything you want to submit in the a1 directory within
/home/YOU/cs245/
- Go to the directory /home/YOU/cs245
- Enter /home/gtowell/bin/submit -c 245 -p 1 -d a1
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.