Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 

Numbers in bold are user input and can be any number

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

2nd Edition

1597499471, 978-1597499477

More Books

Students also viewed these Databases questions

Question

3. Existing organizations and programs constrain behavior.

Answered: 1 week ago