Thread: Help with Polymorphism

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    33

    Help with Polymorphism

    Ok.. this is an assignment.. i'm not going to lie.

    but i have done almost everything of it.. just need some help on the stl <vector>/ <list>

    Code:
    #include <iostream>
    #include <vector>
    #include <string>
    #include <algorithm>
    
    using namespace std;
    
    class customer
    {
          string name;
          string address;
          int phoneNum;
          public:
                 customer(string inName, string inAddress, int inPhoneNum);
                 void display();
                 friend bool operator==(const customer &left, const customer &right);
          
                 
    };
    
    bool operator==(const customer &left, const customer &right)
    {
    	if ((left.name==right.name))
    		return true;
    	else
    		return false;
    };
    
    customer::customer(string inName, string inAddress, int inPhoneNum)
    {
                              name = inName;
                              address = inAddress;
                              phoneNum = inPhoneNum;
    }
    
    void customer::display()
    {
         cout<<"Name :"<<name<<endl;
         cout<<"Address:"<<address<<endl;
         cout<<"Phone Number:"<<phoneNum<<endl;
    }
    
    class Account
    {
          int accountNumber;
          double accountBalance;
          int dateOpened;
          vector <customer> transactions;
          public:
                 Account(int inAccountNumber, double inAccountBalance, 
                 int inDateOpened,vector <customer> inTransactions);
                 bool makeDeposit();
                 bool makeWithdrawal();
                
               
    };
    
    Account::Account(int inAccountNumber, double inAccountBalance, int inDateOpened,
                         vector <customer> inTransactions)
    {
                         accountNumber = inAccountNumber;
                         accountBalance = inAccountBalance;
                         dateOpened = inDateOpened;
                         transactions = inTransactions;
    }
    
    class checkingAccount: public Account
    {
          private:
                  string chequeStyle;
                  double minimumBalance;
          public:
                 checkingAccount(int inAccountNumber, double inAccountBalance,
                 int inDateOpened, vector <customer> inTransactions, string inChequeStyle,
                 double inMinimumBalance);
                 void display();
    };
    
    class savingsAccount: public Account
    {
          private:
                  int interestRate;
          public:
                 savingsAccount( int inAccountNumber, double inAccountBalance,
                 int inDateOpened, vector <customer> inTransactions, int inInterestRate);
    };
           
    int main()
    {
        system("pause");
        return 0;
    }
    this is my code for the question..

    A general bank Account has the following basic features. It has:

    • the accountBalance. This maintains the current balance in the account and
    makes it easy for us to decide when withdrawals should be disallowed;
    A bank account system design class diagram

    • transactions, consisting of the amount, positive or negative, which is added
    to the account. A deposit is a positive transaction and a withdrawal is a
    negative transaction. Transaction details are held together dynamically in a
    ‘linked’ structure. The most recent transaction will be the last entry added.
    The amount of the transaction could be a float or a double. You choose. If
    you are a ‘big’ spender you will probably use doubles! If we sum the
    amounts stored in the transaction list it will equal the accountBalance;

    • an accountNumber. You could get the system to do this automatically or
    look to add it in yourself. Again you choose. Please explain the reason for
    your choice however.

    You have met 'linked structures' previously. Use the STL to manage the collection
    of transactions.



    // just posted the question to allow you have more understanding of it (which frankly i don't have atm)..

    how to add stl to the transactions?
    do i have to declare it under customer class or the account class?

    pls help

    and thanks in advance

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    transactions, consisting of the amount, positive or negative, which is added
    to the account. A deposit is a positive transaction and a withdrawal is a
    negative transaction. Transaction details are held together dynamically in a
    ‘linked’ structure. The most recent transaction will be the last entry added.
    The amount of the transaction could be a float or a double. You choose. If
    you are a ‘big’ spender you will probably use doubles! If we sum the
    amounts stored in the transaction list it will equal the accountBalance;
    As far as I can tell from this, one of the members of the Account class needs to be

    Code:
    std::vector<double> transactions;
    For example , if you deposit $100 and withdraw $50 and $25 (those methods need some parameters), this list will contain [100, -50, -25], or a total of $25 which is equal to current balance.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polymorphism - "pointers" or "references"?
    By Petike in forum C++ Programming
    Replies: 10
    Last Post: 06-04-2009, 05:06 PM
  2. A C++ program examples showing Polymorphism, please help.
    By MarkSquall in forum C++ Programming
    Replies: 19
    Last Post: 06-06-2008, 04:41 AM
  3. Replies: 3
    Last Post: 10-31-2005, 12:05 PM
  4. change sorting method using polymorphism
    By Forever82 in forum C++ Programming
    Replies: 2
    Last Post: 07-31-2003, 01:21 PM
  5. Polymorphism & Overloaded Operators :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 09-13-2002, 08:40 PM