Lab Assignment--Command-Line Linux


Part 1-Linux/Unix Commands

Follow all of the steps:
  1. log onto Linux
  2. start a script in your home directory
  3. in your cs330 lab directory create three new directories named 'weather', 'assignment', and 'web'
  4. change the permissions of the directory 'web' to -rwx r-x r-x using the octal form of chmod
  5. change your working directory to weather
  6. without using a text editor create three files called 'today', 'tomorrow', and 'deer'
  7. check the permissions with ls -l
  8. change the permissions of 'deer' to -rwx r-- r--
  9. change the permissions of 'today' to -rw- r-- r--
  10. check the permissions with ls -l
  11. create a hard link of 'deer' and name it 'good'
  12. check the hard link with ls -i
  13. create a directory named 'cars'
  14. move the file 'good' to the directory 'cars' and rename it 'today2'
  15. change working directory to 'cars'
  16. create a symbolic link to today2 and name it today3
  17. check permissions with ls -l
  18. move up one directory
  19. remove the directory 'cars' and its contents
  20. exit from the script

Part 2-Create a Simple C++ program

The goal of this part of the exercise to get you used to the command-line compiler and C++ code again. You also practice using diff to see if your output is an exact match for the input given.

Create C++ code around the following class:

class Student
{
 private:
  string fullName;
  int assgn1;
  int assgn2;
  int midterm;
  int final;
  int grade;

 public:
  void setName(string);
  void setAssgn1(int);
  void setAssgn2(int);
  void setMidterm(int);
  void setFinal(int);
  void calcGrade();  //grade = rounded up average of assgn1, assgn2, midterm,and final
  string getName();
  int getGrade();
};

As an overview, you will dynamically allocate an array of Student objects based on input from the user. You will then read keyboard input (like this) to assign values to the array of Students. Finally, you will print the student name and average grade(your output will look like this). Further details are provided below:

  1. Define the functions that go with the class. Remember to use the syntax:
    void Student::setName(string theString)

  2. In main, read in the number of students (num)

  3. Dynamically allocate space for an array of num students. Hint: to dynamically declare an array of integers you use the syntax:
    int* weightPtr = new int [3]; //instead of int what will you use?

  4. Loop for the number of students (num) and accept input in the form of:
    Name
    Assignment 1 grade
    Assignment 2 grade
    Midterm grade
    Final exam grade
  5. Output a header:
    +----------------------------------------+     
    + Name                           + Grade +
    +-----------------------------------------
    where there are exactly 40 hyphens in the first and third lines

  6. Loop for the number of students (num) and print out the student's name left justified and the grade right justified.
  7. Output the ending footer (same as the first line of the header)

  8. Deallocate the space for the array of students. Hint: to deallocate the int array from above, we would use:
    delete [] weightPtr;

Validating using diff

Once you are happy that your code is working, we will use diff to see how correctly you have formatted your output:

  1. Use the following commands to copy the files:
    cp /net/data/ftp/pub/class/330/Linux/Exercise/in.txt .
    cp /net/data/ftp/pub/class/330/Linux/Exercise/out.txt .
  2. Instead of getting input from the keyboard, you can use the contents of in.txt using:
    myprogram < in.txt
  3. Instead of writing the output to the screen, you can redirect it to mine.txt using:
    myprogram < in.txt > mine.txt
  4. Now, try a diff:
    diff mine.txt out.txt
    There should be no output.

Deliverables: