Wait for the teacher to demonstrate the procedures at the start of the class.
You can open a Web Browser and point it at this page
First, click on activities and then on the image of a file cabinet in the favorites. This opens a window and you can use a Right Click to in it to open a menu and select "Create New Folder" to add a folder. You can change its name to "cs201" and keep you CSCI201 work in.
Then Double click the new folder icon so that it opens -- it should be empty. Use the same menus to create a directory called "lab02". Double Click it. It will open -- it should empty. We will put files into it from the cs201/lab02 web page.
Right click this link [ hello.cpp ] and select the "Download..." option. Ask the browser to put the file your cs201/lab02 directory (demo in class).
cd cs201/lab02and tap the Return/Enter key. You can list the files with this command
ls(and tap Return).
We will use the Gnu compiler. Try the commands as shown below in your terminal window. The prompts will be different since they depend on your "Working directory".
cp hello.cpp hello.cpp.bakbefore you start to play with the code.
Your task is to try out the errors shown on page 19-21 of our text.
Your tool is the "gedit" editor. Double clicking the "hello.cpp" file should start it up. Or
gedit hello.cpp &
The "&" above lets you pop up the gedit window and then input terminal commands.
Use the editor to make a change suggested in the book and save it.
Click in the terminal window and repeat the test.... use the up-arrow key to go back to a previous command and then tap the "Enter" key to repeat it.
Does the compiler object to your code? It gives a line number in front of the error look on that line, and the lines above it. Look for broken syntax rules. Fix the error and try again until the program runs...
cp hello.cpp.bak hello.cpptyped in your terminal!
cp hello.cpp.bak greeting.cpp
Make the "greeting" program display "Happy New Year" when compiled and run.
Change the comments to match -- your name and what you have done.
~dick/bin/Q div.cppBut if you try dividing 3 by 6 you get the answer 0. This is because the numbers are defined as "int"s -- whole numbers or integers. You should also find out what happens when you input numbers like 2.1 and 0.7.
This is clearly not a good program.
You task is to make the program work with real numbers -- "double"s rather than integers. Hint: look at pages 58-59 and guess the one word you need to change in "div.cpp". Process: Guess, edit, save, test, and repeat if not right.
You can create a new directory by typing in the "mkdir" command:
mkdir example"mkdir" means Make Directory under the current "Working directory".
You can change a terminal/command window to another directory very easily by typing in the "cd" command:
cd example"cd" means Change Directory to the "example" in this directory!
cdalways takes you back to your home directory.
These commands show you where you are and what files and directories you have.
pwdstands for Print Working Directory and
lsmean LiSt the files. These are good when you [ Change Directory ] and are not sure where you got to and what files are there.
Here is another useful command to use before playing with a file:
cp example.cpp old.example.cppwhich CoPies the file example.cpp and creates a new old.example.cpp with the same data in it.
To change the name of a file you can use the "MoVe" command:
mv mistook.cpp mistake.cpp
. . . . . . . . . ( end of section CS201 Laboratory 2 -- Compiling, Running, and Writing simple C++ programs) <<Contents | End>>