![]() |
| | #1 |
| Registered User Join Date: Sep 2009
Posts: 33
| Help with Polymorphism 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;
}
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 | |
| | #2 | ||
| The larch Join Date: May 2006
Posts: 3,222
| Quote:
Code: std::vector<double> transactions;
__________________ I might be wrong. Quote:
| ||
| anon is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |