COS 126
Hello,
World |
Programming Assignment 0
Due: Wednesday, 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 you must do the electronic submission.
Even if you're already a computer whiz, you might learn something!
Your goal this week is to 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.
If you have programmed before, you may be able to finish this
assignment quickly. If you have not programmed before, or if you are
not familiar with the systems that we use, plan to learn the basics in
the computer lab in room 101 in the CS building. There will be
someone there to answer questions most
of the time this week, and there will be help sessions in the evening.
Don't be afraid to ask for help.
Your assignment is to create, compile, and run the following extension
of everybody's first C program (Kernighan and Ritchie, pp. 5-8).
#include <stdio.h>
main()
{
int n;
printf("Hello world! Give me a number:\n");
scanf("%d", &n);
printf("Thanks! I've always been fond of %d\n", n);
}
Completing this assignment involves the following steps.
- Log in to a SUN Unix machine.
If you're the least bit unsure about using a computer,
use one of the machines in room 101 in the CS building. Detailed instructions
on what to do on these machines are given below, and there will be people
there to answer your questions this week.
If you're used to using
arizona via remote login, feel free to do so, but you may need
to make some minor adjustments in the directions that follow.
- When you log in, the computer
starts the "Common Desktop Environment",
which is a graphical user interface based on X Windows. You'll see a
"Control Panel" along the bottom of the screen, and a
"File Manager" window somewhere else on the screen. A
tutorial window may also appear. There are lots of "Help"
menus; click on a few to see what's available.
- In the left side of the Control Panel, you'll see an icon that
depicts a pencil and a piece of paper. There should be a triangle
above this icon; click on the icon and a pop-up menu should
appear. Select "Terminal" and click the left mouse
button.
- You should now have a "Terminal" window somewhere on the screen.
You can enter commands by typing the commands in this or any Terminal window
followed by the "Enter" or "Return" key.
- For your first command, type emacs hello.c &
to create a window for the emacs text editor, ready for
you to type in the file hello.c (the &
means to run emacs in the background, so that you can type
other commands without leaving emacs). emacs is a
bit more complicated than the standard Text Editor on the desktop, but
much more powerful, and you will be able to use emacs in
terminal or telnet sessions on your own computer. 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 exactly as it
appears above. If you omit even a comma, the program won't work. You
can use the Tab key or spaces to get the indentation. When you're
done, save the program in a file named hello.c.
- Now type lcc hello.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 check your program
carefully and get help if you can't see the mistake.
- Type a.out in the Terminal window. This command executes your
program. You should get
Hello world! Give me a number:
in the Terminal
window. Then
nothing will happen. You must type a number (say, 5), and hit Enter, then you will get
Thanks! I've always been fond of 5
and the program should
terminate. You may need to repeat this edit-compile-execute cycle a
few times before it all goes smoothly.
- Once you have hello.c working, submit it by typing the
following command:
/u/cs126/bin/submit 0 hello.c
- You will want to check that everything is properly submitted. To do that,
type
/u/cs126/bin/submit 0
- To get a printed copy of your program, type lpr -Ppsr 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 &, 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 electronic mail to cs126 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. If you've never used mail, type pine to get started,
and ask for help if you get stuck.
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!
Copyright © 1998 Robert Sedgewick