Question

0.000 GoSmart令 12:01 PM uploads.s3.amazonaws.com 2 _your name.c and bon us your name.c for problems form coins 1 and 2, respectively. Substitute your first and last name for your_name in the file name. Problem Statements 1. Given a value V in cents, you need to make change using a minimum number of coins. Assume you have an infinite supply of quarters, nickels, dimes, and pennies. Find the minimum number of coins. Display the quantity of each coin and the total number of coins, similar to the example output below Use global constant identifiers, of type unsigned int, for the values of quarters, nickels, dimes, and pennies. Example: const unsigned int QUARTER 25; Do not use any other global variables. The data type for the value V must be unsigned integer CAUsers Diane\Desktoptwed\binkDebuglwed.exe hange for 99 centrs Quarters Niekels 4 Pennies 9 Total Coins rocess returned 8GBx8》 execution tine 13.424 any ke 2. A company gives a bonus to all its employees. A 2% bonus on salary is given to employees who have been with the
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note that

quarter = 25 cents, dime = 10 cents, nickel = 5 cents, penny = 1 cent

C++ code:

#include<bits/stdc++.h>
using namespace std;

int CoinChange(vector<int> coins,int m, int change)
{
    vector<int> S(change + 1,1000);
    vector<int> seq(change + 1);
    S[0] = 0;
    for(int i = 1; i < change + 1; i++)
    {
        for(int j =0;j<m; j++)
        {
            if(i >= coins[j] && 1 + S[i-coins[j]] < S[i])
            {
                S[i] = 1 + S[i - coins[j]];
                seq[i] = j;
            }
        }
    }
    map<string, int> mymap;
    mymap["Quartar"] = 0;    //quarter = 25 cents, dime = 10 cents, nickel = 5 cents, penny = 1 cent
    mymap["dime"] = 0;
    mymap["nickel"] = 0;
    mymap["penny"] = 0;

    int j = change;
    while(j)
    {
        if(coins[seq[j]] == 1)
        {
            mymap["penny"] += 1;
        }
        else if(coins[seq[j]] == 5)
        {
            mymap["nickel"] += 1;
        }
        else if(coins[seq[j]] == 10)
        {
            mymap["dime"] += 1;
        }
        else
        {
            mymap["Quartar"] += 1;
        }
        j = j - coins[seq[j]];
    }
    cout << "Coins Needed: \n";
    for (std::map<string,int>::iterator it=mymap.begin(); it!=mymap.end(); ++it)
    {
        std::cout << it->first << " => " << it->second << '\n';
    }
    cout<<endl;
    // cout << "Total Coins Needed: \n" << S[change];
    return S[change];
}

int main()
{
    vector<int> coins;
    coins.push_back(25);coins.push_back(10);
    coins.push_back(5);coins.push_back(1);
    int m = 4;
    int V;
    printf("Enter cents value\n");
    scanf("%d",&V);
    printf("Minimum coins required is %d " , CoinChange(coins, m, V));  
    return 0;
}

Sample Output:

C:\Users\Akash\Desktop\HomeworkLib>a
Enter cents value
99
Coins Needed:
Quartar => 3
dime => 2
nickel => 0
penny => 4

Minimum coins required is 9
C:\Users\Akash\Desktop\HomeworkLib>a
Enter cents value
101
Coins Needed:
Quartar => 4
dime => 0
nickel => 0
penny => 1

Minimum coins required is 5

Add a comment
Know the answer?
Add Answer to:
Given a value V in cents, you need to make change using a minimum number of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ELEC 1520 Homework - Integer Operations, Selection Statements Instructions Write C++ programs to solve the following...

    ELEC 1520 Homework - Integer Operations, Selection Statements Instructions Write C++ programs to solve the following two problems. Upload your source code files to Canvas. The file names must be of the form coins_your_name.cpp and bonus_your_name.cpp for problems 1 and 2, respectively. Substitute your first and last name for "your_name" in the file name. Problem Statements 1. Given a value V in cents, you need to make change using a minimum number of coins. Assume you have an infinite supply...

  • Can you please help me with creating this Java Code using the following pseudocode? Make Change C...

    Can you please help me with creating this Java Code using the following pseudocode? Make Change Calculator (100 points + 5 ex.cr.)                                                                                                                                  2019 In this program (closely related to the change calculator done as the prior assignment) you will make “change for a dollar” using the most efficient set of coins possible. In Part A you will give the fewest quarters, dimes, nickels, and pennies possible (i.e., without regard to any ‘limits’ on coin counts), but in Part B you...

  • (In Python 3) Write a program with total change amount as an integer input, and output...

    (In Python 3) Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies. Ex: If the input is: 0 (or less than 0), the output is: No change Ex: If the input is: 45 the output is: 1 Quarter 2 Dimes So...

  • Write a program with total change amount as an integer input, and output the change using...

    Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies. Ex: If the input is: 0 the output is: No change Ex: If the input is: 45 the output is: 1 Quarter 2 Dimes

  • Word Problems Workshee You have a jar of loose change which contains pen total value of...

    Word Problems Workshee You have a jar of loose change which contains pen total value of the change in the jar is $104. In total, there are exactly 1000 coins in the jar There are four times as many pennies as there are nickels and there are twice as many pennies as there are dimes. How many of each type of coin are there? 4. nies, nickels, dimes, and quarters. The

  • it c++ coding. please write on atom software. 1. Write a program that converts dollars into coins a. Request a dolla...

    it c++ coding. please write on atom software. 1. Write a program that converts dollars into coins a. Request a dollar amount as an integer: $5.34 is input as 534 b. Use a constant variable to represent each coin as a fixed value: const int NICKEL 5; c. Use division and the mod function to calculate the number of each coin. Change Calculator Enter dollar amount (as an integer): $534 The equivalent in coins: 21 Quarters 0 Dimes 1 Nickels...

  • Develop the Change Calculator application In this exercise, you’ll create an application that displays the minimum...

    Develop the Change Calculator application In this exercise, you’ll create an application that displays the minimum number of quarters, dimes, nickels, and pennies that make up the number of cents specified by the user. Without the use of a JavaScript Library (for coins). 1.      Open the HTML and JavaScript files below: 2.      In the JavaScript file, note that three functions are supplied. The $ function. The start of a calculateChange function. And an onload event handler that attaches the calculateChange...

  • I made this C program to count change and make a slip saying the exact dollar...

    I made this C program to count change and make a slip saying the exact dollar and change amount given. every time I run the program it says the change given is 477256577 and i'm not sure what I have done wrong? #include<stdio.h> int main(void) { char first, last; int pennies; int nickels; int dimes; int quarters; int loonies; int change; int t_dollars; int t_cents; printf("Type in your 2 initials and press return> "); scanf("%c%c",&first,&last); printf("%c%c please enter in your...

  • Write a C program that calculates exact change. In order to receive full credit, please remember...

    Write a C program that calculates exact change. In order to receive full credit, please remember that only int arithmetic is exact, so you’ll need to break up your double into two ints, the one before the decimal point and the one after the decimal point. Another point worth mentioning is that the % operator gives the remainder. In other words, when working with int values, 9 / 5 = 1 whereas 9 % 5 = 4. Keep this in...

  • PLease help!!! how to type them in Python !!!! Python help!! THank you so much Problem...

    PLease help!!! how to type them in Python !!!! Python help!! THank you so much Problem 1: (20 points) Optimal change You will write a program that uses the // and % operators to figure out how to give change for a specified amount using the minimum number of coins (quarters, dimes, nickels, cents). The good news is that our currency is specifically designed to make this problem easy. For a given number of cents, first use as many quarters...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT