CS 1500
Getting Started - Hello World!

DIRECTIONS:

Use this document as a tutorial to get accustomed to the class computing environment.
Read everything in this document before you start doing the tutorial it describes.

THE USE OF QUOTATION MARKS:

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.

THE USE OF THE WORD ENTER:

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.


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

  2. Finding a Machine: Locate an available Mac computer that is booted into OS X. These will generally be the ones closest to the lab entrance. Your instructor and/or a lab assistant can help you.
     
  3. Starting to Login: Some names of the lab Macs are: ada, babbage, chomsky, godel, hopper, linus, pascal, turing and wozniak. If you are doing remote login from a computer outside of the lab or in the lab running Windows, 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 Resouces section of the CS Departement web page.

  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 logging in remotely, 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 babbage, your shell prompt would be something like: "jdoe@babbage.csustan.edu:(~)". This prompt means that the Unix shell program is ready to accept a command.

  6. Changing Your Password: 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 "passwd" 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 "pico hello.cpp".

    The command "pico hello.cpp" starts up a text editor called PICO, working with a file buffer called hello.cpp.

    PICO is a lot like some PC applications with which you may or may not be familiar: Notepad, TextEdit, or SimpleText. It is a simple text editor - better than a word processor for the kind of thing we are doing.

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

    #include <iostream>

    using namespace std;

    int main (void)
    {
    cout << "Hello World!" << endl ;
    return 0 ;
    }
    (NOTE: The final character in the "endl" above is the letter 'el' and not a 'one'. The "endl" stands for "endline".)
     
  8. Saving and Exiting: Now figure out how to use the keyboard to do this PICO command:

    ^x

    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 ctrl-key."  Then follow the instructions: enter "y" to save and edit the name of the file if necesary. 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 prog1.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.

  9. Compiling and Linking: Next enter "g++ hello.cpp". This is the command that compiles (and links) your program. It tells the compiler (g++) to translate hello.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 (this is the really important part) it does what it's supposed to do.


mmartin@pascal:(~/1500) g++ hello.cpp
mmartin@pascal:(~/1500) a.out
Hello World!
mmartin@pascal:(~/1500)