Question

# a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that...

a. Define the class bankAccount to store a bank customer’s account
number and balance. Suppose that account number is of type int, and
balance is of type double. Your class should, at least, provide the
following operations: set the account number, retrieve the account
number, retrieve the balance, deposit and withdraw money, and print
b. Every bank offers a checking account. Derive the class
checkingAccount from the class bankAccount (designed in part
(a)). This class inherits members to store the account number and the
balance from the base class. A customer with a checking account typically
receives interest, maintains a minimum balance, and pays service charges if
the balance falls below the minimum balance. Add member variables to
from the base class, this class should provide the following operations: set
interest rate, retrieve interest rate, set minimum balance, retrieve minimum
balance, set service charges, retrieve service charges, post interest, verify if
the balance is less than the minimum balance, write a check, withdraw
(override the method of the base class), and print account information. Add
appropriate constructors.
c. Every bank offers a savings account. Derive the class
savingsAccount from the class bankAccount (designed in part
(a)). This class inherits members to store the account number and
the balance from the base class. A customer with a savings account
typically receives interest, makes deposits, and withdraws money. In
addition to the operations inherited from the base class, this class
should provide the following operations: set interest rate, retrieve
interest rate, post interest, withdraw (override the method of the base
class), and print account information. Add appropriate constructors.
d. Write a program to test your classes designed in parts (b) and (c).

Here is what I have so far:

#include <iostream>
#include <string>
using namespace std;
class bankAccount{ // bank class
private: //private data members
string holderName;
string accountType;
int accountNumber;
float balance;
float interestRate;
float round(float valuee) // private function to round off value
{
float num = (int)(valuee * 100 + .5);
return (float)num/ 100;
}
public:
bankAccount(){ //default cnstructor
accountNumber=0;
balance=0.00;
interestRate=0.00;
}
// mutator function of the data members
void setHolderName(string h){
holderName=h;
}
void setAccountType(string a){
accountType=a;
}
void setAccountNumber(int n){
accountNumber=n;
}
void setBalance(float bal){
round(bal);
balance=bal;
}
void setIntersetRate(float rat){
interestRate =rat;
}
// accessor function for the data members (private)
string getHolderName(){
return holderName;
}
string getAccountType(){
return accountType;
}
int getAccountNumber(){
return accountNumber;
}
float getBalance(){
return balance;
}
float getInterestRate(){
return interestRate;
}
};
cout<<endl;
cout<<"1: Enter 1 to add a new customer. "<<endl;
cout<<"2: Enter 2 for an existing customer."<<endl;
cout<<"3: Enter 3 to print customers data. "<<endl;
cout<<"9: Enter 9 to exit the program. "<<endl;
}
int main() {
string name;
string type;
int num = 0;
float balance;
float rate;
bankAccount customer[10]; // array of size 10
int count=0; // will let us know the record and will only show the record that have data stored
int choice;
while(1){ // until user presses 9
cin>>choice;
if(choice==1){ // insert data
num=num % 10000+100; // get random account number
cout<<"Enter customer's name: ";
cin.ignore();
getline(cin,name);
cout<<"Enter account type (checking/savings): ";
getline(cin,type);
cout<<"Enter amount to be deposited to open account: ";
cin>>balance;
cout<<"Enter interest rate (as a percent): ";
cin>>rate;
// store data into the array
customer[count].setHolderName(name);
customer[count].setAccountType(type);
customer[count].setAccountNumber(num);
customer[count].setBalance(balance);
customer[count].setIntersetRate(rate);
count++;
}
else if(choice==2){
// search function for existing users to update and view record
cout<<"Enter Account Name to update record: ";
cin>>name;
for(int i=0;i<count;i++){
if(name==customer[i].getHolderName()){
cout<<"---------- RECORD FOUND ---------"<<endl;
cout<<"Account Number: "<<customer[i].getAccountNumber()<<endl;

cout<<"Account Holder Name: "<<customer[i].getHolderName()<<endl;

cout<<"Account Type: "<<customer[i].getAccountType()<<endl;

cout<<"Account Balance: "<<customer[i].getBalance()<<endl;

cout<<"Account Interest Rate: "<<customer[i].getInterestRate()<<endl;

cout<<"--------------------------"<<endl;

cout<<"Enter data to update "<<endl<<endl;
cout<<"Enter customer's name: ";
cin.ignore();
getline(cin,name);
cout<<"Enter account type (checking/savings): ";
getline(cin,type);
cout<<"Enter amount to be deposited to open account: ";
cin>>balance;
cout<<"Enter interest rate (as a percent): ";
cin>>rate;
customer[i].setHolderName(name);
customer[i].setAccountType(type);
customer[i].setAccountNumber(num);
customer[i].setBalance(balance);
customer[i].setIntersetRate(rate);
}

}
}
else if(choice==3){

//.. view all record of bank
cout<<endl<<"*********** ACCOUNT RECORDS ***********"<<endl;
for(int i=0;i<count;i++){
cout<<endl<<"-------------------------------"<<endl;
cout<<"Account Number: "<<customer[i].getAccountNumber()<<endl;

cout<<"Account Holder Name: "<<customer[i].getHolderName()<<endl;

cout<<"Account Type: "<<customer[i].getAccountType()<<endl;

cout<<"Account Balance: \$"<<customer[i].getBalance()<<endl;

cout<<"Account Interest Rate: "<<customer[i].getInterestRate()<<"%"<<endl;
}
}
else if(choice==9){ //.. exit function
return 0;
}
else{
cout<<"Invalid choice"<<endl;
break;
}
}
}

