In lab 1 you should have created a directory called cps6. Change into that directory using the "cd" command by typing "cd cps6" and create another directory called "lab2" using the "mkdir" command by typing "mkdir lab2". Change into the "lab2" directory using the "cd" command by typing "cd lab2". If you did this correctly, when you type "pwd" you should see a long path name that ends with "/cps6/lab2." If you don't see this, then raise your hand.
In order to do this lab, you need to copy some files using the following "cp" (for "copy") command (don't forget the trailing period, or dot):
cp ~dr/cps6/lab2/* .
This command will copy all the files in the directory ~dr/cps6/lab2 into your directory for you to use.
If you type "ls" to list the files now in your lab2 directory, you should see the following files: Makefile, parts.cc and robyn.cc.
For each of the programming problems that follow, you should use the style rules discussed in class, which includes indentation and comments at the top of the file and for each function.
To compile these programs, you will NOT use the g++ command explicitly, but rather implicitly. The file Makefile will make it easier to use the g++ command. To compile the program called robyn.cc, type:
make robyn
This will automatically use the g++ command and link to libraries that you'll need for this assignment. If your program compiles correctly, the executable file called "robyn" will be created. Then you can type "robyn" to run your program.
Problems
> robyn
I'm on a raining twilight coast
Sending out postcards to the one I love
And the rain falls, up from the ground
No one sees it, 'cause there's no one around
Just one thing baby, you forgot my heart
Just one thing baby, you forgot my heart
And I remember when I was young, they said, "Work hard,"
And I said "Indeed, 'cause it's fun"
And so I tried it, I did what I could
Made no difference
It never did any good
Just one thing baby, you forgot my heart
Just one thing baby, you forgot my heart
This program has both syntax errors (found by the compiler) and a logic error (not found by the compiler). Load the file using "emacs," fill in your name, section number and date in the comment section at the top of the program (put this information at the top of every program you write). Compile this program by typing the xemacs& command C-x c (hold the control key down, type x once, let go of control key, and type c), followed by replacing "make -k" (which automatically appears in the mini-buffer at the bottom of the emacs window) by "make robyn" and press return.
This program should not compile because it has some syntax errors. The line numbers near the errors are indicated in an error message. You should correct all syntax errors. You can type
C-x `
and the cursor should jump to a line that is either the line with the error
or the line near the error (maybe the line below). Correct the error and
type C-x ` again to fix the next error. When you have corrected all the errors,
try compiling the program again by typing C-x c. If you still have
errors, again use C-x ` to fix them. When your program compiles, you
can run your program in the xterm window by typing: robyn.
Run the program, and you should see that it does not produce the output above. If a program compiles and runs, but does not produce the correct output, then the program has a logic error.
Correct all logic errors so the program runs correctly. DO NOT rewrite the program, but rather make as few changes as possible to correct the program.
For example, your face might look something like the following (feel free to design your own glasses and beards):
||||||||||||||||
| |
| ____ ____ |
|--| o |-| o|--|
| ---- ---- |
_| |_
|_ _|
| |______| |
| |
||| |||
||| |||
\\\///
"CAUTION:" The "\" (backslash) character is a special character. To print one backslash, you must put two backslashes inside of the double quotes. For example, to print three backslashes, you must put six inside the double quotes. For
cout << "\\\\\\" << endl;
the output will be:
\\\
Submission of programs:
When both of your programs for problems 1 and 3 compile and produce the correct output, create a README file. This file should include your name, the date, how long you worked on these programs, and anyone you received significant help from. You can then turn everything in by typing:
~dr/bin/submit6 lab2 robyn.cc parts.cc README
You should receive a message telling you that the programs were submitted correctly. To see the files you submitted type ~dr/bin/submit6 lab2 without any file names.