int main(void)
{
AddCust();
AddAcc();
p3main();
p6main();
p10main();
//optional pause
int i;
cin >> i;
}
// This function asks the user questions in order to set up an account.
void AddCust()
{
Customer me;
Customer you("Raam", "Swali", "R500", "1111 2222 3333 4444");
you.output();
Customer name(you);
you.output();
me.input ();
string myCardNum = me.getCard_number();
me.setCard_number ("1234 5678 1234 5678");
me.output();
}
// This function asks the user questions in order to set up an account.
void AddAcc(void)
{
double initialBalance, monthlyDeposit, monthlyInterest;
unsigned int duration;
// Now we initialise an account with the appropriate values
CurrentAcc stdAccount(initialBalance, monthlyInterest);
// Now calculate the savings:
for (unsigned int i=0; i<< "After saving for " << duration << " months, the account balance is: ";)
cout << stdAccount.balance() << endl;
}
// Function to do a mortgage calculation.
void Mortgage(void)
{
double mortgageAmount, yearlyInterest, premium;
unsigned int duration;
bool mortgagePaid=false;
// Set up an account with the mortgage money in it.
// This represents the amount owed.
Account MAcc(mortgageAmount, yearlyInterest/12.0);
for (unsigned int year=0; (year<< "Mortgage repaid in " << year+1 << " years and " << month+1 << " months.\n";
}
if (!mortgagePaid)
cout << "After " << year+1 << " years, you owe: " << MAcc.balance() << endl;
}
}
// Simple bank simulation (multiple accounts)
void Bank(void)
{
// Set up an array of pointers ready to access some accounts.
const unsigned int MAX_ACCOUNTS=10;
Account *accs[MAX_ACCOUNTS];
unsigned int choice=0, currentAccount=0, counter=0;
double doubleValue;
unsigned int intValue;
// Start with one account.
accs[counter++]=new Account(0, 2);
do
{
choice=menu();
switch (choice)
{
case 1:
cout << "Enter deposit amount: ";
cin >> doubleValue;
accs[CurrenAcc]->deposit(doubleValue);
break;
case 2:
cout << "Enter amount to withdraw: ";
cin >> doubleValue;
if (!accs[CurrentAcc]->withdraw(doubleValue))
cout << "Withdraw failed, not enough money in account\n";
break;
case 3:
cout << "Balance in account " << CurrentAcc << " is ";
cout << accs[CurrentAcc]->balance() << endl;
break;
case 4:
cout << "Enter new account number: ";
cin >> intValue;
if (intValue<< "Error, invalid account number\n";
break;
case 5:
if (counter<< "Error, no room for any more accounts\n";
break;
case 6:
for (unsigned int i=0; i<< "Account " << i << " contains " << accs[i]->balance();
cout << " pounds\n";
}
break;
}
}
while (choice!=7);
}
// Displays a menu for p6main()
unsigned int menu(void)
{
unsigned int choice;
void Customer::input()
{
cout << "Please enter your first name, last name, customer ID, and card number each" << endl;
cout << "seperated by a space, then press enter ";
cin >> first_name
>> last_name
>> customer_ID
>> Card_number;
setCard_number(Card_number);
}
// Overloaded version to allow a cheque to be deposited.
// Note the parameter is a constant reference for efficiency.
bool CurrentAcc::deposit(const Cheque& c)
{
if (c.isSafe()) {
money+=c.value()-2.0; // Cheque is safe, so deposit it (-2 pound fee)
return true;
} else {
return false;
}
}
// Withdraws amount from CurrentAcc
bool CurrentAcc::withdraw(double amount)
{
// Check if we have enough money.
if (money>=amount) {
money-=amount;
return true;
} else {
return false;
}
}
// New version of withdraw that uses a reference argument
// to allow multiple values to be returned.
bool CurrentAcc::withdraw2(double& amount)
{
// Check if we have enough money.
if (money>=amount) {
money-=amount;
return true;
} else {
amount=money;
money=0;
return false;
}
}
Cheque CurrentAcc::withdrawCheque(double amount)
{
if (withdraw(amount)) {
Cheque tmp(amount-2);
return tmp; // Amount withdrawn successfully
} else {
Cheque tmp(0, false);
return tmp; // Return a bad cheque.
}
}
// Adds a certain percentage to the account
void CurrentAcc::addInterest(void)
{
money*=(1+interestRate/100.0);
}
// Simple function to reset the value of interestRate
void CurrentAcc::setInterest(double percent)
{
interestRate=percent;
}
// This is NOT a member of the Account class, but it makes sense to put the code here.
ostream& operator <<(ostream& s, Account& a)
{
s << "Current Account(" << a.balance() << "UKP, " << a.interestRate << "%)\n";
return s;
}
class Customer
{
private:
string Card_number;
public:
string first_name;
string last_name;
string customer_ID;
Customer();//constructor
Customer(string, string, string, string);//constructor
Customer(Customer&);//constructor
void input();//Function to get inputs
void output();//Function to get outputs
void display();//To display the info of a customer
string getCard_number();//Accessor
void setCard_number (string Card_Num);
};
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class CurrentAcc
{
double money; // amount of money held by this account
double interestRate; // a monthly or yearly interestrate, depending on how the account is to be used.
public:
// create an account with an initial amountand a specified interest rate
CurrentAcc(double amount, double percent)
{
money = amount;
interestRate = percent;
}
No mortgage header as i got completely peeved with the rest of it lol. As i said, any help greatly appreciated. Any questions on what i put down i will try to answer...as i am supposed to be a beginner.
I need the console to stay open and show the menu to add account, customer etc. At the moment it just keeps showing the add customer details with 2 instances my details before the question.
When i enter new details,, it does not stay open to do anything else. Maybe simple i dont know...