for this programming assignment you will create a class call
for this programming assignment you will create a class called Acount. It will have class variables of name of type string, dollars of type int, and cents of type int. You will need to implement a default constructor, a copy constructor, a parameter, a destructor, a mutator and accessor for the name variable, a deposit method that tales in two ints as parameters, and overload the following operators >, <, >=, <=, ==, !=, <<, >>, and =. Remember that the prototypes should be in Account.h and the implementation in Account.cpp
For implementing the << and >> operators look at the expected input and output to make them correctly.
Write a main method in Bank.cpp that will follow the sample output below to test your Account class. An outline for Bank.cpp is below:
n thing Bank cpp is below: void displayAccountChoices (int, Account int) int main Declare any need variables Account *acct; Find out how many accounts there will be. Verify that number of accounts is positive Create a dynamic array of Accounts to the size of number of accounts entered Loop to read in all of the accounts info You should be using the operator Set up a Sentinel loop until -999 is entered. Change try delaul Dun\'t ask again x O E aSolution
Code:
Account.h:
#include<iostream>
 using namespace std;
class Account
 {
 string name;
 int dollars;
 int cents;
public:
 Account();
 Account(string&s,int d,int c);
 ~Account();
//Accessors
 string& getName();
 int getDollars();
 int getCents();
 double getBalance();
//Mutators
 void setName(string& s);
 void setDollars(int d);
 void setCents(int c);
void deposit(int d,int c);
 void withdraw(int ,int);
//Operators overloaded
   
 bool operator >(Account &);
 bool operator <(Account &);
 bool operator >=(Account &);
 bool operator <=(Account &);
 bool operator ==(Account &);
 bool operator !=(Account &);
 Account operator =(Account &);
 
 friend ostream& operator<<(ostream& out,Account& a);
 friend istream& operator>>(istream& in,Account& a);
   
 };
Account.cpp:
#include<iostream>
 #include<string>
 using namespace std;
#include \"Account.h\"
Account::Account(){
 dollars=cents=0;
 }
Account::Account(string &n,int d,int c){
 name.assign(n);
 dollars=d;
 cents=c;
 }
Account::~Account()
 {
 cout<<\"Account::Destructor\"<<endl;
 }
 string& Account::getName(){ return name;}
int Account::getDollars(){return dollars;}
int Account::getCents(){return cents;}
void Account::setName(string &n){ name.assign(n);}
void Account::setDollars(int d){dollars=d;}
void Account::setCents(int c){cents = c;}
void Account::deposit(int d,int c){ dollars+=d; cents+=c;}
double Account::getBalance(){ return dollars+(cents/100);}
void Account::withdraw(int d,int c)
 {
 if(d>dollars|| c>cents)
 {
    cout<<\"Insufficient money in bank\"<<endl;
    return;
 }
 dollars-=d;
 cents-=c;
 }
bool Account::operator>(Account &a){
if(getBalance()>a.getBalance())
    return true;
return false;
 }
bool Account::operator<(Account &a){
if(getBalance()<a.getBalance())
    return true;
return false;
 }
bool Account::operator>=(Account &a){
if(getBalance()>=a.getBalance())
    return true;
return false;
 }
bool Account::operator<=(Account &a){
if(getBalance()<=a.getBalance())
    return true;
return false;
 }
bool Account::operator==(Account &a){
if(getBalance()==a.getBalance())
    return true;
return false;
 }
bool Account::operator!=(Account &a){
if(getBalance()!=a.getBalance())
    return true;
return false;
 }
Account Account::operator=(Account &a){
 Account newAccount;
newAccount.setName(a.getName());
 newAccount.setDollars(a.getDollars());
 newAccount.setCents(a.getCents());
return newAccount;
}
ostream& operator<<(ostream&out, Account & a)
 {
 cout<<a.name<<\" \"<<a.dollars<<\" \"<<a.cents<<endl;
 }
istream & operator>>(istream & in, Account &a)
 {
cout<<\"Enter name,dollars,cents:\";
 cin>>a.name>>a.dollars>>a.cents;
}
Bank.cpp:
#include<iostream>
 #include<string>
 using namespace std;
 #include \"Account.h\"
void displayAccountChoices(int,Account*,int);
int main(void)
 {
 int n;
 Account *act;
 
 cout<<\"Enter number of records:\";
 cin>>n;
if(n<0){
    cout<<\"input number is not positive. Quiting...\"<<endl;
    return 0;
 }
act= new Account[n];
for(int i=0;i<n;i++)
    cin>>act[i];
 
 int opt;
while(1){
    cout<<\"Enter the number of the account to be modified. to quit enter -999\"<<endl;
    for(int i=0;i<n;i++)
        cout<<i+1<<\":\"<<act[i]<<endl;
    cin>>opt;
   if(opt!=-999)
        displayAccountChoices(opt-1,act,n);
    else if(opt==-999)
        break;
 }
return 0;
 }
void displayAccountChoices(int a,Account *act,int n)
 {
 char opt;
 int d,c;
while(1){
 cout<<\"Would you like to make a (D)eposit, (W)ithdraw,(P)rint balance or (A)ccount Menu?\"<<endl;
 cin>>opt;
if(opt==\'a\' || opt==\'A\')
    break;
 else if(opt==\'D\')
 {
    cout<<\"How many dollars,cents:\";
    cin>>d>>c;
    act[a].deposit(d,c);
 }
 else if(opt==\'W\'){
    cout<<\"Dollars,cents to withdraw:\";
    cin>>d>>c;
    act[a].withdraw(d,c);
 }
 else if(opt== \'P\'){
    cout<<act[a]<<endl;
    cout<<\"The balance in account is $\"<<act[a].getBalance()<<endl;
 }
 }
 }
Output:
Enter number of records:3
 Enter name,dollars,cents:Checking 10 20
 Enter name,dollars,cents:Saving 20 15
 Enter name,dollars,cents:CD 10000 50
 Enter the number of the account to be modified. to quit enter -999
 1:Checking 10 20
2:Saving 20 15
3:CD 10000 50
1
 Would you like to make a (D)eposit, (W)ithdraw,(P)rint balance or (A)ccount Menu?
 P
 Saving 20 15
Would you like to make a (D)eposit, (W)ithdraw,(P)rint balance or (A)ccount Menu?
 D
 How many dollars,cents:5 20
 Would you like to make a (D)eposit, (W)ithdraw,(P)rint balance or (A)ccount Menu?
 P
 Saving 25 35
Would you like to make a (D)eposit, (W)ithdraw,(P)rint balance or (A)ccount Menu?
 W
 Dollars,cents to withdraw:2 20
 Would you like to make a (D)eposit, (W)ithdraw,(P)rint balance or (A)ccount Menu?
 W
 Dollars,cents to withdraw:0 25
 Insufficient money in bank
 Would you like to make a (D)eposit, (W)ithdraw,(P)rint balance or (A)ccount Menu?
 A
 Enter the number of the account to be modified. to quit enter -999
 1:Checking 10 20
2:Saving 23 15
3:CD 10000 50
-999





