Whats wrong with my "simple" Bank App?

closed account (zb5L1hU5)
I have not got a clue whats wrong with my program...any help is greatly appreciated. i will post my main first (main.cpp)

#include <iostream>
#include <fstream>
#include <string>
#include "CurrentAcc.h"
#include "Customer.h"
#include "Mortgage.h"
using namespace std;
void AddCust(void);
void AddAcc(void);
void p3main(void);
void p6main(void);
unsigned int menu(void);
void p10main(void);

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;

cout<< "Enter initial balance: ";
cin >> initialBalance;

cout<< "Enter monthly deposit: ";
cin >> monthlyDeposit;

cout<< "Enter interest rate: ";
cin >> monthlyInterest;

cout<< "Enter saving duration: ";
cin >> 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;

cout << "Enter mortgage amount: ";
cin >> mortgageAmount;

cout << "Enter yearly interest: ";
cin >> yearlyInterest;

cout << "Enter monthly premium: ";
cin >> premium;

cout << "Enter calculation duration (years): ";
cin >> duration;

// 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;

cout << "\n\nA Group Bank\n";
cout << "\t1. Deposit\n";
cout << "\t2. Withdraw\n";
cout << "\t3. Display balance\n";
cout << "\t4. Change account number\n";
cout << "\t5. Create new account\n";
cout << "\t6. Display all accounts\n";
cout << "\t7. Quit\n";
cout << "\nChoose an option: ";

cin >> choice;

return choice;
}

// Demonstrates different ways of printing from classes
void p10main(void)
{
Account myAccount(100, 2);
Person bob("Bob", &myAccount);

cout << "Testing print() method\n";
myAccount.print();
bob.print();

cout << "\nTesting printOn(cout) method\n";
myAccount.printOn(cout);
bob.printOn(cout);

cout << "\nTesting overloaded << method\n";
cout << myAccount;
cout << bob;
}
closed account (zb5L1hU5)
Customer.cpp:

#include <iostream>
#include "Customer.h"

Customer::Customer()
{
first_name = "no name";
last_name = "no name";
customer_ID = "no info";
Card_number = ("0000 0000 0000 0000");
}

Customer::Customer(string f, string l, string id, string n)
{
first_name = f;
last_name = l;
customer_ID = id;
Card_number = n;
}

Customer::Customer(Customer& x)
{
first_name = x.first_name;
last_name = x.last_name;
customer_ID = x.customer_ID;
setCard_number(x.getCard_number());
}

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);
}

void Customer::output()
{
cout << "First name: " << first_name << endl;
cout << "Last name: " << last_name << endl;
cout << "Customer ID: " << customer_ID << endl;
cout << "Card number: " << getCard_number() << endl;
}

void Customer::display()
{
cout << first_name << ' ' << last_name << ' ' << customer_ID << ' ' << getCard_number() << endl;
}

string Customer::getCard_number()
{
return Card_number;
}

void Customer::setCard_number (string Card_Num)
{
Card_number = Card_Num;
}
closed account (zb5L1hU5)
CurrentAcc.cpp:

#include <iostream>
#include "CurrentAcc.h"

// Returns the balance member variable
double CurrentAcc::balance(void) const
{
return money;
}

// Deposits amount into account
void CurrentAcc::deposit(double amount)
{
money+=amount;
}

// 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;
}

void CurrentAcc::print(void)
{
cout << "Current Account(" << balance() << "UKP, " << interestRate << "%)\n";
}

void CurrentAcc::printOn(ostream& s)
{
s << "Current Account(" << balance() << "UKP, " << interestRate << "%)\n";
}

// 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;
}
closed account (zb5L1hU5)
Customer.h:
#ifndef CUSTOMER_H
#define CUSTOMER_H

#include "CurrentAcc.h"

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);
};

#endif // CUSTOMER_H
closed account (zb5L1hU5)
CurrentAcc.h:

#ifndef CURRENTACC_H
#define CURRENTACC_H

#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;
}

// return the account's balance
double balance()
{
return money;
}

// add money to the account
void deposit(double amount)
{
money += amount;
}

// substract money from the account
void withdraw(double amount)
{
money -= amount;
}

// add money according to the interest rate.
double addInterest()
{
double interestRate;
cout << "Please enter the current Interest Rate: ";
cin >> interestRate;
money *= (1 + interestRate/100.0);
return 0;
}
};
#endif
closed account (zb5L1hU5)
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...

thanks in advance.
Last edited on
Topic archived. No new replies allowed.