Objective: Generate a coin dispenser machine. This machine would dispense change for any appropriate monetary value. This value should be less than $100. The machine uses an algorithm which dispenses the least number of coins based on the US coin system of quarters, dimes, nickels, and pennies. The coin dispenser is also able to accept any number of coins and refund that amount to your credit card. So, the dispenser works in two ways. Write two programs for this purpose. If you're confident with creating functions, you may store each program in its own function. Both functions as well as the function calls and test cases must be written in a single file. 1- Write a program that would prompt the user to input some value in dollars and cents in the format of $x.xx and solve the equivalent number of coins. The machine asks for the dollar amount of coin change that the user would need. For an input of $5.42 the machine dispenses the following: - 21 quarters - 1 dime - 1 nickel - 2 pennies To do this, you would first need to convert the input amount into cents: $x.xx?100 (cents) You now have an integer number of pennies that need to be divided into 25 s,10 s, 5 s and single pennies. The coin designations are easily found by an algorithm the uses the two operators (/ for int division) and (\% for remaining amount). The algorithm is shown below:
$5.42 is equivalent to 542 cents. First decide on the number of larger coins, quarters 542/25??>21 quarters 542%25?>17 cents of change Next count out the number of dimes. 17/10???>1 dime 17%10----> 7 cents of change After that count the number of nickels 7 / 5 ----> 1 nickel 7%5??>2 cents left Finally, pennies are remaining, must be less than 5 pennies 2 pennies are what's left. The next step is displaying the original dollar amount along with the coin designations and their number. The display should print something similar to follows: Value: $5.42 Quarter: 21 Dime: 1 Nickel: 1 Penny: 2 Note 1: Test your program on many variations of values. If a negative amount is input, the program should reject it and abort. Use exit(1) function to abort. This function can be used by including the header \#include ?cstdlib?. Note2: All the coins must be declared as CONST variables and used by their identifier names all throughout the program. For example: CONST int QUARTER =25; // this variable is a constant and cannot be modified.
2- Your coin dispenser should also work the other way around, by receiving coins it would determine the dollar value. Write another program that allows the user to enter how many quarters, dimes, nickels, and pennies they have and then outputs the monetary value in form of $x?xx. For example, if the user enters 4 for the number of quarters, 3 for the number of dimes, and 1 for the number of nickels, then the program should output that the coins are worth $1.35. a) What are inputs to the program? Declare all the input values as appropriate types. b) Create a prompting message to prompt the user to input their coin denominations. c) What's the expected output? Declare appropriate variables for to store the results. d) What's the algorithm to solve the problem? How do you relate the inputs to the output? - Make use of the arithmetic operators to solve this problem. - To separate the dollars and cents use the \% and / operator respectively. For the above example 135 cents: 135/100=1 (dollars) and 135%100=35 (cents). e) Display the outputs in an informative manner.