Main.cpp

``````#include <iostream>
using namespace std;

class BankAccount
{
public:
int accountNumber;
double Balance;

public:
BankAccount(int Accno,double Bal)
{
accountNumber = Accno;
Balance = Bal;
}
BankAccount()
{
}
public:
double getBal()
{
return(Balance);
}
int getAccNo()
{
return(accountNumber);
}
void setBal(double amount)
{
Balance = amount;
}
void setAccNo(int Accno)
{
accountNumber = Accno;
}
void virtual showAccNo()
{
cout << " ---------------------------------" << endl;
cout << " ||        Account Info           " << endl;
cout << " ---------------------------------" << endl;
cout << " || Account Number :" << accountNumber << endl;
cout << " || Account Balance:" << Balance << endl;
cout << " ---------------------------------" << endl;
cout << endl;
}

double virtual depAmnt(double dAmnt)
{
Balance = Balance + dAmnt;
return(Balance);
}

double virtual wdrawAmnt(double wAmnt)
{
Balance = Balance - wAmnt;
return(Balance);
}
};

class CheckingAccount : BankAccount
{
double Intrst;
double minBal;
double serChge;

public:
CheckingAccount(int pAccno,double pAmnt,double pIntrst):BankAccount(pAccno,pAmnt)
{
Intrst = pIntrst;
minBal = 500;//By default
}

void setIntRate(double intRate)
{
Intrst = intRate;
}

double retIntRate()
{
return(Intrst);
}

void setMinBal(double mBal)
{
minBal = mBal;
}

double retMinBal()
{
return(minBal);
}

void setSerChge(double sCharge)
{
serChge = sCharge;
}

double retSerChge()
{
return(serChge);
}

double depAmnt(double dAmnt)
{
Balance = Balance + dAmnt;
return(Balance);
}

double wdrawAmnt(double wAmnt)
{
if(wAmnt <= Balance)
Balance = Balance - wAmnt;
else
cout << "You have insufficient funds!" << endl;
return(Balance);
}

void showAccNo()
{
cout << " ---------------------------------" << endl;
cout << " ||        Account Info           " << endl;
cout << " ---------------------------------" << endl;
cout << " || Account Number :" << accountNumber << endl;
cout << " || Account Balance:" << Balance << endl;
cout << " ---------------------------------" << endl;
cout << endl;
}
};

