Question
b.) (Lab5b.cpp) Write a program named Lab5b.cpp . This program reads expense data from a file in a predefined format and produces an expense report.
b.) (Lab5b.cpp) Write a program named Lab5b.cpp. This program reads expense data from a file in a predefined format and produces an expense report.
Follow the steps described here to complete the program.
Define a named constant for the size of the arrays. For example, const int NUM_DAYS = 7;
Define an array of strings for the days and an array of doubles for the expenses using the named constant as the array size. Initialize the array of doubles with 0.0, not 0. Each day in the array of days corresponds to the expense in the same position in the array of expenses.
Check. The arrays have been defined using meaningful identifiers.
Check. The arrays have been defined using the named constant as the array size.
Check. The array of doubles have been initialized with 0.0.
Define a named string constant for the file expenses.txt which was created by lab3a. You may also create the expense file by hand using a text editor.
Open the file using the named string constant.
Read the data from the expense file into the arrays. The code for reading the expense records should not assume there are exactly seven records in the file. Use a counter variable to keep track of the number of records received from the file. Other than reading and counting the number of expense records, don't do any data processing and reporting at this step.
Close the file.
Check. The number 7 is not used in any form in the process of reading the file.
Check. No calculation for total, average, and largest at this step.
Check. No reporting at this step.
Check. File is closed.
Process the data in the arrays. Calculate the total, average, and largest expense.
Generate the expenses report as shown below.
Check. The report is identical as shown above.
Check. Submit both Lab5b.cpp and expenses.txt.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started