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:
Most of what we do below will be described via keyboard shortcuts. You can do most of it as well with the menus within Emacs, if you like - but you'll be much faster and more effective in the end if you learn the keyboard techniques.
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. First, we'll modify your .emacs file. .emacs is the place where all the startup instructions to emacs are kept, and we will add some instructions to set up emacs to highlight your code in color. In emacs, most commands are proceeded by either ctrl-x or alt-x. Create a .emacs setup file by entering ctrl-x, ctrl-f (the f means "file") to get the prompt to open a file, then open the file ~/.emacs (the period in front of emacs is important). The tilde (~) is a shortcut for your home directory (folder), and .emacs is the name of the file you're going to edit. You should see a blank file inside emacs, unless you've created a .emacs before.
3. Click back to the terminal window, and open up another emacs session. To do this again, type "emacs &" at the terminal window.
4. In the second emacs window that opens, again enter ctrl-x, ctrl-f to open a file. Use the backspace key to delete the "~/" that appears by default, and enter "/Accounts/courses/cs127/dmusican/.emacs" . /Accounts/courses/cs127/dmusican is the directory where I will keep common materials for the class to use.
5. Copy all the code from the .emacs I provided into your new .emacs. To do this, highlight all the code in my .emacs with the mouse, then go to your new .emacs and paste it in by typing ctrl-y (the y means "yank").
6. Save your new .emacs file by typing ctrl-x, ctrl-s (the s means "save").
6. Close both emacs windows by typing ctrl-x, ctrl-c (the c means "close") inside each one, and then start up a single emacs window again.
cd ~
pwd
mkdir cs127
ls
cd cs127
pwd
#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;
}
Save your program (ctrl-x, ctrl-s). 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.
3. 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. For
example, I would test it for myself by sending email to dmusican@mathcs.carleton.edu,
and seeing if it goes to my regular email account.