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 Sun Ultra and Mac network, then get a user name and password
- Finding a Machine: Locate an available Sun Ultra
personal computer from which you can login remotely. Your instructor
lab assistant can help you.
- Starting to Login: Some names of the lab Macs and Sun
ada, altair, arcturus, babbage, castor, ceti, chomsky, deneb,
godel, hopper, linus, omicron,
pascal, polaris, pollux, saiph, turing and wozniak. If you are doing
remote login from a computer that is not a Sun
Ultra, make a random choice and log in to one of the machines named
you need help logging in, raise your hand or consult the appropriate
of the handout entitled Gaining Access to Workstations in the
Science Department Network. (This document is available in the
space under the file name loginDirections.html.)
- 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:
"email@example.com:(~)". This prompt means that the
ready to accept a command.
If you just sit down in front of one of the Macs or Sun Ultra's and try
login to it
(it's called "logging in at a console"), you may see a panel asking
which graphical user interface (GUI) you want to use. If so, on the
Suns be sure
that Common Desktop Environment (CDE) is selected. Then wait
graphic "desktop" appears. Next near the bottom of the screen, move the
arrow into the small square that is just to the left of the square
the question mark (?). Then move to the little triangle at the top of
square and click on it. A menu titled "Hosts" should pop up. If that
happen, raise your hand to get some help. Once you have the menu, click
"Console." The menu will retract, and a new window will appear with a
prompt as described above.
- 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
(NOTE: In the name: prog1.cpp above, that is a 'one'
'g' - not the letter 'el').
The command "pico prog1.cpp" starts up a text editor called
working with a file buffer called prog1.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++ prog1.cpp".
the command that compiles (and links) your program. It tells the
(g++) to translate prog1.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.