CS 3050, Fall 2005

(Written by Dr. Sarraille)

Please go though this quickly to make sure you understand everything and that the email program works, etc. This should put us all on the same page. Then we can move on to lab 1.

Doing The Hello World! Practice Assignment


Use this document as a tutorial to get accustomed to the class computing environment. (This is not an assignment for credit.)

Read everything in this document before you start doing the tutorial it describes.


This document may use quotes ("...") to delimit the exact characters you must type to give a particular command to the computer. Usually you are not supposed to include these quotes in what you type. In the very few cases where you are supposed to type the quotes, the directions will say so explicitly.


If you are supposed to press the Enter key after typing a command, the directions will use the word enter. For example,

Enter "vt100"

means type "vt100" (without the quotes) and then press the Enter key.

Commands typed while the editor JOVE is running are not usually completed by pressing the Enter key.

  1. Getting an Account: If you don't already have an account on the CS Dept Sun Ultra network, then get a user name and password from your instructor.

  2. Finding a Machine: Locate an available Sun Ultra computer, or personal computer you can telnet from. Your instructor and/or a lab assistant can help you.

  3. Starting to Login: Some names of the lab Sun Ultra's are: altair, arcturus, barnard, capella, castor, centauri, ceti, deneb, omicron, polaris, pollux, regulus, rigel, saiph, sirius, sol, soleil, spica, vega, and zaurak. If you are telnetting in from a computer that is not a Sun Ultra, make a random choice and log in to one of the machines named above. If you need help logging in, raise your hand or consult the appropriate section of the handout entitled Gaining Access to Workstations in the Computer Science Department Network. (This document is available in the class web space under the file name loginDirections.html .)

  4. Entering Username and Password: To login, you enter your user name and password when prompted. The password you type will not show on the screen. This is normal. It is a security feature that helps prevent others from observing your password.

  5. Declaring a Terminal Type and Waiting for Login to Complete:

    If you are telnetting, then after you successfully log in, the system may ask you about your terminal type. This means the system needs to find out what kind of terminal control codes are being used. If you are asked about this, just enter "vt100". Then wait for the shell prompt to appear.

    The shell prompt will probably be your user name, followed by an "@" sign, then the name of the host you are logged into, then a colon, and then a few more characters. For example, if your user name were "jdoe" and you were logged into zaurak, your shell prompt would be something like: "jdoe@zaurak:(~)". This prompt means that the Unix shell program is ready to accept a command.

    If you just sit down in front of one of the Sun Ultra's and try to login to it (it's called "logging in at a console"), you may see a panel asking about which graphical user interface (GUI) you want to use. If so, be sure that Common Desktop Environment (CDE) is selected. Then wait until the graphic "desktop" appears. Next near the bottom of the screen, move the mouse arrow into the small square that is just to the left of the square containing the question mark (?). Then move to the little triangle at the top of the square and click on it. A menu titled "Hosts" should pop up. If that doesn't happen, raise your hand to get some help. Once you have the menu, click on "Console." The menu will retract, and a new window will appear with a shell prompt as described above.

  6. Changing Your Password: Optional step: At this time, you can change your password. You just click somewhere in the middle of the window containing the shell prompt and then enter "nispasswd" After that, follow the directions on the screen.

    Before you enter the command, you must first think of a good password. Check out this advice on choosing a password.

  7. Starting the Editor and Entering Text: Enter "jove p1.cpp". This starts up a text editor called JOVE, working with a file buffer called p1.cpp.

    JOVE is a lot like some PC applications you may be familiar with: Notepad, TextEdit, or SimpleText.

    Unless the file already exists, the screen goes blank, except for some documentation lines at the bottom. JOVE is running. Type the following text. It is a very simple C++ source program. If there is already text on the screen, erase it and type the text below.

    #include <iostream>

    using namespace std;

    int main (void)
    cout << "Hello World!" << endl ;
    return 0 ;
  8. Saving and Exiting: Now figure out how to use the keyboard to do this JOVE command:

    C-x C-\

    What I mean by the command above is "while holding down the ctrl-key with one hand, with the other hand press the x-key, release the x-key, press the \-key, and release the \-key. Finally release the ctrl-key." Consult JOVE -- a quick reference guide for more information about JOVE commands:

    If you haven't done it already go ahead now and do a C-x C-\ command in the window where JOVE is running.

    The C-x C-\ command causes a copy of the program you typed to be saved. It is saved as a file named p1.cpp, because of the name you typed in step 7.

    C++ programs for the g++ compiler on the Suns are supposed to have names ending in ".cpp" or ".cc". In other words, they should have names like p1.cpp, myprog.cc, prog3.cpp, and so on. This is very important. If the ".cc" or ".cpp" is missing, the compiler or linker may fail, even though the program has no errors.

    Now do this JOVE command:

    C-x C-c

    (You have to use again the definition of C- you just learned.) The command causes JOVE to terminate. You should now be seeing your shell prompt again.

  9. Compiling and Linking: Next enter "g++ p1.cpp". This is the command that compiles (and links) your program. It tells the compiler (g++) to translate p1.cpp into a machine-language version of the program.

  10. Checking for Errors and Executing the Program: If you got an error message, it probably means that you made a mistake when you typed the program. In that case, fix it: go back to step #7. If there were no errors in your program, then your compilation succeeded, and the name of the executable translation of the program is "a.out". In that case, enter "a.out", to execute the program. You should see the message "Hello World!" that your program prints on the screen. Did you see it? If so, give yourself a pat on the back. You just wrote a C++ program, and it does what it's supposed to do.

  11. Making a Record of a Program Run: Now that you are sure the program is working correctly, let's do another test. This one will be "for the record." Enter "script p1.script" and wait until the computer writes a prompt on the screen again. (There may be a slight delay. The prompt you get now may be different than before.)

    Here's an explanation of what you just did: The "script" command turns on a program that makes a record of whatever appears on the screen. The command you entered was "script p1.script" so the record the script program makes will be a file called p1.script.

    Enter "a.out" and see your "Hello World!" message written to the screen again. Now enter "exit" to turn off the scripting program. From the time you entered "script p1.script" to the time you entered "exit", all things that were written on the screen were also recorded in the file called p1.script.

    Enter clear to clear the screen. Now enter "cat p1.script". This causes the computer to type the contents of the script file you made. It should look something like this:
    Script started on Sat Aug 21 19:05:11 2004
    jdoe@vega:(~) a.out
    Hello World!
    jdoe@vega:(~) exit
    script done on Sat Aug 21 19:17:37 2004
    Note that the script file (named p1.script) starts and ends with "timestamps" that tell when the script was started, and when it was completed. In between it reproduces what you typed.

    Now enter "jove p1.script" so you can look at the file with the JOVE editor. You see your script. You also see "weird" characters in the script like ^M at the end of each line, and maybe some other things. These characters are an undesirable side-effect of the way the scripting program interacts with special characters that handle the terminal display. The weird characters are sometimes visible, and sometimes not, depending on just how you try to display your script file. The characters were not visible when you displayed p1.script with "cat," but they were visible when you used JOVE. Do a C-x C-c command to exit JOVE.

    When you turn in a real programming assignment, you will be sending me the source code, plus a script similar to the one you just made. The script will be a record that will show me that you did the right kind of testing of your program.

    I require you to run your script through a filter before you send it to me. It's a way to get rid of most of the weird characters, so the script will be more readable. It is easy to do, no matter how big the script is.

    Here's how: Enter "cat p1.script | col -b > temp". This command pipes the script file to the input of the command "col -b > temp", which filters out some of the weird characters and writes the output to a file named temp. Now the temp file is the filtered version of the script. Enter "mv temp p1.script" to replace the script file with the new filtered version. Now enter "jove p1.script" again. See how the file has been cleaned up? Good. Exit JOVE again by doing a C-x C-c command.

  12. E-Mailing Program and Script: When you have the shell prompt back, enter

    mail -v -s "p1 source" mmartin@cs.csustan.edu < p1.cpp

    DO include the quotes above! This command sends me an electronic mail (e- mail) message. (To get another prompt from the shell, you may need to press the Enter key now.)

    Now enter

    mail -s "p1 test script" mmartin@cs.csustan.edu < p1.script

    This sends me the script file you made. This time you left out the -v, so mail "does its work silently."

    Congratulations! You have just completed all the steps of a sample programming assignment.

  13. Change Your Password: If you haven't already done so, think of a good password now and change your password. See step 6 for the directions. A secure password is very important to you. Attempted break-in's are common. If someone gets access to your account and trashes the class work in your files then you have a problem! Also, someone could get control of your account, masquerade as you, and do bad things.

  14. Exiting the System: If you are telnetting, make a safe exit from the system by entering "logout". If you are at a console, then click the right mouse button in the background, select "Logout", and click on "OK".

  15. The End: You do good work! Go get a cup of coffee, or a glass of your favorite beverage, and kick back.