Question
//Program Name: Bank.cpp Student Starting File //Author: // parts from Gaddis // // //Brief Description: This is the tester/driver application // for the BankAccount and
//Program Name: Bank.cpp Student Starting File
//Author:
// parts from Gaddis
//
//
//Brief Description: This is the tester/driver application
// for the BankAccount and CheckingAccount classes.
//
#include
#include
#include
#include "BankAccount.h" //the class definition
using namespace std;
void displayMenu();
double getValidData();
//***************************************************
// main
//***************************************************
int main()
{
BankAccount studentAccount; //declare and create with constructor
int choice = 0;
int iValue = 0;
string name = "unknown";
do {
displayMenu();
cin >> choice;
cout
switch (choice)
{
case 1 : cout
studentAccount.deposit(getValidData());
break;
case 2 : cout
studentAccount.withdraw(getValidData());
break;
case 3 : cout
cin.ignore(); //skips the newline char
getline(cin,name); //reads an entire line
studentAccount.setName(name);
break;
case 4 : cout
studentAccount.setAcctNumber(static_cast
break;
case 5 : studentAccount.displayData(); //display all account data
break;
case 6 : cout
break;
default : cout
}//switch
}while (choice != 6);
return 0;
}//end of main
//This function displays the user's menu on the screen.
//This is NOT a BankAccount member function
void displayMenu()
{
cout
cout
cout
cout
cout
cout
cout
cout
}
//This function prompts the user for a number
//and checks to see if 0 or greater. Returns
//a valid number
double getValidData()
{
double amount = 0;
cout
cin >> amount;
while (amount
{
cout
cin >> amount;
}
return amount;
}
/*Expected output
Welcome to your bank
1. Make a deposit
2. Make a withdrawal
3. Set the account name
4. Set the account number
5. Display account information
6. Exit
Please enter your choice: 1
Deposit amount. Enter value: -4
Enter value: (0 or greater): 10
Welcome to your bank
1. Make a deposit
2. Make a withdrawal
3. Set the account name
4. Set the account number
5. Display account information
6. Exit
Please enter your choice: 2
Withdraw amount. Enter value: -5
Enter value: (0 or greater): 5
Welcome to your bank
1. Make a deposit
2. Make a withdrawal
3. Set the account name
4. Set the account number
5. Display account information
6. Exit
Please enter your choice: 3
Enter the name: Bart Simpson
Welcome to your bank
1. Make a deposit
2. Make a withdrawal
3. Set the account name
4. Set the account number
5. Display account information
6. Exit
Please enter your choice: 4
Account number. Enter value: 2345
Welcome to your bank
1. Make a deposit
2. Make a withdrawal
3. Set the account name
4. Set the account number
5. Display account information
6. Exit
Please enter your choice: 5
Account Information
-------------------
Number: 2345
Name:Bart Simpson
Balance: 5.00
Welcome to your bank
1. Make a deposit
2. Make a withdrawal
3. Set the account name
4. Set the account number
5. Display account information
6. Exit
Please enter your choice:
*/
**********************************************************************
//Program Id: BankAccount.h Student Starting File
// BankAccount class declaration and implementation
// Separate Files
//Author: Patricia Baker
//Chapter 7: Writing Classes
//Description:
// Basic bank account assignment.
//
// Concepts covered:
// protected member variables
// public member functions - accesssor/get and mutator/set
// default constructors
#include
#include
#include
using namespace std;
//BankAccount class declaration
class BankAccount
{
private:
int acctNumber;
string name;
double balance;
public:
BankAccount();
BankAccount(int aNum, string aName, double amount);
void setAcctNumber(int aNum);
void setName(string aName);
void setBalance(double amount);
int getAcctNumber();
string getName();
double getBalance();
void deposit(double amount);
void withdraw(double amount);
void displayData();
};//End of BankAccount class declaration
//Member function implementation section
// Constructor function. Initializes acctNumber to 0, name to Unknown and
// balance to 0.0.
BankAccount::BankAccount()
{
acctNumber = 0;
name = "Unknown";
balance = 0.0;
}
//Overloaded constructor. overloaded constructor function.
//Initializes acctNumber to aNum, name to aName and balance to amount.
BankAccount::BankAccount(int aNum, string aName, double amount)
{
acctNumber = aNum;
name = aName;
balance = amount;
}
//This function copies the argument passed into the parameter to
//the private member variable acctNumber.
void BankAccount::setAcctNumber(int aNum)
{
acctNumber = aNum;
}
//This function copies the argument passed into the parameter to
//the private member variable name.
void BankAccount::setName(string aName)
{
name = aName;
}
//This function copies the argument passed into the parameter to
//the private member variable balance.
void BankAccount::setBalance(double amount)
{
balance = amount;
}
//This function returns the value of the private member variable acctNumber.
int BankAccount::getAcctNumber()
{
return acctNumber;
}
//This function returns the value of the private member variable name.
string BankAccount::getName()
{
return name;
}
//This function returns the value of the private member variable balance.
double BankAccount::getBalance()
{
return balance;
}
//This function adds the amount passed in to the balance.
void BankAccount::deposit(double amount)
{
balance = balance + amount;
}
//this function subtracts the amount passed in from the balance.
void BankAccount::withdraw(double amount)
{
balance = balance - amount;
}
// Displays the data of a bank account
void BankAccount::displayData()
{
cout
cout
cout
cout
cout
cout
}
F a O Ch 11 Program 1: BankAcco Ch11 Program 1 - Bank x +Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started