Starting from:

$30

CS52-Assignment 5 Wallet and Record Player Solved

Following the 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 << "\nYou now have: " << endl;
cout << "Dollars:" << w.getDollars() << endl << "Cents:" << w.getCents() << endl;
}
else {
cout << "\nSorry, 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


Record Player
Following the  diagram shown below, create the class RecordPlayer. An RecordPlayerrepresents a stereo component that can play vinyl records. Please review the class and the sample driver code. There is a specific order to the way the class methods should be called. In other words, you can’t plop the Needle unless there actually is a record on the player and the recordplayeris turned on. You also can’t return the Needle unless there is actually a record on the player and the recordplayeris turned on. Your class should enforce these rules and write errors to cout as they occur. A sample driver for this class is shown below.

Rules of the record player
You can affix a platter if the record player is on or off and the needle is not ploped
Record player must be on and must have record affixed to the platter to plop the needle on the record
Can only return the needle if the record player is on and there is a record on the player
Performing the same action twice results in a “no-op” where nothing changes. For example, you can’t plop an already plopped needle, and you can’t return a needle that’s already returned. Another example: you can’t turn on/off a record player that is already on
Please note: codeboard must test differently for this project. There is no input. The provided driver will be called automatically. Your code will not compile when you start the project; only when you’ve implemented the RecordPlayer class will it compile successfully.

Record Player
RecordPlayer( );

void turnOn( );
void turnOff( );
bool isPoweredOn( );
void affixPlatter( string record );
void plopNeedle( );
void returnNeedle( );


bool isOn;
string record;
bool needleIsOnTheRecord;
Record Player Sample Driver Code
//declare 6 RecordPlayers
RecordPlayer good_r, bad_r1, bad_r2, bad_r3, bad_r4, bad_r5;

//first test correct
good_r.turnOn();
good_r.affixPlatter("Barrow Manila I");
good_r.plopNeedle();
good_r.returnNeedle();
good_r.turnOff();

//bad test, plops needle without turning it on or putting record on
bad_r1.plopNeedle();

//turns it on but no record on platter
bad_r2.turnOn();
bad_r2.plopNeedle();

//not on nor has album on platter
bad_r3.returnNeedle();

//turned on but no album
bad_r4.turnOn();
bad_r4.returnNeedle();

//not turned on
bad_r5.affixPlatter("Barrow Manila I");
bad_r5.plopNeedle();
Record Player Sample Driver Code Output
Record player is turned on
Record Barrow Manila I is now on the platter
Needle is placed on the record
Needle is returned from the record
Record player is turned off
Cannot place needle on the record
Record player is turned on
Cannot place needle on the record
Cannot return needle from the record
Record player is turned on
Cannot return needle from the record
Record Barrow Manila I is now on the platter
Cannot place needle on the record

More products