I need help solving my project. I\'m having some technical errors that I can\'t
ID: 3546031 • Letter: I
Question
I need help solving my project. I'm having some technical errors that I can't figure out. There is more then I listed but I can't figure them out until I get these solved. Any help is appreciated.
Here is the prompt:
You have been developing a BankAccount class for Parkville Bank that contains several fields and functions, including overloaded operators.
Remove the annual rate field and all references to it so that a BankAccount contains only an account number and a balance. Also remove the computeInterest()function if it is still part of your class.
Create a class named SavingsAccount that descends from BankAccount. Include an interest rate field that is initialized to 3 percent when a SavingsAccount is constructed. Create an overloaded insertion operator that displays all of the data for a SavingsAccount.
c. Create a class named CheckingAccount that descends from BankAccount. Include two new fields including a monthly fee and the number of checks allowed per month; both are entered from prompts within the constructor. Create an overloaded insertion operator that displays all the data for a CheckingAccount.
d. Write a main()function to demonstrate the SavingsAccount and CheckingAccount classes. Save the file as CheckingAndSavings.cpp.
e. Add a constructor for the SavingsAccount class that requires a double argument that is used to set the interest rate. Create a class named CheckingWithInterest that descends from both SavingsAccount and CheckingAccount. This class provides for special interest-bearing checking accounts. When you create a CheckingWithInterest object, force the interest rate to .02, but continue to prompt for values for all the other fields. Create an array of five CheckingWithInterest accounts, prompt the user for values for each, and display the accounts. Save the file as CheckingWithInterest.cpp.
Some of the errors i'm getting:
t.cpp: In member function 'BankAccount BankAccount::operator-=(double)':
My Code:
#include<iostream>
using namespace std;
// David Gray
// 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)
{
// provide code
acctNum=acct;
balance=bal;
}
BankAccount::BankAccount()
{
// Provide code
acctNum=0;
balance=0;
}
void BankAccount::enterAccountData()
{
int account;
int balance;
cout<<"Please enter the accountnumber"<<endl;
cin>>account;
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<<endl;
cin>>balance;
while(balance < 0)
{
cout<<"Error: Invalidbalance, cannot have a negative balance, please check and tryagain"<<endl;
cin>>balance;
}
int acctNum = account;
double acctBal = balance;
}
void BankAccount::displayAccount()
{
cout << endl;
cout << "The balance in account #" << acctNum << " is: $ " << balance << endl;
}
BankAccount BankAccount::operator+=(double deposit)
{
//write the code for this
cout << "How much would you like to deposit into your account?" << endl;
cin >> deposit;
deposit = deposit + balance;
cout << "New Balance = $" << deposit;
}
BankAccount BankAccount::operator-=(double withdrawal)
{
//you already have this
cout << "How much would you like to withdraw from your account?" << endl;
cin >> withdrawal;
withdrawal = withdrawal + balance;
return withdrawal;
}
BankAccount BankAccount::operator+(int num)
{
//you already have this
acctNum = acctNum + num;
}
bool BankAccount::operator>(BankAccount account)
{
//you already have this
if (acctBal > account.acctBal)
return true;
else
return false;
}
bool BankAccount::operator<(BankAccount account)
{
//you laready have this
if (acctBal < account.acctBal)
return true;
else
return false;
}
bool BankAccount::operator==(BankAccount account)
{
//you laready have this
if (acctBal == account.acctBal)
return true;
else
return false;
}
ostream& operator << (ostream& out, BankAccount account)
{
//you laready have this
cout << endl
out << "Account #" << account.acctNum << endl;
out << "Account Balance: $" << account.acctBal << endl;
cout << endl
return out;
}
istream& operator>>(istream& in, BankAccount& account)
{
//you laready have this
cout << "Enter Account # ";
in >> account.acctNum;
cout << "Enter Account Balance: $";
in >> account.acctBal;
cout << endl;
return in;
}
class SavingsAccount : public BankAccount
{
friend ostream& operator << (ostream&, SavingsAccount);
private:
double interestRate;
public:
SavingsAccount(int, double, double);
};
SavingsAccount::SavingsAccount(int acct, double bal, double rate) : BankAccount (acct, bal)
{
//write the code for this
// the code should initialize interest rate. account number, and account balance
rate = 3;
interestRate = rate;
}
ostream& operator<< (ostream& out, SavingsAccount acct)
{
//write the code for this
out << "Bank Account #" << acct.acctNum << " has a balance of $" << acct.balance<< "." << endl;
out << "Its interest rate is " << acct.interestRate*100 << "% per year." << endl;
return out;
}
class CheckingAccount: public BankAccount
{
friend ostream& operator<<(ostream&, CheckingAccount);
private:
double fee;
int numChecks;
public:
CheckingAccount(int, double, double, int);
};
CheckingAccount::CheckingAccount(int acct, double bal, double cost, int checks) : BankAccount(acct, bal)
{
//write the code for this
fee=cost;
numChecks=checks;
}
ostream& operator<<(ostream& out, CheckingAccount acct)
{
//write the code for this
cout << endl
out << "Account #" << acct.acctNum << endl;
out << "Account Balance: $" << acct.acctBal << endl;
out << "Enter your account fee:" << endl;
in << cost;
out << "Enter the number of checks available:" << endl;
in << checks;
cout << endl
return out, in;
}
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
//Slightly modified your code wherever necessary and removed all the errors from the code :)
#include<iostream>
using namespace std;
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);
void setAccountNumber(int num);
void setBalance(double bal);
int getAccountNumber();
double getBalance();
};
BankAccount::BankAccount(int acct, double bal)
{
acctNum=acct;
balance=bal;
}
BankAccount::BankAccount()
{
acctNum=0;
balance=0;
}
void BankAccount::enterAccountData()
{
int account;
cout<<"Please enter the account number"<<endl;
cin>>account;
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<<endl;
cin>>balance;
while(balance < 0)
{
cout<<"Error: Invalidbalance, cannot have a negative balance, please check and tryagain"<<endl;
cin>>balance;
}
acctNum = account;
}
void BankAccount::displayAccount()
{
cout << endl;
cout << "The balance in account #" << acctNum << " is: $ " << balance << endl;
}
BankAccount BankAccount::operator+=(double deposit)
{
deposit = deposit + balance;
cout << "New Balance = $" << deposit;
return *this;
}
BankAccount BankAccount::operator-=(double withdrawal)
{
withdrawal = withdrawal + balance;
return withdrawal;
}
BankAccount BankAccount::operator+(int num)
{
acctNum = acctNum + num;
return *this;
}
bool BankAccount::operator>(BankAccount account)
{
if (balance > account.balance)
return true;
else
return false;
}
bool BankAccount::operator<(BankAccount account)
{
if (balance < account.balance)
return true;
else
return false;
}
bool BankAccount::operator==(BankAccount account)
{
//you laready have this
if (balance == account.balance)
return true;
else
return false;
}
void BankAccount::setAccountNumber(int num){
acctNum = num;
}
void BankAccount::setBalance(double bal){
balance = bal;
}
int BankAccount::getAccountNumber(){
return acctNum;
}
double BankAccount::getBalance(){
return balance;
}
ostream& operator << (ostream& out, BankAccount account)
{
//you laready have this
cout << endl;
out << "Account #" << account.acctNum << endl;
out << "Account Balance: $" << account.balance << endl;
cout << endl;
return out;
}
istream& operator>>(istream& in, BankAccount& account)
{
//you laready have this
int accountNumber;
double bal;
cout << "Enter Account # ";
in >> accountNumber;
cout << "Enter Account Balance: $";
in >> bal;
cout << endl;
account.setAccountNumber(accountNumber);
account.setBalance(bal);
return in;
}
class SavingsAccount : public BankAccount
{
friend ostream& operator << (ostream&, SavingsAccount);
private:
double interestRate;
public:
SavingsAccount(int, double, double);
SavingsAccount();
};
SavingsAccount::SavingsAccount(int acct, double bal, double rate=.03) : BankAccount (acct, bal)
{
//write the code for this
// the code should initialize interest rate. account number, and account balance
interestRate = rate;
}
SavingsAccount::SavingsAccount()
{
setAccountNumber(0);
setBalance(0);
interestRate = 0.03;
}
ostream& operator<< (ostream& out, SavingsAccount acct)
{
//write the code for this
out << "Bank Account #" << acct.getAccountNumber() << " has a balance of $" << acct.getBalance()<< "." << endl;
out << "Its interest rate is " << acct.interestRate*100 << "% per year." << endl;
return out;
}
class CheckingAccount: public BankAccount
{
friend ostream& operator<<(ostream&, CheckingAccount);
private:
double fee;
int numChecks;
public:
CheckingAccount(int, double, double, int);
CheckingAccount();
int getNumChecks();
double getFee();
};
CheckingAccount::CheckingAccount(int acct, double bal, double cost, int checks) : BankAccount(acct, bal)
{
//write the code for this
fee=cost;
numChecks=checks;
}
CheckingAccount::CheckingAccount() : BankAccount(0, 0)
{
fee=0;
numChecks=0;
}
int CheckingAccount::getNumChecks(){
return numChecks;
}
double CheckingAccount::getFee(){
return fee;
}
ostream& operator<<(ostream& out, CheckingAccount acct)
{
//write the code for this
cout << endl;
out << "Account #" << acct.getAccountNumber() << endl;
out << "Account Balance: $" << acct.getBalance() << endl;
out << "Account fee: " << acct.getFee() << endl;
out << "Number of checks available: " << acct.getNumChecks() << endl;
cout << endl;
return out;
}
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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.