Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement a class named Purse that represent a coin purse: ? An object represent

ID: 3542849 • Letter: I

Question

Implement a class named Purse that represent a coin purse:

? An object represents a coin changer or coin purse that can contain any number of pennies, nickels,

dimes, and quarters.

? Constructor - Creates a purse with a given number of pennies, nickels, dimes, and quarters.

? Reporters:

? get_pennies Returns the total monetary value in the purse in pennies.

? get_nickels Returns the total monetary value in the purse in nickels.

? get_dimes Returns the total monetary value in the purse in dimes.

? get_quarters Returns the total monetary value in the purse in quarters.

? get_dollars Returns the total monetary value in the purse in dollars.

? reduce() - this function enforces a constraint that minimizes the total number of coins for a given dollar

amount. And this function is called by other functions that can change the contents of the purse: insert()

and remove() functions.

? insert(float dollars) increase the total amount in the purse. And it needs to call the reduce() to enforce

the constraint as mentioned before.

? remove(float dollars) reduces the total amount by that many dollars in the purse. And it needs to call the

reduce() to enforce the constraint as mentioned before.

Explanation / Answer

please rate - thanks


any quedstions - ask


#include <iostream>
using namespace std;
class Purse
{private:
int quarters;
int dimes;
int nickels;
int pennies;
public:
Purse(int q,int d,int n,int p)
{quarters=q;
dimes=d;
nickels=n;
pennies=p;
            }      
      
float get_pennies()
{return pennies*.01;
}
float get_nickels()
{return nickels*.05;
}
float get_dimes()
{return dimes*.1;
}
float get_quarters()
{return quarters*.25;
}
float get_dollars()
{return get_pennies()+get_nickels()+get_dimes()+get_quarters();
}
void reduce(float total)
{int t=(int)(total*100);
quarters=t/25;
t%=25;
dimes=t/10;
t%=10;
nickels=t/5;
pennies=t%5;
}
void insert( float dollars)
{float total=get_dollars()+dollars;
reduce(total);
}
void remove(float dollars)
{float total=get_dollars()-dollars;
reduce(total);
}


};

int main()
{Purse p(1,1,1,1);
cout<<p.get_dollars()<<endl;
p.insert(2);
cout<<"Total = $"<<p.get_dollars()<<endl;
cout<<p.get_quarters()<<" in quarters ";
cout<<p.get_dimes()<<" in dimes ";
cout<<p.get_nickels()<<" in nickels ";
cout<<p.get_pennies()<<" in pennies ";
p.remove(1);
cout<<"Total = $"<<p.get_dollars()<<endl;
cout<<p.get_quarters()<<" in quarters ";
cout<<p.get_dimes()<<" in dimes ";
cout<<p.get_nickels()<<" in nickels ";
cout<<p.get_pennies()<<" in pennies ";
     system("pause");
     return 0;
     }


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote