Answer to Question #286648 in HTML/JavaScript Web Application for Areeb

Question #286648

Write a JavaScript program which accepts amount in rupees as input (integer) within Range from

Rs. 100 to Rs. 100000 and then asks the user for particular currency note preference and display the total

number of currency notes of Rs. 500, 100, 50, 20, 10, 5, and 1. The user can be given a maximum of 200

notes of his preferred choice. (5 marks)

For example: when a user enters a number, Rs. 57477 and enters 50 notes as his preferred choice, the

results would be like this.

Currency Note : Number

500 : 94

100 : 4

50 : 200

20 : 3

10 : 1

5 : 1

1 : 2


1
Expert's answer
2022-01-11T14:38:59-0500
#include <iostream>


template ​<int denom, typename T>
class rupeeChange {
public:
static T result(T a, T b) {


    int leftOver = b;
    int dcount = 0;


    if (denom == 0) 
    {
        leftOver = b;
        dcount = b / a;
        leftOver %= a;
        if (dcount > 200) { leftOver += a * (dcount - 200); dcount = 200; }


        if (dcount > 0)
            std::cout << "\tGive " << dcount << " of Denomination "
                << a << " (Favorite) " << std::endl;
    }
    else if (b != 0 && a !=  denom) 
    {
        leftOver = b;
        dcount = b / denom;
        leftOver %= denom;
        if (dcount > 200) { leftOver += denom * (dcount - 200); dcount = 200; }


        if (dcount > 0)
            std::cout << "\tGive " << dcount << " of Denomination "
                << denom << std::endl;
    }


    if (denom == 0) 
        return rupeeChange <500, T>::result(a, leftOver);
    else if (denom == 500)
        return rupeeChange<100, T>::result(a, leftOver);
    else if (denom == 100)
        return rupeeChange<50, T>::result(a, leftOver);
    else if (denom == 50)
        return rupeeChange<20, T>::result(a, leftOver);
    else if (denom == 20)
        return rupeeChange<10, T>::result(a, leftOver);
    else if (denom == 10)
        return rupeeChange<5, T>::result(a, leftOver);
    else if (denom == 5)
        return rupeeChange<1, T>::result(a, leftOver);


    return dcount;
  }
};
template ​< typename T>
class rupeeChange<1, T> {
 public:
  static T result(T a, T b) {
    if ( b > 0 )
        std::cout << "\tGive " << b << " of Denomination " << 1 << std::endl;
  return 0;
  }
};
template ​<int denom, typename T>
inline T Results(T a, T b)
{
  std::cout << "\nCashing out " << b << "..." << std::endl;
  return rupeeChange<0, T>::result(a, b);
}


int main()
{
  Results<0>(5, 5006);
  Results<0>(500, 99502);
  Results<0>(500, 7519);
 Results<0>(1, 7509);

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS