Getting Started - Hello World!
Use this document as a tutorial to get accustomed to the class
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,
means type "vt100" (without the quotes) and then press
the Enter key.
- 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
- 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
lab assistant can help you.
- 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
you need help logging in, raise your hand or consult the Resouces section
of the CS Departement web page.
- Entering Username and Password: To login, you enter
name and password when prompted. The password you type will not show on
screen. This is normal. It is a security feature that helps prevent
from observing your password.
- Declaring a Terminal Type and Waiting for Login to
If you are logging in remotely, then after you successfully log in, the
may ask you about your terminal type. This means the system needs to
what kind of terminal control codes are being used. If you are asked
this, just enter "vt100". Then wait for the shell prompt to
The shell prompt will probably be your user name, followed by an "@"
then the name of the host you are logged into, then a colon, and then a
more characters. For example, if your user name were "jdoe"
were logged into babbage, your shell prompt would be something like:
"firstname.lastname@example.org:(~)". This prompt means that the
ready to accept a command.
- Changing Your Password: At this time, you can change
your password. You just
somewhere in the middle of the window containing the shell prompt and
enter "passwd" After that,
follow the directions on the
Before you enter the command, you must first think of a good password.
advice on choosing a password.
- Starting the Editor and Entering Text: Enter "pico
The command "pico hello.cpp" starts up a text editor called
working with a file buffer called hello.cpp.
PICO is a lot like some PC applications with which you may or may not
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
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.
(NOTE: The final character in the "endl" above is the
'el' and not a 'one'. The "endl" stands for "endline".)
using namespace std;
int main (void)
cout << "Hello World!" << endl ;
return 0 ;
- Saving and Exiting: Now figure out how to use the
keyboard to do this PICO command:
What I mean by the command above is "while holding down the ctrl-key
hand, with the other hand press the x-key, release the
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
prog1.cpp, myprog.cc, prog3.cpp, and so on. This is very important. If
".cc" or ".cpp" is missing, the compiler or linker may fail, even
program has no errors.
- Compiling and Linking: Next enter "g++ hello.cpp".
the command that compiles (and links) your program. It tells the
(g++) to translate hello.cpp into a machine-language version
Checking for Errors and
Executing the Program: If you got an error message, it probably
that you made a mistake when you typed the program. In that case, fix
back to step #7. If there were no errors in your program, then your
compilation succeeded, and the name of the executable translation of
program is "a.out". In that case, enter "a.out", to
the program. You should see the message "Hello World!" that
program prints on the screen. Did you see it? If so, give yourself a
the back. You just wrote a C++ program, and (this is the really
part) it does what it's supposed to do.