Question
Code a program in c++ with the following requirements met (needs to be in one file without .h files, everything in one .cpp file): Step
Code a program in c++ with the following requirements met (needs to be in one file without .h files, everything in one .cpp file):
Step 1. (5 points) In class CoinPurse, write two CoinPurse constructors: default: set all coin counts to zero 2nd: set all coin counts to initial values; use parameters for: quarter, dime, nickel, penny IMPORTANT: prohibit negative values - if negative attempted, set to 0 tip: you can combine both of these into one constructor
Step 2. (5 points) In main, in one statement, declare a new CoinPurse object called purse1 and initialize purse1 with: 4 quarters, 3 dimes, 2 nickels, 1 penny
Step 3. (5 points) In class CoinPurse, write the definition for a new public member function: total_value. total_value returns the total value of all quarters, dimes, nickels and pennies in a CoinPurse object. For example: a purse with 4 quarters, 3 dimes, 2 nickels and 1 penny has a total value of (4*25)+(3*10)++(2*5)+(1*1)=141 (cents)
Step 4. (5 points) In main, write code to call the total_value method on the purse1 object. Display the returned value, which is the total value of the coins in purse1. Format the output so it prints in dollars and cents. Example: $1.41
Step 5. (5 points) In class CoinPurse, implement a mutator/setter called set() which sets the coin counts of all coins. Pre-validate any new coin counts; do not allow any coin count to be less than zero. If the ANY of the coin counts are invalid (negative), do not modify ANY coin counts. If the set() succeeds, return true; if the set() fails, return false
Step 6. (5 points) To avoid redundant code and insure proper validation, modify constructor(s) as needed to call set() instead of using redundant code.
Step 7. (5 points) In class CoinPurse, write a show() method that outputs the number of each coin in the purse in one string, like this: "(q=4 d=3 n=2 p=1)" (don't < Step 8. (5 points) In main, call set to change the values in purse1 to: 8 quarters, 7 dimes, 6 nickels, 5 pennies. In main, Call show to display the contents of purse1 (number of each coin). Step 9. (5 points) In class CoinPurse, write one modify() method that modifies coin counts using a positive (increment), negative (decrement) or zero (keep the same) value. For example: purse1.modify(0, 0, 2, -3) This will: keep quarters, dimes the same; increase nickels by 2, and decrease pennies by 3. IMPORTANT! Do not allow coin counts to become less than zero! If ANY coin will become negative, don't make any changes. If the modify() succeeds, return true; if the modify() fails, return false Step 10 (5 points) In main, write a menu driven loop that allows the user the add or remove coins from purse1. In a loop, display the total value, coins and options. Use s to stop. For example: $3.05 (q=8 d=7 n=6 p=5) Modify p)enny n)ickel d)ime q)uarter s)top: p -3 $3.02 (q=8 d=7 n=6 p=2) Modify p)enny n)ickel d)ime q)uarter s)top: n 0 $3.02 (q=8 d=7 n=6 p=2) Modify p)enny n)ickel d)ime q)uarter s)top: d 2 $3.12 (q=8 d=9 n=6 p=2) Modify p)enny n)ickel d)ime q)uarter s)top: q -4 $2.12 (q=4 d=9 n=6 p=2) Modify p)enny n)ickel d)ime q)uarter s)top: s Your user interface should look like this. Step 11 (10 points) Test your code as described above, and paste the output at the bottom. Step 12 (5 points, EXTRA CREDIT) Add a new option that allows the user to add a specific amount of cents That is, instead of the user specifying a specific coin and count, the computer determines the coin counts, based on the cents to add. For example: $1.41 (q=4 d=3 n=2 p=1) Modify c)ents p)enny n)ickel d)ime q)uarter s)top: c 125 $2.66 (q=9 d=3 n=2 p=1) Modify c)ents p)enny n)ickel d)ime q)uarter s)top: c 24 $2.90 (q=9 d=5 n=2 p=5) Modify c)ents p)enny n)ickel d)ime q)uarter s)top: s When adding cents, add the fewest number of coins possible. That is, first add as many quarters as possible, then as many dimes as possible, then nickels and pennies. As a result, adding cents never adds more than 2 dimes, 1 nickel, or 4 pennies. If doing Step 12, do Step 11 (test and paste output at the bottom) LAST.
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