next up previous


CSE 2320 Section 501 Fall 1998

Program 1

Due: September 22, 1998, 5:30pm (September 23, 1998, 5:00pm for -10%)

Implement the recursive, divide-and-conquer version of ADD-ODDS from Homework 1, problem 5. You may write your code in C or C++, but cannot use global variables. In addition to correctness, programming style is also important, so please write modular, well-documented code.

1.
Implement the recursive, divide-and-conquer function ADD-ODDS(A,p,r) that returns the sum of the odd numbers found in the positive integer array $A[p \ldots r]$.

2.
The main part of your program will read in data from a file whose name is given as the first argument to your executable. The first line of the input file contains the number of lines (1-99) in the rest of the file. Each subsequent line begins with the number of elements (1-99) in the array followed by the elements (1-99). Your main program should process each line one at a time by reading in the array, calling ADD-ODDS, and then printing the result. For example, if your compiled program is in a.out, and you want to run it on the sample input file pgm1in that is in the directory /public/cse/2320-501 on omega, you should do the following:

omega> a.out /public/cse/2320-501/pgm1in
9
398
0
9
384

3.
Be sure to properly document your source code. If you are unsure about the level of comments, please ask the GTA, who will be grading your homeworks. Also, in the comment at the top of your source code, you must include the homework number, your full name, ID number, login, class (2320), and a line indicating how to compile your program (e.g., compile using: cc or compile using: gcc -lm).

4.
After ensuring that your program compiles and executes correctly on the omega machine, run the program /public/cse/2320-501/handin1 to electronically hand in your source file. All source code must be in one file (i.e., no separate .h and .c files). The handin program will prompt you for the file name containing your source code and will output the date and time when your program was handed in. Be sure you are in the directory containing your source file when you run the handin program. Note: You may run the handin program as many times as you like, but only the most recently handed in file will be retained. Do not turn in a printout of your source code in class.


next up previous