COS 126: Fall 1996 Hello World |
Due: Wed. 9/18, 11:59pm |
The purpose of this assignment is to familiarize you with using the computer and with the mechanics of preparing and submitting assignment solutions. This assignment carries no grade, but it should be submitted. Do this assignment even if you're already a computer whiz; it's good for you.
You should learn to use emacs
for editing files, netscape
for browsing the World Wide Web, lcc
for compiling programs, and
/u/cs126/bin/submit
for submitting programs. You may be able to
complete this assignment during the first or second meetings of your precept,
which will be held in CS Bldg. room 101. If not, try to go to the lab (CS Bldg.,
room 101) when an undergraduate lab assistant is scheduled to be there (usually
8-12pm) so you can get help. Don't be afraid to ask for help;
the lab assistants are paid to help you.
Your goal is to create, compile, and run the following basic program.
#include <stdio.h> int main(void) { int n; printf("Hello world! Give me a number:\n"); scanf("%d", &n); printf("Thanks for entering %d\n", n); return 0; }
Completing this assignment involves the following steps. If you run into problems, ask a lab assistant for help.
hello.c
.emacs
text editor, which is a bit more
complicated, but much more powerful, and you can use emacs
in
terminal or telnet
sessions on your own computer. To start emacs
,
type emacs hello.c &
in the Terminal window (don't
forget the
&
); an emacs
window should appear. If
you've used text editors before, you will know how to use emacs
.
Just use the pull-down menus and the mouse. You can also run a tutorial (look at
the Help menu). Enter the program above, and save it in hello.c
.lcc hello.c
(that's ell-c-c) in the Terminal window.
This command runs the C compiler, lcc
, which compiles
hello.c
and leaves an executable file named a.out
in your directory. If lcc
complains in some way, you mistyped
something, and you should get help.a.out
in the Terminal window. This command executes your
program. The computer should print
in the Terminal window. Then it will do nothing. You must type a number (say, 5), and hit Enter, then the computer should print
Hello world! Give me a number:
and the program should terminate. You may need to repeat this edit-compile-execute cycle a few times before it all goes smoothly.
Thanks for entering 5
hello.c
working, submit it by typing the
following command in the Terminal window.
/u/cs126/bin/submit 1 hello.c
lpr hello.c
.
You can also click on the Printer icon in the Control Panel.When you've finished this assignment, try out some of the other software you'll be using this semester. To browse the COS 126 Web pages, type
netscape http://www.cs.princeton.edu/courses/cs126/ &
You can also just type netscape &
, click on
netscape
's Open button, and enter
http://www.cs.princeton.edu/courses/cs126/
in the pop-up dialog box. Cruise around the COS 126 Web; it is essential that you understand what's where and how to get to it.
You'll also use electronic mail a lot this semester. So, to get started,
send us electronic mail telling us (briefly) whether or not you have previous
programming experience, in which department at Princeton you might major, and
anything else you'd like to say. To send us mail, type mail cs126
,
write your message, then Ctrl-d (i.e., press the Ctrl and the "d" keys
simultaneously) on a line by itself to end the message. You can also terminate a
message by typing a period (".") on a line by itself. Alternatively,
click on the Mail icon in the Control Panel and use the graphical interface to
the mail system.
Experiment with the window system by creating and resizing windows, using
the mouse, etc. Send mail to a friend. Try some basic UNIX commands (ls
,
cd
, man
, mkdir
, to name a few). Make
sure that you get reasonably comfortable with using the computer; it's going to
be your constant companion this semester.
To log out, position the mouse over the background, i.e., not over any windows, click the right mouse button, and select "Logout". Alternatively, you can just click the "EXIT" button in the Control Panel. Don't forget to log out!