(Latest Revision -- 02/03/2014)

Doing The Hello World! Practice Assignment

DIRECTIONS:

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.

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.

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

TUTORIAL:
  1. Getting an Account: If you don't already have an account for using the CS Dept Lab network of workstations, then get a user name and password from your instructor.

  2. Finding a Machine: Locate a Macintosh workstation. Some of their names are:


    Your instructor and/or someone who works in the lab can help you.

  3. Entering Username and Password: The login procedure basically involves just entering 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. If you have any difficulty with this, just ask someone what to do.

  4. Getting a Shell

    If you just sit down in front of one of the workstations and try to login to it, that's called "logging in at a console",

    When you log into a Macintosh at the console, you need to launch the "Terminal.app" to get a shell prompt. We will refer to it as "Terminal." There may be a shortcut icon in the Dock area at the bottom of the screen for launching Terminal. Terminal also can be found under Applications/Utilities in the filesystem. Ask for help if you don't see how to launch it right away.

    The shell prompt will probably be your user name, followed by an "@" sign, then the name of the host (computer), then a colon, and then a few more characters. For example, if your user name were "bcates" and you were logged into hopper, your shell prompt would be something like:

    bcates@hopper:(~)

    This prompt means that the Unix shell program is ready to accept a command.

    If you log in remotely, 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.

  5. 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 "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.

  6. Starting the Editor and Entering Text: Enter "jove p1.cpp".

    (NOTE: In the name: p1.cpp above, that is a 'ONE' after the 'p' - NOT the letter 'el').

    The command "jove p1.cpp" starts up a text editor called JOVE, working with a file buffer called p1.cpp.

    JOVE is a lot like some PC applications with which you may be familiar: Notepad, TextEdit, or SimpleText. It is a simple text-only editor - the right tool for the job of creating a computer program. On the other hand, it would be an extremely bad idea to try to use a word processor to write a computer program. The result would be a disaster.

    After you enter the command "jove p1.cpp", unless the file p1.cpp already exists, the screen will go 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 and you don't know what to do, 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".)

  7. 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 this:

    "While holding down the ctrl-key with one finger,
    type an x by briefly depressing the x-key,
    then type a \ by briefly depressing the \-key, and
    then finally release the ctrl-key."

    The ctrl-key is the key labelled "control" - probably located at lower left on the keyboard.

    Consult JOVE -- a quick reference guide for more information about JOVE commands. (JOVE is actually a very powerful tool for doing programming work. It takes a little effort to learn it, but if you hope to do a lot of programming someday, I think learning JOVE now will be very helpful to you.)

    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 6. Note that JOVE tells you at the bottom of the screen the name under which it saved the file, and the number of characters in the file.

    C++ programs for the g++ compiler are supposed to have names ending in ".cpp" or ".cc". In other words, they should have names like p1.cpp, myLyricsWriter.cc, taxCalculator.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

    (As before, typing this JOVE command requires that you type two characters while holding down the ctrl-key. The command causes JOVE to terminate. After doing the command, you should see your shell prompt again, at the bottom of the screen.)

  8. 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.

  9. Checking for Errors and Executing the Program: If you got an error message after entering "g++ p1.cpp" it probably means that you made a mistake when you typed the program. In that case, fix it: go back to step 6. 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.

  10. Making a Record of a Program Run: Now that you are sure the program is working correctly, let's test it again "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 
    bcates@babbage:(~) a.out 
    Hello World!  
    bcates@babbage:(~) 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 is the record of what you typed.

    Now enter "jove p1.script" so you can look at the script 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 the filtering, 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.

  11. Starting the Editor and Making a .forward File: As a part of doing this lab assignment, you may need to check for e-mail sent to your CS Lab E-mail address. You will need to check for such e-mails many more times during the semester. To set things up so you can read the e-mail, do the following.

    You have now created your .forward file. Partners who are not logged in now still need to make .forward files. They should do that at the earliest convenient time.

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

    mail -s "p1 source" john@ishi.csustan.edu < p1.cpp

    DO include the quotes above! This command sends me an electronic mail (e- mail) message.

    Now enter

    mail -s "p1 test script" john@ishi.csustan.edu < p1.script

    This sends me the script file you made.

    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 5 for the directions. A secure password is very important to you. Attempted break-in's are common. (Believe it or not, our systems are pretty much always under attack from hostile software trying to find accounts with passwords that are easy to guess.)

    If someone gets access to your account and trashes the class work in your files, or sends obnoxious e-mail messages (pretending to be you), then you have a problem!

  14. Exiting the System: If you logged in remotely, make a safe exit from the system by entering "logout". If you are logged in at the console of a Macintosh, then select Log Out at the bottome of the 'Apple' drop-down menu.

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