Date: Thu Aug 29 2002.
Due: 12:00 Noon, Thu Sept 5 2002.
Submitting your code: Turn in your files on host lectura.cs.arizona.edu using the command
turnin cs352_placement file1 file2 ... filen
Please follow the directions below carefully and exactly: understanding and programming to a specification is an important aspect of this exam.
- Input :
- A file containing M rows (M >= 0), each row containing N integers (N >= 0) separated by whitespace (i.e., some number of blanks and/or tabs).
- Output :
Thus, your output should have a total of M+1 rows, with each row containing N+1 columns.
- each row of the original input file, preceded by the sum total of the integers in that row; and
- a final row whose first element is the sum of all the individual row sums, and whose next N elements are the sums of the individual columns of the input file.
Example: Given the input
your program should produce the output
1 10 -37 12 5 3 17 6 9 -2 0 11 9 123 13 where the entries in boldface indicate the totals computed by your program.
-9 1 10 -37 12 5 33 3 17 6 9 -2 156 0 11 9 123 13 180 4 38 -22 144 16 In the output you generate, it is not necessary to retain the same whitespace between numbers within a row as in the input file.
- Error Conditions :
- The program must be invoked with a single argument, which is the name of a (readable) file.
- All the rows in the input file should have the same number of entries, and each entry should be an integer.
If any of these conditions is violated, your program should give an error message identifying the problem as far as possible and exit with status -1. For example, the error message produced if the file specified does not exist should be different from that produced if the file exists but is not readable (these are just two examples of things that can go wrong; other such situations should be dealt with similarly).
- Restrictions :
- Your program should use an amount of memory proportional to the number of data elements in the input.
- There should not be any a priori hard limits on the maximum number of rows and/or columns in an input file.
In other words, it is not acceptable to allocate a large fixed array of integers to hold the input data.
- Invoking your Program :
- Your (executable) program will be called mytotal and will be invoked as
- mytotal infile
- Files to Turn in :
- Turn in (a) all source files for your program, and (b) a Makefile that supports the following targets:
make mytotal: causes your program to be built without any errors or compiler warnings.make clean: deletes all binary files (*.o and mytotal) in the directory.
- Exit Status :
- The program should exit with status 0 if execution completes normally, -1 if an error was encountered (see above).
Invocation :The script will be invoked with two arguments, i.e., asmycompare file1 file2Each of file1 and file2 must name a file that exists and is readable.If invoked with an incorrect number of arguments, or if any of the files specified does not exist or is not readable, the script should give a descriptive error message and exit with status -1.
Input File Format :
Each input file will consist of a number of lines, each line containing a number and a letter (one of A, B, C, D, E), e.g.:Behavior :289383 BThe number represents a student ID, and the letter is the student's grade in the class represented by that file.
692777 A
747793 A
885386 C
516649 B
202362 C
368690 E
897763 BYou may make the simplifying assumption that the student ID is separated from the grade by some number of blank (i.e., space) characters, but not tabs or any other whitespace character. However, do not make any assumption about the number of space characters separating the two fields in any line.
You may also assume that the input files, if they exist and are readable, are in the correct format (as described above), so you need not check the format of the file for correctness.
When invoked as mycompare file1 file2, the script should print out each student id that satisfies the following property:Exit Status :The student received an A or B ("did well") in one of the two courses specified by the input files, but received a D or E ("did poorly") in the other course.The script should exit with status 0 if execution completes normally, -1 if an error was encountered (see above).