[Santa Clara University]
Department of Mathematics
and Computer Science

Machine Problem 2

Math 61
D. C. Smolarski, S.J.
Winter 2000

                
Data Structure Concepts: ARRAYS,
SORTING, SEARCHING,
STRUCTURES/CLASSES (RECORDS)
30 points
DUE: Noon, Thursday, January 27, 2000

Gentle Reminder: This program is to be done individually, without any collaboration! See the information found on the web page: General Rules and Other Information.

This program is supposed to simulate an accounting system. It should be written in C++.

You may create and run this program on a PC, but since this program should be run with two different input files, "hardcoding" the filename within the source code actually makes the assignment MORE difficult! (Alternatively, you can compile the code, and then go into DOS mode and use file redirection, but this may be less than desirable for many people!)

The input files have three sections to them.

Your program should do the following:
  1. Read in the accounts. There are no more than 20 but there may be fewer. The end of the accounts is indicated by the phony account number, 0000. When each line is read, the program should test the account number to determine when 0000 has been read and this section of the input file is ended. One should also keep track of how many actual accounts there are. (HINT: You might want to copy test2b.cxx [which uses standard C i/o (see this link for a brief overview)] or test2c.cxx [which uses C++ stream i/o] in my ma61 subdirectory [or at these links, test2b.cxx or test2c.cxx] to see how to do such a read-in of an arbitrary number of account lines terminated by a 0000 line.) (You can copy the file using the cp command as illustrated below.)
  2. Sort the accounts according to account number.
  3. Process both transaction sections, one section at a time. For each section, keep track of the total values of that type of transaction. (These totals will be outputed at the end.)
    The program should read in one transaction line, search the account list (using binary search) and modify the old balance.
    One should NOT read another transaction line before finishing the work on the previous one! You do not know the total number of transactions. There may be more than one transaction for each account and the total number of transactions may be much greater than the number of accounts! As with the previous section, the ends of each of these sections of input are also indicated by a phony account number, 0000.
    NOTE: Since there is no need to retain this "transaction" information after it has been used to modify the balances, one should NOT use an array to store these values!
  4. Print out the updated account list in NUMERICAL order by accounts with account number first, then name, then balance.
  5. Sort the accounts alphabetically according to the person's name. You will want to use the C/C++ library function "strcmp." To compare two strings, s1 and s2, one uses the function call
    strcmp(s1,s2)
    If s1 equals s2, the function call returns 0.
    If s1 is lexicographically less than s2, it returns a negative value.
    If s1 is lexicographically greater than s2, it returns a positive value.
    ("Lexicographically less than" means it precedes the other in the dictionary, i.e., it is in correct alphabetical order.)
    (Also see this link for additional information on "strings" [i.e., arrays of char], and associated functions.)

    By testing the return value, one can determine the order and then determine whether one needs to correct the order of s1 and s2 or not.

  6. Print out the updated account list in ALPHABETICAL order, with name first, then account number, then balance.
  7. Print out the total value of the debit transactions, and the total value of the credit transactions.

Run your program for TWO input files!

The input files can be copied from my subdirectory as follows:
      math 34:cp /home/dsmolars/ma61/mp2ina.inp  . 
      math 35:cp /home/dsmolars/ma61/mp2inb.inp  . 
or, they may be accessed at these links: mp2ina.inp and mp2inb.inp and downloaded to a disk via the web browser.

Input file format:
Account lines: 1-4 = account number, 7-30 = name, 35-42 = balance.
Transaction lines: 1-4 = account number, 7-15 = debit/credit

TURN IN: (1) print-out of the file with the C/C++ source code, (2) printout of the output file for EACH input file. NOTE: Remember to use good programming style, label your output, and include plenty of comments!!!


This page is maintained by Dennis C. Smolarski, S.J., dsmolarski@math.scu.edu. Last changed: 7 January 2000.