Question: Please make sure your code(C++) will compile on Visual Studio 2015 correctly, and do not copy someone's code!!!!!!!!. Please show all the code not just

Please make sure your code(C++) will compile on Visual Studio 2015 correctly, and do not copy someone's code!!!!!!!!. Please show all the code not just some functions. Please show the result when you compile it on your visual studio. Really appreciate.

Develop a recursive function to determine the number of distinct ways in which a given amount of money in cents could be changed into quarters, dimes, nickels, and pennies. For example, if the amount is 17 cents, then there are six ways to make changes. Here is the sample output: 1) 1 dime, 1 nickel, and 2 pennies 2) 1 dime and 7 pennies 3) 3 nickels, and 2 pennies 4) 2 nickels, and 7 pennies 5) 1 nickels, and 12 pennies 6) 17 pennies Here is the function interface: // precondition: denomination = 1 (for penny), 2 (for nickel), 3 (for dime), or 4 (for quarter). // // postcondtion: If amount < 0, then 0 has been returned. Otherwise, the value returned is the // number of ways that amount can be changed into coins whose denomination is // no larger than denomination int ways (int amount, int denomination); For the sake of simplifying the ways function, develop a function coins that return the value of each denomination. Thus coins(1) returns 1, coins(2) returns 5, coins(3) returns 10, and coins(4) returns 25. Develop a main driver function that takes the user input of initial amount in cents and outputs the entire number of ways that amount can be changed into quarters, dimes, nickels, and pennies. Also printout an optimal way (with coin count) that minimize the number of coins for the specified amount of cents.

Hints:

Based on the Homework dealing with recursion, most of you would think the ways() is the recursive function. Ways() is just the driver to find the number of ways, print them and print the shortest path). Instead ways is a (regular) function that calls the recursive function. Call it something like waysRecursive. To know what to pass in the recursive function, consider what you need every combination of. You need every combination possible with Quarters, then every combination starting with dimes, then nickels then pennies. See attached output showing this with 53 cents as an example.

So, you probably have to know the amount (that presumably keeps lowering))

Then what else should you pass...probably the denomination since you are dealing with starting Quarters, then dimes, etc.

Then remember that you have to keep the shortest path (likely a list or a vector denoting the shortest path). If only there was a way to pass a variable that if it changes in the function, it also changes in the calling function.

There may be other functions that you want to write, like printing functions etc. Remember modular coding is much better than tons of lines of code in main or even other functions. At least by my solution, there is only one recursive function.

attached output

Please enter the amount in US currency (cents) to change: Optimal Combination: { 2 Quarters 3 Pennies } Total: 5 [1] { 2 Quarters 3 Pennies } Total: 5 [2] { 1 Quarter 2 Dimes 1 Nickel 3 Pennies } Total: 7 [3] { 1 Quarter 2 Dimes 8 Pennies } Total: 11 [4] { 1 Quarter 1 Dime 3 Nickels 3 Pennies } Total: 8 [5] { 1 Quarter 1 Dime 2 Nickels 8 Pennies } Total: 12 [6] { 1 Quarter 1 Dime 1 Nickel 13 Pennies } Total: 16 [7] { 1 Quarter 1 Dime 18 Pennies } Total: 20 [8] { 1 Quarter 5 Nickels 3 Pennies } Total: 9 [9] { 1 Quarter 4 Nickels 8 Pennies } Total: 13 [10] { 1 Quarter 3 Nickels 13 Pennies } Total: 17 [11] { 1 Quarter 2 Nickels 18 Pennies } Total: 21 [12] { 1 Quarter 1 Nickel 23 Pennies } Total: 25 [13] { 1 Quarter 28 Pennies } Total: 29 [14] { 5 Dimes 3 Pennies } Total: 8 [15] { 4 Dimes 2 Nickels 3 Pennies } Total: 9 [16] { 4 Dimes 1 Nickel 8 Pennies } Total: 13 [17] { 4 Dimes 13 Pennies } Total: 17 [18] { 3 Dimes 4 Nickels 3 Pennies } Total: 10 [19] { 3 Dimes 3 Nickels 8 Pennies } Total: 14 [20] { 3 Dimes 2 Nickels 13 Pennies } Total: 18 [21] { 3 Dimes 1 Nickel 18 Pennies } Total: 22 [22] { 3 Dimes 23 Pennies } Total: 26 [23] { 2 Dimes 6 Nickels 3 Pennies } Total: 11 [24] { 2 Dimes 5 Nickels 8 Pennies } Total: 15 [25] { 2 Dimes 4 Nickels 13 Pennies } Total: 19 [26] { 2 Dimes 3 Nickels 18 Pennies } Total: 23 [27] { 2 Dimes 2 Nickels 23 Pennies } Total: 27 [28] { 2 Dimes 1 Nickel 28 Pennies } Total: 31 [29] { 2 Dimes 33 Pennies } Total: 35 [30] { 1 Dime 8 Nickels 3 Pennies } Total: 12 [31] { 1 Dime 7 Nickels 8 Pennies } Total: 16 [32] { 1 Dime 6 Nickels 13 Pennies } Total: 20 [33] { 1 Dime 5 Nickels 18 Pennies } Total: 24 [34] { 1 Dime 4 Nickels 23 Pennies } Total: 28 [35] { 1 Dime 3 Nickels 28 Pennies } Total: 32 [36] { 1 Dime 2 Nickels 33 Pennies } Total: 36 [37] { 1 Dime 1 Nickel 38 Pennies } Total: 40 [38] { 1 Dime 43 Pennies } Total: 44 [39] { 10 Nickels 3 Pennies } Total: 13 [40] { 9 Nickels 8 Pennies } Total: 17 [41] { 8 Nickels 13 Pennies } Total: 21 [42] { 7 Nickels 18 Pennies } Total: 25 [43] { 6 Nickels 23 Pennies } Total: 29 [44] { 5 Nickels 28 Pennies } Total: 33 [45] { 4 Nickels 33 Pennies } Total: 37 [46] { 3 Nickels 38 Pennies } Total: 41 [47] { 2 Nickels 43 Pennies } Total: 45 [48] { 1 Nickel 48 Pennies } Total: 49 [49] { 53 Pennies } Total: 53 Total distinct coin combinations: 49 

Another Hint

The base case is if the amount == 0 you don't need to do anything, as the amount has been whittled down to zero. Remember in a void function you can just return (no variable).

For the recursion, at the start, if the amount >= 25 then you can add another quarter to the list and call the function (this time with quarters and the new amount), otherwise you have to look at the dimes. So, you would call the function with dimes and the new amount). Then if the new amount >= 10 then you can add another dime to the list,( and call the function with dimes and the new amount), otherwise you have to look at the nickels. Then if the new amount >=5 then you can add a nickel to the list, (and call the function with nickels and the new amount). otherwise you must look at pennies. If the new amount >=1 then you can add a penny to the list, (and call the function with penny and the new amount). By this time if the newest amount is zero, then there are no more coins to add to the list.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!