C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-02-2009, 02:40 AM   #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
sivapc is offline   Reply With Quote
Old 11-02-2009, 05:39 AM   #2
The larch
 
Join Date: May 2006
Posts: 3,222
Quote:
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.

Quote:
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).
anon is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Polymorphism - "pointers" or "references"? Petike C++ Programming 10 06-04-2009 05:06 PM
A C++ program examples showing Polymorphism, please help. MarkSquall C++ Programming 19 06-06-2008 04:41 AM
Polymorphism Theory Question - Polymorphic Class Definition. ventolin C++ Programming 3 10-31-2005 12:05 PM
change sorting method using polymorphism Forever82 C++ Programming 2 07-31-2003 01:21 PM
Polymorphism & Overloaded Operators :: C++ kuphryn C++ Programming 2 09-13-2002 08:40 PM


All times are GMT -6. The time now is 11:46 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22