Lab Assignment--Command-Line Linux
Part 1-Linux/Unix Commands
Follow all of the steps:
- log onto Linux
- start a script in your home directory
- in your cs330 lab directory create three new directories named
'weather', 'assignment', and 'web'
- if you do not have a cs330 lab directory then create it)
- change the permissions of the directory 'web' to -rwx r-x r-x using the
octal form of chmod
- change your working directory to weather
- without using a text editor create three files called 'today', 'tomorrow', and 'deer'
- check the permissions with ls -l
- change the permissions of 'deer' to -rwx r-- r--
- change the permissions of 'today' to -rw- r-- r--
- check the permissions with ls -l
- create a hard link of 'deer' and name it 'good'
- check the hard link with ls -i
- create a directory named 'cars'
- move the file 'good' to the directory 'cars' and rename it 'today2'
- change working directory to 'cars'
- create a symbolic link to today2 and name it today3
- check permissions with ls -l
- move up one directory
- remove the directory 'cars' and its contents
- 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:
void calcGrade(); //grade = rounded up average of assgn1, assgn2, midterm,and final
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:
- Define the functions that go with the class. Remember to use the syntax:
void Student::setName(string theString)
- In main, read in the number of students (num)
- 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 ; //instead of int what will you use?
- Loop for the number of students (num) and accept input in the form of:
Assignment 1 grade
Assignment 2 grade
Final exam grade
Output a header:
- after you have accepted input, you can store the values into the current "Student" and calculate the grade
+ Name + Grade +
where there are exactly 40 hyphens in the first and third lines
Loop for the number of students (num) and print out the student's name left justified and the grade right justified.
Output the ending footer (same as the first line of the header)
- Notice that the Name part is 32 characters wide, but the first and last characters are spaces, so that only 30 characters are taken up by the name
- Notice that the Grade part is 7 characters wide, but the first and last characters are spaces, so that only 5 characters are taken up by the number
- Hint: for formatting, setw(width) and left and right might be useful
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:
- 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 .
- Instead of getting input from the keyboard, you can use the contents of in.txt using:
myprogram < in.txt
- Instead of writing the output to the screen, you can redirect it to mine.txt using:
myprogram < in.txt > mine.txt
- Now, try a diff:
diff mine.txt out.txt
There should be no output.
- Script of Part 1
- Code for Part 2
- Demonstration of compile, run and use of diff for Part2