Hi guys this is the first time ive posted to this forum, and ive tried getting my answer by asking others and google, but what i'm after is to complete an assignment that is asking me to complete a program that basically works as an ATM machine. it reads in a customer file and using that data it will determine what customer has what account. The assignment has to include inheritance and four classes so what i have posted below doesnt work but it has the four classes. Also the program must have basic ATM functionality like being able to withdraw, deposit etc, but i can probably manage on my own. Any help would be appreciated or if you could steer me into the correct direction, i dont expect anything to give me the answers but any help would be greatly appreciated.
Customers.dat file:
Jason Santa
67 eighth Ave, heats
S
123456
0.00
X
Joseph jasons
20 Wattle Ave, Doonside
K
937568
0.00
S
246890
0.00
C
917355
0.00
X
James Bond
C/- MI6, London
C
293567
0.00
X
Napolean Solo
Delflorios, New York City
S
337761
0.00
C
846579
0.00
X
C++ code from before:
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
const float savingsInterestRate =0.05;
const int maxCustomers = 7;
const int maxTrans = 20;
// Savings Account class
class savingsAccount
{
private:
int accNumber;
float balance;
float interestRate;
public:
savingsAccount(int,float,float);
void setupAccount(int, float,float);
void addDeposit(float amount);
void subWdrawal(float amount);
void addInterest();
float getBalance();
bool matchAccount(int);
};
bool savingsAccount::matchAccount(int accNo)
{
if(accNo==accNumber) return true;
else return false;
}
// Constructor function
savingsAccount::savingsAccount(int aN, float bal,float iRate)
{
accNumber=aN;
balance=bal;
interestRate=iRate;
}
void savingsAccount::setupAccount(int aN, float bal,float iRate)
{
accNumber=aN;
balance=bal;
interestRate=iRate;
}
void savingsAccount::addDeposit(float amount)
{
balance=balance+amount;
}
void savingsAccount::subWdrawal(float amount)
{
balance=balance-amount;
}
void savingsAccount::addInterest()
{
balance=balance+balance*interestRate;
}
float savingsAccount::getBalance()
{
return balance;
}
class checqueAccount
{
private:
int accNumber;
float balance;
float interestRate;
public:
checqueAccount(int,float,float);
void setupAccount(int, float,float);
void addDeposit(float amount);
void subWdrawal(float amount);
void addInterest();
float getBalance();
bool matchAccount(int);
};
bool checqueAccount::matchAccount(int accNo)
{
if(accNo==accNumber) return true;
else return false;
}
// Constructor function
checqueAccount::checqueAccount(int aN, float bal,float iRate)
{
accNumber=aN;
balance=bal;
interestRate=iRate;
}
void checqueAccount::setupAccount(int aN, float bal,float iRate)
{
accNumber=aN;
balance=bal;
interestRate=iRate;
}
void checqueAccount::addDeposit(float amount)
{
balance=balance+amount;
}
void checqueAccount::subWdrawal(float amount)
{
balance=balance-amount;
}
void checqueAccount::addInterest()
{
balance=balance+balance*interestRate;
}
float checqueAccount::getBalance()
{
return balance;
}
class creditAccount
{
private:
int accNumber;
float balance;
float interestRate;
public:
creditAccount(int,float,float);
void setupAccount(int, float,float);
void addDeposit(float amount);
void subWdrawal(float amount);
void addInterest();
float getBalance();
bool matchAccount(int);
};
bool creditAccount::matchAccount(int accNo)
{
if(accNo==accNumber) return true;
else return false;
}
// Constructor function
creditAccount::creditAccount(int aN, float bal,float iRate)
{
accNumber=aN;
balance=bal;
interestRate=iRate;
}
void creditAccount::setupAccount(int aN, float bal,float iRate)
{
accNumber=aN;
balance=bal;
interestRate=iRate;
}
void creditAccount::addDeposit(float amount)
{
balance=balance+amount;
}
void creditAccount::subWdrawal(float amount)
{
balance=balance-amount;
}
void creditAccount::addInterest()
{
balance=balance+balance*interestRate;
}
float creditAccount::getBalance()
{
return balance;
}
//Customer class containing savingsAccount object
class Customer
{
private:
string name;
string address;
savingsAccount sAccnt;
public:
Customer(string = "", string ="", int =0, float =0.0, float =savingsInterestRate);
void CreateCust(string, string, int);
void accessAccount(char);
bool searchAccounts(int);
void applyTrans(char,float);
};
// This function could be put in the savingsAccount class (some other changes would be necessary)
void Customer::applyTrans(char transType, float amt)
{
if(transType=='C') sAccnt.addDeposit(amt) ;
else if(transType=='D') sAccnt.subWdrawal(amt) ;
else sAccnt.addInterest();
}
//Constructor function calling savingsAccount constructor
Customer::Customer(string nme, string addr,int an, float b, float ir):sAccnt(an,b,ir)
{
name = nme;
address = addr;
}
void Customer::CreateCust(string nme, string addr, int saNumber)
{
name = nme;
address = addr;
sAccnt.setupAccount(saNumber,0.0,savingsInterestRate); // call savingsAccount setup function
}
bool Customer::searchAccounts(int accNo)
{
if (sAccnt.matchAccount(accNo)) return true;
else return false;
}
// Access account to get balance
void Customer::accessAccount(char op)
{ float amt;
cout<<fixed;
if (op=='B') cout<<"Balance of "<<setw(10)<<name<<"s account is: "<<setw(10)<<setprecision(2)<<sAccnt.getBalance()<<endl;
}
// Transaction class - simple version, other functions in ProcessTrans class
class Transact
{
private:
int accNo;
float amt;
char transType;
public:
void readRecord(ifstream&);
int getTransAccNo();
float getTransAmt();
char getCode();
};
// Read one transaction record from file
void Transact::readRecord(ifstream &infile)
{
infile>>accNo;
infile >> amt;
infile>>transType;
}
int Transact::getTransAccNo()
{
return accNo;
}
float Transact::getTransAmt()
{
return amt;
}
char Transact::getCode()
{
return transType;
}
//Process transactions class containing customers and transactions
class ProcessTrans
{
private:
Customer custs[maxCustomers];
Transact trans[maxTrans];
ifstream infile;
int numTrans; //Actual number of transactions read from file
//could include number of customers if using file
int findAcc(int);
public:
void getCustomers();
void getTrans();
void Process();
void Report();
};
void ProcessTrans::getCustomers() // Could read from a file
{
custs[0].CreateCust("Mark","63 Ninth",123456);
custs[1].CreateCust("Pam","20 Wattle",246890);
custs[2].CreateCust("Bill","20 Wattle",917355);
custs[3].CreateCust("Fred","20 Wattle",937568);
custs[4].CreateCust("Keith","20 Wattle",337761);
custs[5].CreateCust("Kevin","20 Wattle",846579);
custs[6].CreateCust("Bron","20 Wattle",293567);
}
// Load tranactions into array from file
void ProcessTrans::getTrans()
{ int count=0;
infile.open("trans.dat");
if(infile.fail()) cout<<"File not found";
else {
while(infile.peek()!=EOF) {
trans[count].readRecord(infile);
count++;
}
}
infile.close();
numTrans=count-1;
}
void ProcessTrans::Report()
{
for(int i=0;i<maxCustomers;i++)
custs[i].accessAccount('B');
}
// Find the customer whose account matches the transaction account number
int ProcessTrans::findAcc( int accNo)
{
for(int i=0;i<maxCustomers;i++)
if (custs[i].searchAccounts(accNo)) return i;
return -1;
}
// Main processing driver function
void ProcessTrans::Process()
{ int cust,i;
for(i=0;i<numTrans;i++) { // Loop through transaction array
cust = findAcc(trans[i].getTransAccNo()); // find customer for that transaction
if (cust>=0)
custs[cust].applyTrans(trans[i].getCode(),trans[i].getTransAmt()); // apply the transaction
else cout<<"No customer found";
}
}
int main(){
ProcessTrans pt;
pt.getCustomers();
cout<<"sim08u's Bank"<<endl;
cout<<"Transaction Daily Report"<<endl;
cout<<"========================"<<endl;
cout<<"Initial Balances"<<endl;
cout<<"----------------"<<endl;
pt.Report();
pt.getTrans();
cout<<endl<<"Processing Transactions"<<endl<<endl;
pt.Process();
cout<<"Final Balances"<<endl;
cout<<"--------------"<<endl;
pt.Report();
system("pause");
return 0;
}