I have attached a quick class model of what I am trying to achieve (Also, sorry for the mass of code but I figured I'd post everything I have thus far in case anyone saw other improvements I could make).
I can give a customer an 'Account' but I want to give the customer a 'CurrentAccount' which is inherited from Account; and then store it in an array of Accounts.
How do I go about doing this?
Thank you for any help!
Customer.cpp
#include "Customer.h"
#include <iostream>
#include <string>
#include "Date.h"
using namespace std;
Customer::Customer()
{
noOfAccounts = 0;
}
int Customer::getID()
{
return ID;
}
string Customer::getName()
{
return name;
}
string Customer::getAddress()
{
return address;
}
string Customer::getTelNo()
{
return telNo;
}
string Customer::getSex()
{
return sex;
}
int Customer::getAge()
{
return age;
}
Account Customer::getAccount()
{
return *accRef;
}
void Customer::setID(int ID)
{
this->ID = ID;
}
void Customer::setName(string name)
{
this->name = name;
}
void Customer::setAddress(string address)
{
this->address = address;
}
void Customer::setTelNo(string telNo)
{
this->telNo = telNo;
}
void Customer::setSex(string sex)
{
this->sex = sex;
}
void Customer::setAge(int age)
{
this->age = age;
}
void Customer::setAccount(Account *accRef)
{
this->accRef = accRef;
}
void Customer::addNewCustomer()
{
cout << "Enter your name > ";
getline(cin,name);
cout << "Enter your Address: ";
getline(cin,address);
cout << "Enter your telephone number: ";
getline(cin,telNo);
cout << "Enter your sex: ";
getline(cin,sex);
cout << "Enter your Age: ";
cin >> age;
}
void Customer::addNewAccount()
{
acnts[noOfAccounts].createAccount();
noOfAccounts++;
}
void Customer::showPersonDetails()
{
cout << ID << ": " << name << " - " << address;
}
void Customer::showPersonAccounts()
{
cout << "Accounts<" << noOfAccounts << ">:" << endl;
if (noOfAccounts == 0)
{
cout << "<None>" << endl;
}
else
{
for (int i = 0; i < noOfAccounts; i++)
{
acnts[i].showAccount();
}
}
cout << endl;
}
Account.cpp
#include "Account.h"
Account::Account() //create an account with an initial amountand a specified interest rate
{
}
double Account::balance(void) const //return the account's balance
{
return money;
}
void Account::deposit(double amount) //add money to the account
{
money += amount;
}
void Account::createAccount()
{
cout << "Enter Initial Balance > ";
cin >> money;
}
void Account::showAccount()
{
cout << "Amount: \x9C" << money << endl;
}
CurrentAccount.cpp
#include "currentAccount.h"
CurrentAccount::CurrentAccount()
{
}
void CurrentAccount::setInterest(double percent)
{
this->interestRate = percent;
}
void CurrentAccount::addInterest(void)
{
money *= (1 + interestRate/100.0);
}
void CurrentAccount::createAccount()
{
cout << "Enter Initial Balance > ";
cin >> money;
cout << "enter Interest rate > ";
cin >> interestRate;
}
void CurrentAccount::showAccount()
{
cout << "Amount: \x9C" << money << " at " << interestRate << "% interest" << endl;
}
main.cpp
#include "Account.h"
#include "Cheque.h"
#include <limits>
#include "Customer.h"
#include <ctime>
#include <conio.h>
int noOfCustomers = 0;
Customer cust[10];
void choosingAccount(int ID)
{
char choice;
bool active = true;
while (active)
{
cout << "\t\n" << "1. Current Account" << endl;
cout << "\t\n" << "2. Junior Current Account" << endl;
cout << "\t\n" << "3. Student Saving Account" << endl;
cout << "\t\n" << "0. Back" << endl;
switch(choice)
{
case '1':
cust[ID-1].addNewAccount();
break;
case '2':
cust[ID-1].addNewAccount();
break;
case '3':
cust[ID-1].addNewAccount();
break;
case '40':
active = !active;
break;
default:
cout << "\nInvalid selection\n\n";
break;
}
}
}
void specificCustomerMenu(int ID)
{
char choice;
bool active = true;
while (active)
{
if ((ID > 0) && (ID <= noOfCustomers))
{
cout << "Main Menu >> Customers >> " << ID << endl;
cout << "--------------------------------" << endl;
cout << cust[ID-1].getName() << endl;
cout << cust[ID-1].getAge() << endl;
cout << cust[ID-1].getTelNo() << endl;
cout << cust[ID-1].getAddress() << endl;
cout << "--------------------------------" << endl;
cust[ID-1].showPersonAccounts();
cout << "--------------------------------" << endl;
cout << "Mortgage: " << endl;
cout << "Loan: " << endl;
cout << "Card: " << endl;
cout << "--------------------------------" << endl;
cout << "\t\n" << "1. Deposit Money" ;
cout << "\t\n" << "2. Withdraw Money" ;
cout << "\t\n" << "3. Produce Cheque";
cout << "\t\n" << "4. Deposit Cheque";
cout << "\t\n" << "5. Open Acount";
cout << "\t\n" << "6. Close Account" ;
cout << "\t\n" << "7. Add Credit Card";
cout << "\t\n" << "8. Add Loan";
cout << "\t\n" << "9. Add Mortgage";
cout << "\t\n" << "0. Back";
cout << "\n\n\t" << "> ";
cin >> choice;
cin.ignore(256, '\n');
switch(choice)
{
case '0':
active = !active;
break;
case '5':
choosingAccount(ID);
break;
default:
cout << "\nInvalid selection\n\n";
break;
}
}
else
{
cout << "\nInvalid ID\n\n";
active = !active;
}
}
cout << endl;
}
void customerMenu()
{
char choice;
bool active = true;
int cID;
while (active)
{
cout << "Main Menu >> Customers" << endl;
cout << "-----------------------" << endl;
cout << "\t\n" << "1. View Customer" ;
cout << "\t\n" << "2. List Customers" ;
cout << "\t\n" << "3. Add Customer";
cout << "\t\n" << "4. Delete Customer";
cout << "\t\n" << "0. Back";
cout << "\n\n\t" << "> ";
cin >> choice;
cin.ignore(256, '\n');
cout << "\n";
switch(choice)
{
case '1':
cout << "Enter Customer ID > ";
cin >> cID;
cout << endl;
specificCustomerMenu(cID);
break;
case '2':
if (noOfCustomers == 0)
{
cout << "-----No Customers----" << endl << endl;
}
else
{
for (int i = 0; i < noOfCustomers; i++)
{
cust[i].showPersonDetails();
cout << endl;
}
}
cout << endl;
break;
case '3':
cust[noOfCustomers].addNewCustomer();
cust[noOfCustomers].setID(noOfCustomers+1);
noOfCustomers++;
cout << endl << "-----Customer Added Successfully----" << endl << endl;
break;
case '4':
//TO DO: Delete Customer.
break;
case '0':
active = !active;
break;
default:
cout << "\nInvalid selection\n\n";
break;
}
}
}
int main()
{
char choice;
bool active = true;
cout << "BANK SYSTEM V1.4" << endl;
cout << "-----------------------" << endl;
while (active)
{
cout << "\nMain Menu" << endl;
cout << "---------------" << endl;
cout << "\t\n" << "1. Customers" ;
cout << "\t\n" << "2. Account" ;
cout << "\t\n" << "3. Cheques";
cout << "\t\n" << "4. Management";
cout << "\t\n" << "0. Exit";
cout << "\n\n\t" << "> ";
cin >> choice;
cin.ignore(256, '\n');
cout << "\n";
switch(choice)
{
case '1':
{
customerMenu();
break;
}
case '0':
active = !active;
break;
default:
cout << "\nInvalid selection\n\n";
break;
}
}
return 0;
}