Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Week 10 Adding Class to Your Programs Lab + Homework 10 - Piggy Bank ATM 2 Although Mr. Pigglesworth Bank has been your trusted piggy

Week 10 Adding Class to Your Programs

Lab + Homework 10 - Piggy Bank ATM 2

Although Mr. Pigglesworth Bank has been your trusted piggy bank since age 5, you have had enough of the establishment's antiquated style of service. You have decided to bring Mr. Pigglesworth into the modern era by programming an ATM application for your piggy bank. To model your piggy bank, you will define a class called Coins, which contains four integer members: quarters, dimes, nickels, and pennies. You will also define several member functions that will help you work with your Coins instances.

When your program is launched, it does the following.

1) It creates a Coin instance called piggyBank that contains 5 quarters, 10 dimes, 15, nickels,

and 20 pennies. Hint: Use a constructor.

2) The program calls ShowMenu() to display a menu of 5 choices: D for depositing coins in bank, W for withdrawing coins from bank, S for showing the account balance, and Q for quitting the program. The program then waits for the user to make a choice.

3) The program proceeds to carry out the action the user selected.

If D or d was selected, Coins member function EnterCoins() is called on an Coins

instance called amount to ask the user to specify how much of each type of coin should be deposited. Assume that the user always has the amount of coins they wish to deposit. Coins member function DepositCoins (Coins amount) is then called on piggyBank to deposit amounts quantity of coins before returning to step 2.

If W or w was selected, Coins member function EnterCoins() is called on a Coins instance called amount to ask the user to specify how much of each type of coin should be withdrawn from piggyBank. The Coins member function CoinsAvailable(Coins amount) is called on piggyBank to determine if the user is attempting to withdraw more coins than the bank contains. If the user is attempting to take more coins than the bank contains, the program cancels the transaction and displays an error message; otherwise, Coins member function WithdrawCoins(Coins amount) is called on piggyBank to remove the appropriate amount of coins from piggyBank. Either way, program returns to step 2.

If S or s was selected, the user is shown the quantities for each kind of coin in piggyBank. Program returns to step 2.

if Q or q was selected, the program quits.

If none of the above actions were selected, an error message is displayed before

returning to step 2.

Requirements:

1) The program must define a class called Coins that contains four private integer data members: quarters, dimes, nickels, and pennies.

CPSC 120 Week 10 2) The program must define and call these functions:

Coins ()

Coins class default constructor. It assigned all data members to zero.

Coins (int newQuarters, int newDimes, int newNickels, int newPennies)  

A Coins class constructor that takes in four parameters. The values of the parameters are assigned to the corresponding class data members.

void DepositCoins (Coins amount)  

A Coins class public member function that takes amount parameters data members (quarters, dimes, ...) and adds them to the corresponding data members within the instance.

void WidthdrawCoins (Coins amount)  

A Coins class public member function that takes the amount parameters data members and subtracts them from the corresponding data members of the instance.

bool CoinsAvailable (Coins amount)  

A Coins class public member function that allows you to test if the Coins instance has enough coins to complete a withdrawal transaction. Returns true when none of the amount parameters data members are greater than the instances corresponding data members. Otherwise, it returns false.

void EnterCoins ()

A Coins class public member function that asks the users for the number of quarters, dimes, nickels, and pennies and stores those quantities using the Coins instance's data members.

void ShowAccountBalance ()

A Coins class member function that displays the number of quarters, dimes, nickels, and pennies the class instances data members contain. See expected output for details.

void ShowMenu ()

A standard function that displays a menu of options to the user. See expected output for details.

3) Do not make adjustments to the above function headers. They must be used as is. There are no restrictions on other functions you choose to create.

4) Follow good code style guidelines.

Hints:

1) The assignment operator = works with classes, but most other operators, like + and - do not.

You will need to do all of the calculations on each of the Coins classes data members. The calculations will need to occur in class member functions because the data members are private.

2) Keep in mind that Coins class member functions have access to the private data members of the instance it is called on. They can also access the private data members of Coins objects passed as function parameters.

CPSC 120 Week 10

3) Class constructors must be public.

4) Write and test each function, one at a time. Testing as you go will give you confidence your

functions are correct. Waiting until after you have written everything before testing your program for the first time will make it 1000% harder to track down issues.

Expected Output:

------ATM Options------ D - Deposit coins in bank W - Withdraw coins from bank S - Show account balance Q - Quit ----------------------- 
Enter your selection: s ========Account======== Quarters: 5 Dimes: 10 
Nickels: 15 Pennies: 20 ======================= ------ATM Options------ D - Deposit coins in bank W - Withdraw coins from bank S - Show account balance Q - Quit ----------------------- 
Enter your selection: d Enter number of quarters: 2 Enter number of dimes: 4 Enter number of nickels: 6 Enter number of pennies: 8 ------ATM Options------ D - Deposit coins in bank W - Withdraw coins from bank S - Show account balance Q - Quit ----------------------- 
Enter your selection: s ========Account======== Quarters: 7 Dimes: 14 
Nickels: 21 Pennies: 28 ======================= ------ATM Options------ D - Deposit coins in bank 

CPSC 120

Week 10

W - Withdraw coins from bank S - Show account balance Q - Quit ----------------------- 
Enter your selection: w Enter number of quarters: 8 Enter number of dimes: 0 Enter number of nickels: 0 Enter number of pennies: 0 There are not enough coins to complete the transaction. ------ATM Options------ D - Deposit coins in bank W - Withdraw coins from bank S - Show account balance Q - Quit ----------------------- 
Enter your selection: s ========Account======== Quarters: 7 Dimes: 14 
Nickels: 21 Pennies: 28 ======================= ------ATM Options------ D - Deposit coins in bank W - Withdraw coins from bank S - Show account balance Q - Quit ----------------------- 
Enter your selection: w Enter number of quarters: 2 Enter number of dimes: 4 Enter number of nickels: 6 Enter number of pennies: 8 ------ATM Options------ D - Deposit coins in bank W - Withdraw coins from bank S - Show account balance Q - Quit ----------------------- 
Enter your selection: s ========Account======== Quarters: 5 Dimes: 10 

Nickels: 15

CPSC 120

Week 10

Pennies: 20 ======================= ------ATM Options------ D - Deposit coins in bank W - Withdraw coins from bank S - Show account balance Q - Quit ----------------------- 
Enter your selection: q 

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

Mastering Influxdb Database A Comprehensive Guide To Learn Influxdb Database

Authors: Cybellium Ltd ,Kris Hermans

1st Edition

B0CNGGWL7B, 979-8867766450

More Books

Students also viewed these Databases questions

Question

A) 10 B) 25 C) 50 D) 100 E) 200 A) 10 B) 25 C) 50 D) 100 E) 200

Answered: 1 week ago