Demonstrate defining and opening input and output file streams, reading data from a file, writing data to a file, modularizing code using functions that return values and the use of default parameter values.
Instructions:
Due to your hard work for Broken Arrow Cellular, Mr. Bitsworth, MBA, CDO, ROTFL, has reviewed your code and, while he likes the way it works, believes it has become too large and wants you to break the code into more manageable modules, read the input from a file and write the output to a file. He wants the functions defined below written to modularize the code. Starting with Programming Assignment 4, fix any errors that remain in it, then:
1. Ask the user for the input file name (
customerData.dat
) and the output file name (BACBilling.txt).
a. Declare input and output stream objects and then open both files.
b. If either file fails to open, display a message and ask the operator to re-enter the file name.
2. Aside from the file names entered by the user, all input will come from the input file stream and all output will go to the output file stream.
3. Write a function that, when given the customer status, returns the appropriate discount. The prototype is:
double calculateDiscount(char = 'N');
4. Write a function that , when given the GB usage and the discount, returns the amount of the bill. The prototype is:
double calculateAmount(double = 0.0, double = 0.0);
5. The output, which will be written to the output file, should look exactly like the output from Programming Assignment 4.
6. Don't forget to close the files.
Work Products:
Submit:
- Design artifacts, completed BEFORE you begin to code! (.txt or .docx).
- C++ program file containing your solution (.cpp).
Grading:
I will be grading the following:
- Design artifacts (algorithm or pseudo-code). I expect to see evidence it was completed before the code was started.
- Comments and formatting.
- Correct use of C++ constructs: for statement, input and out file stream objects, running totals, functions output formatting.
- Correct input order and format.
- Correct output values and format (which includes spacing, symbols and precision) in the output file.
Hints:
1. Do not try to code all functions at once. Code one at a time and get it working before going to the next. (Turning in a program with one working function will get more points than a program with no working functions.)
2. Comment out the code from the main program that you want to put in a function. That way you can refer back to it while writing the function. When the function is working, delete the commented code.
3. The output should be the same as Programming Assignment 4, so refer to that assignment if you need to see an output example.
End of Programming Assignment 5.