My teacher barely speaks english and doesnt not help us on our projects and I am
ID: 3545992 • Letter: M
Question
My teacher barely speaks english and doesnt not help us on our projects and I am confused.
You have been developing BankAccount clas for Parkville Bank that contains several fields and functions, including overloaded operators. You have also created child classes derived from the BankAccount class: Checking Account, SavingsAccount, and CheckingWithInterest. Complete these tasks.
-Create a BankaccountException class. The class contains a BankAccount object and a string message explaining the reason for the exception. Include a constructor that requires values for the BankAccount and the message. Also include a function that displays the message.
-Modify each BankAccount class construtor and data entry function so that it throws an exception whenever a client attempts to instantiate a BankAccount with an account number that is less than 1000 or greater than 9999
- Write a main() function that asks the user to enter values for four BankAccounts. If the user attempts to create a BankAccount with an invalid account number, catch the exception, display a message, and force the account number and balance to 0. Display the four BankAccount objects.
- Write a main() function that declares an array of four CheckingAccounts (The CheckingAccount constructor class the BankAccount data entry function, so an exception might be thrown.) If the user attempt to create a CheckingAccount with an invalid account number, catch the exceptions, and, before ending the program, display two messages. The first message is the string message contained with the BankAccountException object. The second indicates which CheckingAccount (1,2, 3, or 4) caused the early termination. If all four CheckingAccounts are valid, then display them.
-Alter the SavingAccount constructor to make sure an exception is thrown when the account number is invalid (based on the same rules for a BankAccount account number) and also when the interest rate is negative (Make sure the messages are different.) Write a main() function that declares an array for four SavingsAccounts. If the user attempts to create a SavingsAccount with an invalid accoung number or a negative interest ratem catch the exception, display the appropriate message, and display which account caused the early termination (1,2,3, or 4). If all four SavingsAccounts are valid, then display them.
CODE:
#include<iostream>
using namespace std;
// your name
// project 4: Chapter 10 CASE Project 2
class BankAccount
{
friend ostream& operator<<(ostream&, BankAccount);
friend istream& operator>>(istream&, BankAccount&);
private:
int acctNum;
double balance;
public:
BankAccount(int, double = 0.0);
BankAccount();
void enterAccountData();
void displayAccount();
BankAccount operator+=(double);
BankAccount operator-=(double);
BankAccount operator+(int);
bool operator<(BankAccount);
bool operator>(BankAccount);
bool operator==(BankAccount);
};
BankAccount::BankAccount(int acct, double bal)
{
acctNum = acct;
balance = bal;
}
BankAccount::BankAccount()
{
balance = 0;
annualRate = 0;
}
void BankAccount::enterAccountData()
{
int account;
double balance;
cout << "Please enter the account number :";
cin >> account;
cout << endl;
while (account< 1000 || account > 9999)
{
cout << "Error: Invalid account number,please try again. :" << endl;
cin >> account;
}
//Allows user to enter a balance that cannot benegative
cout << "Please enter the balance for " << account << " : ";
cin >> balance;
cout << endl;
while (balance < 0)
{
cout << "Error: Invalid balance, cannot have a negative balance, please check and try again" << endl;
cin >> balance;
}
acctNum = account;
acctBal = balance;
}
void BankAccount::displayAccount()
{
cout << "Account #" << acctNum << " ";
cout << "Account Balance :" << acctBal << endl;
}
BankAccount BankAccount::operator+=(double deposit)
{
balance += deposit;
return balance;
}
BankAccount BankAccount::operator-=(double withdrawal)
{
balance -= withdrawal;
return balance;
}
BankAccount BankAccount::operator+(int num)
{
BankAccount sum(9999, 0);
sum.balance = BankAccount::balance + acct.balance;
return sum;
}
bool BankAccount::operator>(BankAccount account)
{
bool truth = false;
if (balance > account.balance)
truth = true;
return truth;
}
bool BankAccount::operator<(BankAccount account)
{
string string1 = "false";
bool truth = false;
if (balance < account.balance)
truth = true;
return truth;
}
bool BankAccount::operator==(BankAccount account)
{
bool truth = false;
if (balance == account.balance)
truth = true;
return truth;
}
ostream& operator << (ostream& out, BankAccount account)
{
out << "Account Number: " << account.acctNum << endl
<< "Account Balance: $" << account.balance << endl
<< "Annual Rate: " << account.annualRate << endl;
return out;
}
istream& operator>>(istream& in, BankAccount& account)
{
cout << "Enter your account number: ";
in >> account.acctNum;
cout << "Enter your account balance: ";
in >> account.balance;
cout << "Enter your annual rate: ";
in >> account.annualRate;
cout << endl;
return in;
}
class SavingsAccount : public BankAccount
{
friend ostream& operator << (ostream&, SavingsAccount);
private:
double interestRate;
public:
SavingsAccount();
};
SavingsAccount::SavingsAccount()
{
//write the code for this
// the code should initialize interest rate. account number, and account balance
}
ostream& operator<< (ostream& out, SavingsAccount acct)
{
//write the code for this
}
class CheckingAccount: public BankAccount
{
friend ostream& operator<<(ostream&, CheckingAccount);
private:
double fee;
int numChecks;
public:
CheckingAccount();
};
CheckingAccount::CheckingAccount()
{
//write the code for this
}
ostream& operator<<(ostream& out, CheckingAccount acct)
{
//write the code for this
}
int main()
{
cout << "Savings account information:" << endl;
SavingsAccount savings;
//reading savings account data
cin>> savings;
cout << savings;
cout << endl << "Checking account information:" << endl;
//reading checking account data
CheckingAccount checking;
cin >>checking;
cout << checking;
return 0;
}
Explanation / Answer
#include<iostream>
using namespace std;
class BankAccount
{
private:
int acctNum;
double acctBal;
double balance;
double annualRate;
public:
BankAccount(int, double = 0.0, double = 0.0);
void enterAccountData();
void computeInterest(int);
void displayAccount();
double getBal();
};
BankAccount::BankAccount(int acct, double bal, double rate)
{
// provide definition
}
void BankAccount::enterAccountData()
{
int account;
double balance;
cout<<"Please enter the account number :";
cin>>account;
cout<<endl;
while(account< 1000 || account > 9999)
{
cout<<"Error: Invalid account number,please try again. :"<<endl;
cin>>account;
}
//Allows user to enter a balance that cannot benegative
cout<<"Please enter the balance for "<<account << " : ";
cin>>balance;
cout << endl;
while(balance < 0)
{
cout<<"Error: Invalid balance, cannot have a negative balance, please check and try again"<<endl;
cin>>balance;
}
acctNum = account;
acctBal = balance;
}
void BankAccount::computeInterest(int years)
{
for(int i=0; i<years; i++);
{
int interest = static_cast<int> (acctBal*0.03);
acctBal = acctBal + interest;
displayAccount();
}
}
void BankAccount::displayAccount()
{
cout << "Account #" << acctNum << " ";
cout << "Account Balance :" << acctBal << endl;
}
double BankAccount::getBal()
{
return acctBal;
}
class Portfolio
{
private:
int clientNum;
BankAccount checking;
BankAccount savings;
double stockMarketVal;
double realEstateVal;
void balancePortfolio();
public:
Portfolio(int, int, double, int, double, double, double, double);
void display();
};
Portfolio::Portfolio(int client, int cNum, double cBal, int sNum,
double sBal, double sRate, double stockVal,
double realVal) : checking(cNum, cBal), savings(sNum, sBal, sRate)
{
//provide definition
}
void Portfolio::balancePortfolio()
{
//provide definition
}
void Portfolio::display()
{
//provide definition
}
int main()
{
//provide definition
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.