#include<iostream> using namespace std; #include <stdlib.h> class BankAccount {
ID: 3544575 • Letter: #
Question
#include<iostream>
using namespace std;
#include <stdlib.h>
class BankAccount
{
friend ostream& operator<<(ostream&, BankAccount);
friend istream& operator>>(istream&, BankAccount&);
private:
int acctNum;
double balance;
double annualRate;
public:
BankAccount(int, double = 0.0, double = 0.0);
BankAccount();
//void enterAccountData();
void enterAccountData();
//void computeInterest(int);
//void displayAccount();
void displayaccount();
BankAccount operator+=(double);
BankAccount operator-=(double);
BankAccount operator+(const BankAccount&);
bool operator<(BankAccount);
bool operator>(BankAccount);
bool operator==(BankAccount);
};
BankAccount::BankAccount(int acct, double bal, double rate)
{
//Provide code
acctNum=acct;
balance=bal;
annualrate=rate;
}
BankAccount::BankAccount()
{
//provide code
}
/*
void BankAccount::enterAccountData()
{
//
}
*/
void BankAccount::computeInterest(int years)
{
//provide code
}
/*
void BankAccount::displayAccount()
{
//provide code
} **/
//Work on these overloading operators
BankAccount BankAccount::operator+=(double deposit)
{
// write your code here
cout << "How much would you like to deposit?" << endl;
cin >> deposit;
balance = balance + deposit;
return balance;
}
BankAccount BankAccount::operator-=(double withdrawal)
{
// write your code here
cout << "How much would you like to withdrawal?" << endl;
cin >> withdrawal;
balance = balance - withdrawal;
return balance;
}
BankAccount BankAccount::operator+(const BanAccount &acct)
{
BanAccount sum(9999, 0);
sum.balance = BankAccount::balance + acct.balance;
return sum;
}
bool BankAccount::operator>(BankAccount account)
{
// write your code here
if (myAccount > yourAccount)
cout << "My account has more than your account" << endl;
}
bool BankAccount::operator<(BankAccount account)
{
// write your code here
if (myAccount < yourAccount)
cout << "Your account has more than mine" << endl;
}
bool BankAccount::operator==(BankAccount account)
{
// write your code here
if (myAccount == yourAccount)
cout << "Our accounrds have the same amount" << endl;
}
ostream& operator<<(ostream& out, BankAccount account)
{
// provide code
}
istream& operator>>(istream& in, BankAccount& account)
{
// provide code
}
int main()
{
BankAccount myAccount, yourAccount (1111, 100, 0.12);
double increment = 4.50; int val = 2;
//the following statment demonstrate that your overloaded insertion operators works
cout << myAccount <<endl;
cout <<yourAccount<<endl;
//the following statement demonstrate that your extraction operator works
cin >> myAccount;
//The following statement dipalys that += ans -= work
myAccount += increment;
cout <<myAccount;
myAccount -= increment;
cout <<myAccount;
//The following statements demonstrate that the + operaotr works
BankAccount temp;
temp = myAccount + yourAccount;
cout <<temp;
//The following statements demonstrate that the < operaotr works
cout <<(myAccount<yourAccount);
//The following statements demonstrate that the > operaotr works
cout <<(myAccount>yourAccount);
//The following statements demonstrate that the == operaotr works
cout <<(myAccount==yourAccount);
system ("PAUSE");
return 0;
}
Explanation / Answer
#include<iostream>
using namespace std;
#include <stdlib.h>
class BankAccount
{
friend ostream& operator<<(ostream&, BankAccount);
friend istream& operator>>(istream&, BankAccount&);
private:
int acctNum;
double balance;
double annualRate;
public:
BankAccount(int, double = 0.0, double = 0.0);
BankAccount();
//void enterAccountData();
void enterAccountData();
void computeInterest(int);
//void displayAccount();
void displayaccount();
BankAccount operator+=(double);
BankAccount operator-=(double);
BankAccount operator+(const BankAccount&);
bool operator<(BankAccount);
bool operator>(BankAccount);
bool operator==(BankAccount);
};
BankAccount myAccount, yourAccount (1111, 100, 0.12);
BankAccount::BankAccount(int acct, double bal, double rate)
{
acctNum=acct;
balance=bal;
annualRate=rate;
}
BankAccount::BankAccount()
{
//provide code
}
/*
void BankAccount::enterAccountData()
{
//
}
*/
void BankAccount::computeInterest(int years)
{
//provide code
}
/*
void BankAccount::displayAccount()
{
//provide code
} **/
//Work on these overloading operators
BankAccount BankAccount::operator+=(double deposit)
{
// write your code here
cout << "How much would you like to deposit?" << endl;
cin >> deposit;
balance = balance + deposit;
return balance;
}
BankAccount BankAccount::operator-=(double withdrawal)
{
// write your code here
cout << "How much would you like to withdrawal?" << endl;
cin >> withdrawal;
balance = balance - withdrawal;
return balance;
}
BankAccount BankAccount::operator+(const BankAccount &acct)
{
BankAccount sum(9999, 0);
sum.balance = BankAccount::balance + acct.balance;
return sum;
}
bool BankAccount::operator>(BankAccount account)
{
if (myAccount > yourAccount)
cout << "My account has more than your account" << endl;
}
bool BankAccount::operator<(BankAccount account)
{
if (myAccount < yourAccount)
cout << "Your account has more than mine" << endl;
}
bool BankAccount::operator==(BankAccount account)
{
if (myAccount == yourAccount)
cout << "Our accounrds have the same amount" << endl;
}
ostream& operator<<(ostream& out, BankAccount account)
{
// provide code
}
istream& operator>>(istream& in, BankAccount& account)
{
// provide code
}
int main()
{
BankAccount myAccount, yourAccount (1111, 100, 0.12);
double increment = 4.50; int val = 2;
//the following statment demonstrate that your overloaded insertion operators works
cout << myAccount <<endl;
cout <<yourAccount<<endl;
//the following statement demonstrate that your extraction operator works
cin >> myAccount;
//The following statement dipalys that += ans -= work
myAccount += increment;
cout <<myAccount;
myAccount -= increment;
cout <<myAccount;
//The following statements demonstrate that the + operaotr works
BankAccount temp;
temp = myAccount + yourAccount;
cout <<temp;
//The following statements demonstrate that the < operaotr works
cout <<(myAccount<yourAccount);
//The following statements demonstrate that the > operaotr works
cout <<(myAccount>yourAccount);
//The following statements demonstrate that the == operaotr works
cout <<(myAccount==yourAccount);
system ("PAUSE");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.