Question
CODE IN C++ You are asked to write a program that reads in a sequence of expenditure record, stores them, sorts the records based upon
CODE IN C++
You are asked to write a program that reads in a sequence of expenditure record, stores them, sorts the records based upon the dollar amount in increasing order, and then reports the total and median expenditure amount.
Use case (Scenario)
$RecordKeeper Enter the expenditure record (e.g., $1.95, coffee, enter 0.0 to end):$8.45 Enter the expenditure record (e.g., $1.95, coffee, enter 0.0 to end):$45.03 Enter the expenditure record (e.g., $1.95, coffee, enter 0.0 to end):$2.03 Enter the expenditure record (e.g., $1.95, coffee, enter 0.0 to end):$0.0 Sorted list of expenditure: $2.03 $8.45 $45.03 The total is $55.51 (Fifty five and 51/100). The median is $8.45. Bye!
Error handling: You are required to handle the following error inputs. If the input is any of the following case, your program should display appropriate error message, and ask the user to try again.
- The dollar amount cannot be greater than 9999.99
- The dollar amount cannot be negative
- There are at most two decimal digitals in the input
- Handle non-digit input, such as ten, for the dollar amount
Details: 1. design a DollarAmount class. - Write the class declaration -implement the class -test the class
2. overload input operator (>>) (this includes your previous code that handles errors in input).
3. overload output operator (<<) (which displays the amount in the format of $234.54.
4.overload addition operator +, to be used to calculate the total amount
5. overload greater-than operator > (so that we can use the template sort function, which uses >)
In the driver program main() function, dynamically allocate an array of DollarAmount of a certain initial size, enter a loop to read input (until 0.0 is entered). If the array is filled up, you need to grow the array (by allocating a new array of larger size, copying existing elements into the new array). After the user finishes with the input, the program calculates and displays the total dollar amount, then sorts the array, displays the sorted array, and the median dollar amount.
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