Welcome to CS 127!!!
The students in this class have a variety of backgrounds. Specifically, many are already fluent in C++. Others are fluent in Java. This lab is designed to bring everyone up to speed with the same amount of C++ knowledge, and using C++ on our systems in particular. Those students who are already familiar with C++ should see this lab as a review and as an opportunity to fill in gaps where they might exist.
For this lab, find a partner to work with. If one of you has trouble logging into the machines, let the other person log in for today. If you both have trouble, see if you can shuffle groups so that each person has a partner that can successfully log in.
If you see a Windows Novell login, you need to reboot the system. To do this:
cd ~
pwd
mkdir cs127
ls
cd cs127
pwd
1. Start up emacs by typing
emacs &
inside the "terminal" window. The "&" means start it as a background job, so that you still have access to the terminal window if you want it.
2. Enter in the following C++ program:#include <iostream>One of the really nice things about emacs is that it will automatically indent your code for you. Use the "tab" key liberally; it doesn't put tabs in as you would expect. Instead, it lines up each line exactly right.int main()
{
cout << "Hello world!" << endl;
}
3. Save your program by typing ctrl-x, ctrl-s (the s means "save"). When it prompts you for a filename at the bottom, call this program hello.cpp (the cpp identifies the program as "c-plus-plus"), and then click back on the terminal window. Type "ls". You should see your hello.cpp program listed. You may or may not see a file called hello.cpp~. If you do, the ~ at the end indicates that this is an automatic backup of an old version of your program that emacs has created for you.
4. Compile your program by entering the following at the command prompt:
Type "ls" again. You should now see the file "hello" sitting there.
helloand see your program run!
hsp musicant cs127 fileSo to submit your file named "hello.cpp", type
hsp musicant cs127 hello.cppYou can find detailed information on hsp at http://www.mathcs.carleton.edu/system_notes/hsp.html.
Once you have submitted a file with a particular name, you cannot submit
another file of that same name.
cp /Accounts/courses/cs127/dmusican/ArrayTools.cpp .Make sure to include that "." at the end of each of the two lines as above. cp means copy, and the dot is an abbreviation for the current directory that you are in. So the first line effectively says "copy the file /Accounts/courses/cs127/dmusican/ArrayTools.cpp to here."
cp /Accounts/courses/cs127/dmusican/ArrayTools.h .
2. Open up the two files inside two separate Emacs windows, and take a look at them. Some of the syntax may be new to you, regardless of background. Walk through the program and see what you think it does. Write down on a piece of paper what the output should be.
3. Compile the program by issuing the following command in the terminal window:
g++ ArrayTools.cpp -Wall -o ArrayTools4. Run the program by typing "ArrayTools" at the command prompt. Do you see what you expected? If not, try to figure out why.
5. Add a method to the program called binarySearch that does a binary search on the array for a particular number. To refresh your memory, a binary search does what you would ntuitively do -- start in the middle of a sorted list. If your number is too small, then jump halfway in between the number you last picked and the maximum value. And so on...
6. Add a method called selectionSort that sorts the list using a selection sort. A selection sort searches through the array for the smallest number. When it finds it, it swaps it with the number in the first position. It then searches the rest of the array (everything but the first element) for the smallest number. When it finds it, it swaps it with the number in the second position. And so on...
For example, here are the iterations that selection sort would go through in sorting a list of numbers:
17 14 16 15 19 13
13 14 16 15 19 17
13 14 15 16 19 17
13 14 15 16 17 19
7. Turn in your work with hsp at the end of the class period. I won't be grading this lab. As such, it is not essential that you get all the way through steps 6 and 7, though I would like to see how far you can get. Have fun, and see you Monday in the classroom!
dmusican@carleton.edu
That's all you need to do! Test it by sending email to yourself at the mathcs department and see if it forwards to your Carleton address. Here's a quick way to test it: at a Linux prompt, I would type the following: