Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CODE IN C++ The Requirement (What you need to do) write a program that reads in a sequence of expenditure record, stores them, sorts the

CODE IN C++

The Requirement (What you need to do)

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 (some specifics that should display an error should any of the 4 be inputed by the user. ex. error is user inputs a negative dollar value -40.00 ): 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.

  1. The dollar amount cannot be greater than 9999.99
  2. The dollar amount cannot be negative
  3. There are at most two decimal digitals in the input
  4. Handle non-digit input, such as ten, for the dollar amount

Details

The following are more detailed requirement/hints with regards to how to implement the program:

  1. Design DollarAmount class
    1. What are the attributes of the object? What operations do you need to provide for object of this type?
    2. Write the class declaraion (i.e., class header file).
    3. Implement the class.
    4. 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).
  • int main() { ... DollarAmount * arr = new DollarAmount[INIT_SIZE]; DollarAmount * ptr=NULL;
  • 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 progaram 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions