Question: Wallet Following the class diagram shown below, create the class Wallet. A Wallet represents a carrier of bills and coins. You use your wallet to

Wallet

Following the class diagram shown below, create the class Wallet. A Wallet represents a carrier of bills and coins. You use your wallet to pay for things, which reduces the balance held inside. When you visit an ATM, you can fill it back up with cash again. A sample driver for this class is shown below. You should probably make a more thorough driver to test your class better. I will have my own driver which will aim to exploit any possible edge cases.

Wallet Class Description

Wallet( );

Wallet( int d, int c );

int getDollars( );

int getCents( );

bool canPayFor( int dollarAmount, int centsAmount );

void payFor( int dollarAmount, int changeAmount );

void visitATMForCash( int dollarAmount );

int dollars;

int cents;

Wallet Sample Driver Code

int atm = 0, d = 0, c = 0, x = 0, y = 0;

char cont = 'y';

cout << "Hello, how much money do you have in your wallet?" << endl;

cout << "Dollars: ";

cin >> d;

cout << "Cents: ";

cin >> c;

cout << endl;

Wallet w(d, c);

cout << "How many dollars would you like to withdraw from the ATM? ";

cin >> atm;

w.visitATMForCash(atm);

cout << "Currently you have: " << endl;

cout << "Dollars: " << w.getDollars() << endl << "Cents: " << w.getCents() << endl << endl;

do {

cout << "How much are you going to spend?" << endl;

cout << "Dollars: ";

cin >> x;

cout << "Cents: ";

cin >> y;

if (w.canPayFor(x, y) == true) {

w.payFor(x, y);

cout << " You now have: " << endl;

cout << "Dollars:" << w.getDollars() << endl << "Cents:" << w.getCents() << endl;

}

else {

cout << " Sorry, you do not have enough money to spend. Please spend less." << endl;

}

cout << "Are you spending more money (y/n)? ";

cin >> cont;

cout << endl;

} while (cont == 'y');

cout << "You have this amount left in your wallet: " << endl;

cout << "Dollars: " << w.getDollars() << " Cents: " << w.getCents() << endl << endl;

Sample Driver Output

Hello, how much money do you have in your wallet?

Dollars: 10

Cents: 0

How many dollars would you like to withdraw from the ATM? 5

Currently you have:

Dollars: 15

Cents: 0

How much are you going to spend?

Dollars: 6

Cents: 56

You now have:

Dollars: 8

Cents: 44

Are you spending more money (y/n)? y

How much are you going to spend?

Dollars: 10

Cents: 0

Sorry, you do not have enough money to spend. Please spend less.

Are you spending more money (y/n)? n

You have this amount left in your wallet:

Dollars: 8 Cents: 44

Your submission should follow this organization:

main.cpp this is your driver file wallet.h wallet.cpp

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!