Homework #1

Due: Sept. 10, 2004 (F)

(Note: I'll be out of the office on Friday for a conference, but

the extra time might be nice)

Since most of you have majors in technical fields, I want you to use Linux/UNIX to edit, compile, execute, and debug your programs. This does not mean that you should install Linux on your home machine, since you can use your CNS account to work in a CNS Linux lab (Wright 112, Wright 339, etc.) or open a secure shell to cowboy.cns.uni.edu using some tool like "putty." (You can download putty from http://www.uni.edu/its/us/software/ ).

Information about Linux commands can be found at: http://www.cns.uni.edu/cns-computing/help/unix.html

The steps you need to follow for this lab are:

  1. type into a file named "pgm1.c" the following program using some editor (pico, vi, emacs, etc.) under Linux. WARNING: this program has intentional syntax and semantic errors.
  2. compile the program using the GNU C compiler by typing: gcc -o pgm1 pgm1.c

    (which puts the executable programming in the file called "pgm1")

  3. If you have syntax errors, the compiler will tell you a line number and some poorly worded indication of the cause for each error. While you still have errors, go back to step (1) to edit your program and then recompile. When you have no syntax errors, go on to step (4).
  4. execute your program using the data: 30, 40, 50, 20, and -999 (the sentinel value) by typing:

    "./pgm1" where the "./" indicates the pgm1 in the current directory.

  5. If your program does not give the expected results, think about your logic before going back to step (1) to fix your program. When thinking about your logic, I would recommend playing computer and hand tracking each statement like the computer would. Hopefully, this will expose your semantic errors.
The program to type into the file "pgm1.c" is #include <stdio.h> int main ( ) { int score; int sum int count; print("Enter the first score: "); scanf("%d", score); while (score != -999) count = count + 1; printf("Enter the next score: "); scanf("%d", &score); sum = sum + score; } /* end while */

printf("The average is %d\n", sum / count);

} /* end main */

To submit your assignment, click on the link at the bottom of the homework page for the course: http://www.cs.uni.edu/~fienup/cs036f04/homework/index.htm

You will need to

  1. log on to the submission system using your CNS account information
  2. select the "810:036, C++ Fienup" course
  3. select the radio button corresponding to lab being submitted
  4. enter the name of the file you wish to submit which needs to be accessable on the computer from which you are submitting