Program Assignment

Program Assignment #2 (covers enumerated types and array usage)
 
The cell phone company that you wrote last week’s program for would like to analyze and compare the phone
usage charges for customers in the low usage, mid usage, and high usage plans.  Therefore, they would like you to write a program to determine the lowest, highest, and average charges levied for cell phones in each of these plans. You will use arrays to store the cell phone charges data, and the low, high, average data.
 
One of the output files from week 1's program, USAGE.TXT, contained a phone number (string formatted as ###-###-####), a plan type (L for low use, M for mid use, and H for high use), and usage charges (a double floating point value, formatted to 2 decimal places) on each line.
 
Sample USAGE.TXT data file:
303-333-3333 M     56.87
720-777-7777 M     50.07
303-444-5555 U     99.99
720-888-9999 H    142.49
720-999-1111 H     78.49
720-222-2222 H     76.77
720-123-4567 L     14.79
 
The program should display a short description of what it will do to the user, and then read and process the data in the USAGE.TXT data file and produce a report.
 
When the program tries to open the data file, if the data file does not exist, the program should issue an error
message, and return from the main function with a return code of 1 (NOTE:  This means that if the program attempts to open the file from within another function, it will need to pass back information about the success or failure to main, so main can exit properly).
 
If the data file opens successfully, read the data from the file.  As you read each line of data, examine the plan type. Use it to place the phone charge for the phone into one of three arrays for further processing later in the program: 
 
 All phone charges for phones in the low usage plan will be placed in the first array. ·
 All phone charges for phones in the mid usage plan will be placed in the second array. ·
 All phone charges for phones in the high usage plan will be placed in the third array.  ·
 
Each array should be able to store up to 1000 phone charges.  Maintain separate counters for each array to keep track of how many charges you have stored in each one.  Your program must implement array bounds checking.  If there are too many charges stored in the file to fit in one (or more) of the array(s), issue an error
message to the user, and ignore any further file data for that  array.  The error message should only appear if there is too much data in the file (i.e. it should not appear if there are exactly 1000 charges of one type).
 
NOTE:  Do not perform any calculations while reading the data into the arrays.
Your program should recognize the end of file correctly, whether the last line in the file contains an end of line character or not (i.e. whether the data file ends at the end of the last line of data, or on the next blank line). 
 
HINT:  To make this happen, be sure to use correctly the priming read in your code.
After all the phone charges have been stored into one of the three arrays, use the data in the arrays to calculate
the low, high, and average charges levied for phones in each plan. Develop generic functions to do these calculations that can be called three times, once for each array.  Each function should have only two input parameters, an array and a count.
 
NOTE:  Do not sort the array data to find the high and low values.  Search the array for them.
 
The low, high, and average results returned from the calculation functions will be stored in three additional
arrays.  Each of these arrays will have three cells – one the low charge, one for the high charge, and one for the average charge.
 
First define an enumerated type with values of LOW, HIGH and AVERAGE (Remember that the ordinal value of the first enumerated value is 0 by default – so the ordinal values of these three enumerated values will be 0, 1 and 2). 
 
Create three arrays, each indexed by this enumerated type, to hold the low, high and average charges.  
 One array for the low, high and average phone charge for phones in the low usage plan·
 One array for the low, high and average phone charge for phones in the mid usage plan·
 One array for the low, high and average phone charge for phones in the high usage plan ·
 
Finally, write one generic function to display the results neatly to the screen, along with a count for each plan type.  This function should also be called three times: once for the low use plan statistics, once for the mid use
plan statistics, and once for the high use plan statistics,
 
Sample output:
 For 1 phones enrolled in the low usage plan:
   Lowest phone charge = $   14.79
  Highest phone charge = $   14.79
  Average phone charge = $   14.79
 
 For 2 phones enrolled in the mid usage plan:
   Lowest phone charge = $   50.07
  Highest phone charge = $   56.87
  Average phone charge = $   53.47
 
For 3 phones enrolled in the high usage plan:
   Lowest phone charge = $   76.77
  Highest phone charge = $  142.49
  Average phone charge = $   99.25
 
Note:  For formatting purposes, you can assume that all phone charges in the input file will be 999.99 or less.
 
Your program should take into account that there may be no phones enrolled in any one of the plans.
If there were no charges for one plan type, your output should indicate that fact, instead of displaying low, high, and average charges.
 
Example:
 There were NO phone charges for any phones on the mid usage plan.
 
When the program successfully completes, return from the main function with a return code of 0.
 
PROGRAM NOTES:
 
1.  Your program must conform to the CS362 Coding Standards specified in Content section 1.4. 
As such, the program must include a file header comment block at the top of the program, and each function must include a function header comment block.
2. This program must be of modular design (minimum of four functions that have parameters), must use proper parameter passing, and must define function prototypes above main.
 The breakdown of the code into functions must be logical, not arbitrary!·
 The main function should do little more than call other functions.·
o The function calls in main should provide an outline of the program tasks.
 The other functions should each perform ONE well-defined task.·
o Functions that contain only one or two lines of code should be avoided, since the overhead of calling them would not be worth it.
3. Descriptive function, constant and variable names should be used. Constants/variables should be  
commented.  All fixed values should be defined as constants.
4. All code will be structured C++ code.  Object-oriented programming (classes, templates, etc) will not be used. 
5.   Your program should be thoroughly tested, and test data files should be submitted.
Powered by