COS 126 Hello, World on Arizona |
Programming Assignment 0 Due: Wednesday 11:59pm |
The purpose of this assignment is to familiarize you with the mechanics of preparing and submitting assignment solutions. This assignment carries no grade, but you must do the electronic submission. Follow these instructions if you want to work on the the arizona system, which runs the Solaris operating system on Sun workstations. We provide different instructions if you prefer to use a Windows or Mac OS X system. Your goal this week is to learn to use emacs for editing files and gcc for compiling 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 arizona computer lab in the Friend 016 laboratory. Don't be afraid to ask for help.Your assignment is to create, compile, run and submit three short C programs. In addition, you will edit and submit a descriptive file called readme.txt with each of your assignments. (Instructions for the readme file are on the checklist for each assignment.)
PROGRAM 1 hello.c : Create, compile, run and submit the following extension of everybody's first C program.
#include <stdio.h> int main(void) { int num; printf("Hello world! Give me an integer:\n"); scanf("%d", &num); printf("Thanks! I've always been fond of %d.\n", num); return 0; }
PROGRAM 2 hello-while.c : Create, compile, run and submit Hello World Exercise #5.
PROGRAM 3 hello-if.c : Create, compile, run and submit Hello World Exercise #6.
Completing this assignment involves a number of steps that are described below. The instructions refer to Program 1, but will be the same for Programs 2 and 3.
|
Log in to a machine on the arizona cluster. Experienced users can can login remotely to arizona via a telnet or ssh session to arizona.princeton.edu - you can learn more about working on arizona remotely here. Unix novices should use one of the workstations in arizona lab. There will be trained staff there to answer your questions.
Don't worry if it looks a little different, or the name phoenix is replaced by something else that reminds you of Arizona. You can enter a command by typing it in the Terminal window followed by the "Enter" or "Return" key.phoenix.Princeton.EDU%
This customizes several Unix tools specifically for COS 126. (Specifically, it adds /u/cs126/bin to your path, copies our .emacs file to your directory, and creates a dummy web page for you, unless you already have one. If most of this sounds like gibberish, don't worry about it. )phoenix.Princeton.EDU% source /u/cs126/bin/setup126-f02
|
Now you are ready to write your first program.
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. The emacs editor is a bit more complicated than the standard Text Editor on the desktop, but much more powerful, and includes special features designed for writing C programs. 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 launch a tutorial from the Help menu.phoenix.Princeton.EDU% emacs hello.c &
|
in the Terminal window. This command runs the C compiler, gcc, which compiles hello.c and leaves an executable file named a.out in your directory. We use gcc126 instead of gcc to ask the compile to output additional warnings: novice and veteran programmers will find this invaluable. If gcc complains in some way, you mistyped something, and you should check your program carefully. Ask for help if you can't see the mistake.phoenix.Princeton.EDU% gcc126 hello.c
|
This command executes your program. You should getphoenix.Princeton.EDU% a.out
in the Terminal window. Then nothing will happen. You must type an integer (say, 5), and hit Enter, then you will getHello world! Give me an integer:
and the program should terminate. You may need to repeat this edit-compile-execute cycle a few times before it all goes smoothly.Thanks! I've always been fond of 5.
|
phoenix.Princeton.EDU% lpr hello.c
|
and click on netscape's Open button, and enterphoenix.Princeton.EDU% netscape &
choose the Assignment Submission menu option, and follow the instructions provided.http://www.princeton.edu/~cs126
|
Cruise around the COS 126 Web site; it is essential that you understand what's where and how to get to it. Be sure to fill out the online questionnaire. Also make sure you find the "Assignment 0 Checklist" page, and also be sure to read the COS 126 Collaboration Policy.http://www.princeton.edu/~cs126
|