CPS08: Lab3 Classes, Programming, Tools Spring 1995 In part of this lab you'll be logging onto the CS machine mentor and setting things up there. The operating system on mentor is different than on the DEC stations so you'll need to get used to a few things. In case mentor isn't working properly this lab can be completed on both the DEC stations and on mentor. The same instructions will work in both places (except, perhaps, for submit). If the instructions for connecting to mentor don't work, skip them and proceed to the steps below. *********Logging in to mentor From an xterm window type telnet mentor.cs.duke.edu to connect to the machine mentor. You'll be prompted for your login and password so you should supply these. The first thing you should do is change your password. To do this, type passwd. You'll be prompted for your old password and your new password. After changing your password you should run the command ~ola/setup! (just type that). This will set up your files so that you can work more easily. ************ You MUST run ~ola/setup! or your environment won't be right. ************ After you've done this, log out (type logout or control-D). Then log back in using telnet and your new password. Create a cps08 directory using the mkdir command. There's no method for setting individual permissions on this directory as we did on the acpub machines, we'll try to fix this later. Change into this directory and create a lab3 subdirectory. Then change into this and copy files by typing what's below (don't forget the trailing dot). cp ~ola/cps08/lab3/* . If you type ls you should see the following files: Makefile, toss.cc and enter.cc. You need to give your machine permission for mentor to connect to it. To do this type in an xterm on the DEC station NOT in a mentor xterm the following: xhost +mentor.cs.duke.edu Do NOT put a space after the + sign. You should then be able to type emacs to get an emacs window. If this doesn't work, skip to the description of Acpub Alternative below for completing the lab on the acpub machines. ********Acpub Alternative As part of lab 1, you should have created a directory called cps08. Change into that directory using the cd command and create another directory called lab3 using the mkdir command. Change into the lab3 directory. If you did this correctly, when you type pwd you should see a long path name that ends with /cps08/lab3. You need to copy some files to do this lab. The cp command is used for copying files on Unix systems. Type the following command to copy files for the lab (don't forget the trailing period, or dot): cp "ola/cps08/lab3/* . This command will copy all the files in the directory ~ola/cps08/lab3! into your cps08/lab3/ directory. If you type ls you should see the following files: Makefile, toss.cc and enter.cc. *****Lab Use the emacs commands C-x C-f to find/load the file toss.cc. Then compile this command using C-x c and type make toss in the minibuffer. Run the program from an xterm window to see that it works. Then load the file enter.cc into emacs also. Type C-x b to switch buffers. Note that there's a default buffer to switch to listed in the minibuffer. You can just hit return to switch to this. Switch between enter.cc and toss.cc a few times. You can also type C-x C-b to list the buffers. Try this. Now compile and run the program enter.cc. If you have questions about how enter.cc works, ask them. You'll now practice cutting and pasting. You'll cut and paste the function InRange from enter.cc into toss.cc. To do this move the cursor to the i of int in the definition of InRange. Hold the control key down and press the space bar (this is C-' '). You should see a message in the mini-buffer: Mark Set. Now move the cursor to the end of the function (after the curly brace ). Press M-w (that's Escape-w). This will copy everything between the mark (which you set) and the point (the cursor). Now switch to toss.cc and move the cursor below main. You want to paste what you just copied. To do this type C-y (control-y). You should see the entire function now below main. If you type C-x u this will undo what you just did. You can try this and then yank back (C-y) the buffer you copied. Since the function is below main, you'll need to either put a prototype for it above main or copy it above main. You can do either one of these things. Then you should use InRange to prompt the user for a number of times to roll the dice between 1 and 10,000 using InRange. Compile and run this program. Now modify the program so that the user is prompted for a specific target to roll. For example, the target might be 7 (or 11, or any number between 2 and 12). Then you should modify the program so that it keeps track of how many times this target is rolled. For example, if the target is 7 and the dice are tossed 1,000 times, a 7 might occur 200 times. To do this you'll need to define a variable to count the number of times the target is rolled, a variable for the target, and you'll need to include an if statement to track whether the target matches the outcome of the dice. Be sure to ask questions if some of this isn't clear. When you've got this program compiled and running you'll need to print it. You can't print from the mentor machine so you'll have to ftp the file over to your acpub account and print it from there. Later we may have a fix for this. Here's what to do now. 1. Create a lab3 subdirectory in your cps08 directory on your acpub account. Change into this directory and then type ftp mentor.cs.duke.edu (you'll be prompted for your password). 2. From the ftp prompt 'ftp> ' you should change into your cps08/lab3 directory using the cd command: cd cps08/lab3. You can type ls to see what's there. 3. Now you want to get the modified toss.cc program. To do this type get toss.cc. 4. Check to see if you got the file in another xterm (you can't check with ftp active). If you retrieved the file, you can type quit to get out of ftp. You should also practice ftp'ing from mentor to the acpub machine. The same protocol is followed, but from mentor you would type ftp teer5.acpub.duke.edu for example, and you'd use put instead of get. Print the file toss.cc by typing enscript -2rG -Pteerlp1 toss.cc. If this doesn't work ask a TA. (You can substitute another printer for teerlp1). The -r option may cause an error message, but it still works. To turn in programs: When your modified toss.cc works, you can submit it, along with a README describing how long it took you and what your impressions of the lab are. Submit works on the DEC stations. It may not work on mentor. submit08 lab3 toss.cc README The README file should include your name, how long you worked on the program, and anyone you received significant help from. You should receive a message telling you that the programs were submitted correctly.