Answers: Classes Homework

  1.    class Checking
       {
       public:
          void open(int,float);
          void writecheck(float);
          void deposit(float);
          void display();
       private:
          int acctnum;
          float balance;
       };
    
  2.    #include 
       #include "Checking.h"
       void Checking::open(int anum, float bal)
       {
          acctnum = anum;
          balance = bal;
       }
       void Checking::writecheck(float amt)
       {
          balance -= amt;
       }
       void Checking::deposit(float amt)
       {
          balance += amt;
       }
       void Checking::display()
       {
          cout << "Account Number: " << acctnum << endl;
          cout << "Balance:        " << balance << endl;
       }
    
  3.    #include "Checking.h"
       int main()
       {
          Checking one, two;
          one.open(2345,1500);
          two.open(9876,4200);
          one.writecheck(835);
          one.writecheck(284);
          one.deposit(1450);
          one.display();
          two.deposit(720);
          two.writecheck(2279);
          two.display();
       }
    
  4.    class Checking
       {
       public:
          Checking();
          Checking(int,float);
          void writecheck(float);
          void deposit(float);
          void display();
       private:
          int acctnum;
          float balance;
       };
       Checking::Checking()
       {
          acctnum = 1111;
          balance = 0;
       }
       Checking::Checking(int anum, float bal)
       {
          acctnum = anum;
          balance = bal;
       }
    
  5.    #include "Checking.h"
       int main()
       {
          Checking accounts[5] = {Checking(2345,1500),Checking(9876,4200)};
          accounts[0].writecheck(835);
          accounts[0].writecheck(284);
          accounts[0].deposit(1450);
          accounts[0].display();
          accounts[1].deposit(720);
          accounts[1].writecheck(2279);
          accounts[1].display();
       }
    

Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2006