class SavingAccount:BankAccount
{
double minBal;
public:
SavingAccount(int pAccno,double pAmnt):BankAccount(pAccno,pAmnt)
{
minBal = 500;
}
double depAmnt(double dAmnt)
{
Balance = Balance + dAmnt;
return(Balance);
}
double wdrawAmnt(double wAmnt)
{
if(wAmnt <= Balance)
Balance = Balance - wAmnt;
else
cout << "You have in sufficient funds!" << endl;
return(Balance);
}
void setMinBal(double mBal)
{
minBal = mBal;
}
void showAccNo()
{
cout << endl;
cout << " ---------------------------------" << endl;
cout << " ||        Account Info           " << endl;
cout << " ---------------------------------" << endl;
cout << " || Account Number :" << accountNumber << endl;
cout << " || Account Balance:" << Balance << endl;
cout << " ---------------------------------" << endl;
cout << endl;
}
};

int main()
{
double amount;
int choice;
do
{
cout << endl;
cout << "       Create an Account      " << endl;
cout << " *****************************" << endl;
cout << " ** 1 - Checking Account   **" << endl;
cout << " ** 2 - Saving Account     **" << endl;
cout << " ** 3 - Exit               **" << endl;
cout << " *****************************" << endl;
cin >> choice;
cout << endl;

if(choice==1)
{
cout << "Enter account number: " << endl;
int Accno;
cin >> Accno;
cout << "Enter opening balance: " << endl;
double newBal;
cin >> newBal;
double intRate;
cout << "Enter interest rate: " << endl;
cin >> intRate;
CheckingAccount obj(Accno,newBal,intRate);
int accChoice;
do
{
cout << endl;
cout << " *************************" << endl;
cout << " ** 1 - Deposit        **" << endl;
cout << " ** 2 - Withdraw       **" << endl;
cout << " ** 3 - Account Info   **" << endl;
cout << " ** 4 - Exit           **" << endl;
cout << " *************************" << endl;
cin >> accChoice;
cout << endl;
switch(accChoice)
{
case 1:
cout << "Enter amount: " << endl;
cin >> amount;
double dAmnt;
dAmnt = obj.depAmnt(amount);
cout << "Available balance: " << dAmnt << endl;
break;
case 2:
cout << "Enter amount: " << endl;
cin >> amount;
double wAmnt;
wAmnt = obj.wdrawAmnt(amount);
cout << "Available balance: "<< wAmnt << endl;
break;
case 3:
obj.showAccNo();
break;
}
}

while(accChoice!=4);
}
else if(choice==2)
{
cout << "Enter account number:" << endl;
int pAccno;
cin >> pAccno;
cout << "Enter opening balance:" << endl;
double pnewBal;
cin >> pnewBal;
double _irate;
cout << "Enter interest rate:" << endl;
cin >> _irate;
SavingAccount sObj(pAccno,pnewBal);
int pChoice;
do
{
cout << endl;
cout << " *************************" << endl;
cout << " ** 1 - Deposit        **" << endl;
cout << " ** 2 - Withdraw       **" << endl;
cout << " ** 3 - Account Info   **" << endl;
cout << " ** 4 - Exit           **" << endl;
cout << " *************************" << endl;
cin>>pChoice;
cout << endl;
switch(pChoice)
{
case 1:
cout << "Enter amount:" << endl;
cin >> amount;
double _dAmnt;
_dAmnt = sObj.depAmnt(amount);
cout << "Available balance: " << _dAmnt;
break;
case 2:
cout << "Enter amount:" << endl;
cin >> amount;
double _wamount;
_wamount = sObj.wdrawAmnt(amount);
cout << "Available balance: " << _wamount;
break;
case 3:
sObj.showAccNo();
break;
case 4:
break;
default:
cout << "Invalid choice";
break;
}
}
while(pChoice!=4);
}
}
while(choice!=3);
}``````

Output:

Note: I hope the above provided solution is according to your description. If in case you find an error in the structure or in the method then please do let me know through comments. I'll try to resolve your issues. Thank You!!!

ThumbsUP!!!! Have a nice day...