In this homework you will write a series of programs using Go. The second will build on the first, etc. Submit each part as if they were completely independent. In other words, each part should be in a single .go file that is runnable independently of any other .go file.

A suggestion. In homework 1 you set up a system for being able to use VSC on you local machine to work with files on the lab machines. Use that system. In particular, create a new directory within the 245 directory you created in homework 1, presumably called something like "HW2".

Through this assignment you will be building a series of programs that hold information about rocket launches. A description of the columns in this data is given in the following table.
Column number id type description
1 identifier string a unique id
2 something floating point number I have no idea what this means
3 year integer the year
4 month integer month 1==January, etc
5 day integer day of month. First day of month is 1
6 vehicle string the type of rocket
7 variant string The variant of the rocket -- for instance, how many boosters does it have
8 flight string A descriptor of the flight. Often unintelligible.
9 mission string A descriptor of the mission. Often unintelligible.
10 launch site string The location of the rocket launch
11 launchpad string the place within the location
12 apogee integer max distance from earth
13 category string I am sure that this is meaningful, just not to me.

Part 1 -- Structs: 30%

Write a program that does the following:

Part 2 -- CSV files: 30%

There is a CSV (CSV = Comma Separated Values) file containing information of the above form. It is available at
        /home/gtowell/Public/CS245/HW2/hl.csv
    
Read the contents of this CSV file into structs that are stored in a slice. I strongly recommend reading the CSV file using packages supplied with the Go language. (Note there are some unofficial; packages that might allow you to marshall the CSV file directly into structs. You may try to use these, but I do not recommend it.) Here is an example program for reading a CSV file:
        package main

import (
	"encoding/csv"
	"fmt"
	"os"
)

func main() {

    // os.Open() opens specific file in
    // read-only mode and this return
    // a pointer of type os.File
    file, err := os.Open("the.csv")

    // Checks for the error
    if err != nil {
        fmt.Printf("Error while reading the file %v\n", err)
    }

    // Closes the file
    defer file.Close()

    // The csv.NewReader() function is called in
    // which the object os.File passed as its parameter
    // and this creates a new csv.Reader that reads
    // from the file
    reader := csv.NewReader(file)

    // ReadAll reads all the records from the CSV file
    // and Returns them as slice of slices of string
    // and an error if any
    records, err := reader.ReadAll()

    // Checks for the error
    if err != nil {
        fmt.Println("Error reading records")
    }

    // Loop to iterate through
    // and print each of the string slice
    for _, eachrecord := range records {
        fmt.Println(eachrecord)
    }
    
I largely copied this program from https://www.geeksforgeeks.org/how-to-read-a-csv-file-in-golang/. There is a little more explanation on this page.

Use your Print function -- from part 1 -- to confirm that you are reading this file correctly.

Part 3 -- Slices: 15%

With the slice, do the following

Part 3 -- Questions: 25%

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.
  1. 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?
  2. From part 3: 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.

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, everything you write in the README.

The easiest place to write your readme is within VSC. Make a file just like a code file but name it README.txt (or just README) then just write in it. You should start by copying the sample readme. Put the README file into the HW2 directory.

Submit

These directions assume that you followed the suggestions above and have a directory named HW2 inside a 245 directory on the UNIX servers.

  1. Open a terminal window on your computer (a windows powershell or a Mac terminal)
  2. if it is still on your local machine, copy the PDF file of your report into the HW2 directory on the UNIX servers. To do so:
    1. first put the PDF (or test file) into the place where you are in the terminal (or switch the terminal to the place where the PDF file is).
    2. Second copy the file over to UNIX. I assume the pdf file is names "report2.pdf". To do this (assuming things from homework 1)
          scp report2.pdf lab186:245/HW2
      
    3. Use similar scp commands to get any other files from your local machine to the UNIX machines
  3. When all of the files are in the HW2 directory and you are still in the 245 directory
        /home/gtowell/bin/submit  -c 245 -p 2 -d HW2
            
    This says to submit for project 2 (-p) everything in the directory HW2 (-d) for the class 245 (-c). You should see listing of all the files you submitted and a message that says "success".
  4. 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 gtowell@brynmawr.edu with all of your files attached. I will accept this for assignment 2 ONLY. You should also find me so that we can work out what went wrong and so that it does not go wrong next time.

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 HW2 directory within /home/YOU/245/

  1. Go to the directory /home/YOU/245
  2. Enter /home/gtowell/bin/submit -c 245 -p 2 -d HW2
If this worked you will get a message with the word "success".