Hi folks.
Sorry for the delay.
I decided to post the codes here. Here's my "bank" menu program. The first 4 options are simple, but the last 2 options I need help with. The last 2 options are affected with the header files and the additonal .cpp files that I created, and i'm not too good at implementing these files with my menu program because I never work with them before. So, if anyone here could help me make my program seems functional, and working, that would be great.
thanks,
DFC
Menu Program:
Code:
#include <iostream>
#include <fstream>
#include <string>
#include "Account.h"
#include "Bank.h"
using namespace std;
Bank myBank("David", "Bank for the local");
//function prototypes
int menu();
void printRegister();
void printTransaction();
void printList();
void printInterest();
void printAddCustomer();
void printFindCustomer();
//
//
//Add Breakpoint to line 34
int main()
{
int choice = -1;
char dummy;
while (choice != 0)
{
choice = menu();
switch (choice)
{
case 1:
printRegister();
// cout << "choice 1 selected. press any key to continue" << endl;
cin >> dummy;
break;
case 2:
printTransaction();
// cout << "choice 2 selected. press any key to continue" << endl;
cin >> dummy;
break;
case 3:
printList();
cin >> dummy;
break;
case 4:
printInterest();
// cout << "choice 4 selected. press any key to continue" << endl;
cin >> dummy;
break;
case 5:
printAddCustomer();
cin >> dummy;
break;
case 6:
printFindCustomer();
cin >> dummy;
break;
case 0:
cout << "choice 0 selected. press any key to continue" << endl;
break;
default:
cout << "not a valid choice. press any key to continue" << endl;
cin >> dummy;
break;
}
}
cout << "\n\n\nThanks for using my software" << endl;
return 0;
}
//display the main choices in a loop
//returns when the user enter zero or
//any positive number
int menu()
{
int response = -1;
while (response < 0)
{
cout << "Miscellaneous Financial Processing" << endl;
cout << " Main Menu " << endl;
cout << "1: Registering Applicant(s)" << endl;
cout << "2: Financial Transaction" << endl;
cout << "3: Customer List/Table" << endl;
cout << "4: Interest rate " << endl;
cout << "------------------------" << endl;
cout << "5: Registering Applicant(s) version 2" << endl;
cout << "6: Locate a registrant " << endl;
cout << "7. Financial Transaction (version 2) " << endl;
cout << "0: Quit" << endl;
cout << "Press the number corresponding to your choice and press enter" << endl;
cin >> response;
cin.ignore();
}
return response;
}
void printRegister()
{
const int MAX = 40; // Maximum array dimension
char fname[MAX];
char lname[MAX];
char bday[MAX];
char phone[MAX];
char acc;
char fileOut[] = "applicant.txt";
ofstream outputToFile;
outputToFile.open(fileOut,ios::app);
cout <<"This section help you fill out an application to registered for an account" << endl;
cout << "" << endl;
cout << "Please enter your first name: " << endl;
cin >> fname;
cout << "Enter your last name: " << endl;
cin >> lname;
cout << "Birthday (mmddyy): ";
cin >> bday;
cout << "Your home phone number: ";
cin >> phone;
cout << "Enter the your account number (max of 5 digits): ";
cin >> acc;
outputToFile << fname << endl;
outputToFile << lname << endl;
outputToFile << bday << endl;
outputToFile << phone << endl;
outputToFile << acc << endl;
cout << "Thank you for registering. Your data is recorded in our banking records.";
cout << "Have a nice day.";
outputToFile.close();
}
void printTransaction()
{
int transelect;
float balance;
double deposit, withdraw;
cout << "This section will helps determine the state of your current balance";
cout << "Enter your current monetary balance: ";
cin >> balance;
cout << "Choose a task: " << endl;
cout << "i) Depositing" << endl;
cout << "ii) Withdrawing" << endl;
cin >> transelect;
switch (transelect)
{
case 1:
cout << "Enter the amount you want to deposit: ";
cin >> deposit;
cout << "You deposited $" << deposit << "from $" << balance << endl;
cout << "Your current balance is now $" << balance+deposit << endl;
break;
case 2:
cout << "Enter the amount you want to withdraw: ";
cin >> withdraw;
cout << "You withdrawn $" << withdraw << "from $" << balance << endl;
cout << "Your current balance is now $" << balance-withdraw << endl;
break;
}
}
void printList()
{
// int fil;
// cout <<" This section list customer data and/or balance actions that have been processed previously" << endl;
// cout <<" Select the file to open the list: " << endl;
string line;
ifstream myfile ("applicant.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
else cout << "Unable to open file";
}
void printInterest()
{
double bal, rate;
double result;
int interest;
int year;
cout << "Enter your current balance: $ ";
cin >> bal;
cout << "Enter enter the annual rate of your choice (no more than 9%): ";
cin >> interest;
cout << "Enter number of years: ";
cin >> year;
rate = interest / 100;
result = (bal * rate) + bal * year;
cout << "Interest rate result: " << result << " in " << year << " years";
}
void printAddCustomer()
{
char fileOut[] = "registrants.txt";
ofstream outputToFile;
outputToFile.open(fileOut,ios::app);
cout << "This process will add in new customer to the banking database" << endl;
char customerName[20];
int customerNumber;
cout << "Enter your last name and press enter: ";
cin >> customerName[20];
Account acct(customerName);
myBank.addAccount(acct);
outputToFile << customerName << endl;
outputToFile << "Your record has been added successfully to the database" << endl;
outputToFile.close();
}
void printFindCustomer()
{
char fileOut[] = "findingcustomer.txt";
ofstream outputToFile;
outputToFile.open(fileOut,ios::app);
cout << "If you are searching for a registrant, you come to the right place" << endl;
char customerName[35];
int customerNumber;
cout << "Enter the last name of the registrant that you are looking for, then";
cout << "press Enter: ";
cin >> customerName;
outputToFile << customerName << endl;
customerNumber = myBank.findAccounttwo(customerName);
if(customerNumber < 0)
{
outputToFile << "Sorry. We cannot locate the registrant that you are looking for. " << endl;
}
else
{
outputToFile << "Mr./Mrs./Ms " << customerName << " is located within our database";
}
outputToFile.close();
}
Account.h
Code:
#ifndef ACCOUNT_H
#define ACCOUNT_H
class Account
{
private:
double balance;
int accountNum;
char fname[30];
char lname[30];
public:
Account(char* fname, char* lname);
Account(char getNames);
Account(const int num = 0, const double balance = 0.0);
Account();
void print();
void deposit(int amount);
void withdraw(int amount);
int getBalance;
};
#endif
Account.cpp
Code:
#include <iostream>
#include "Account.h"
using namespace std;
Account::Account(char* f)
{
strcpy(firstname, f);
}
Account::Account()
{
strcpy(firstname, "No first name given");
}
Account::Account(char* l)
{
strcpy(lastname, l);
}
Account::Account()
{
strcpy(lastname, "No last name given");
}
void Account::print()
{
cout << firstname << " " << lastname << endl;
}
char* Account::getNames()
{
return lastname;
}
Bank.h
Code:
#ifndef BANK_H
#define BANK_H
#include "Account.h"
class Bank
{
private:
int customerPosition;
int LAST_CUSTOMER;
char firstname[25];
char lastname[25];
Account myAccounts[20];
public:
Bank(char* firstname, char* lastname);
char* getNames();
void addAccount(Account account);
void addAccount(Account account, int position);
void addMoreAccounts();
void print();
int findAccountone(char* firstname);
int findAccounttwo(char* lastname);
};
#endif
Bank.cpp
Code:
#include <iostream>
#include "Bank.h"
using namespace std;
Bank::Bank(char* f, char* l)
{
LAST_CUSTOMER = 20;
customerPosition = 0;
strcpy(firstname, f);
strcpy(lastname, l);
}
void Bank::print()
{
cout << "Recipient's first name: " << firstname << endl;
cout << " + last name: " << lastname << endl;
cout << "Recipient's number " << customerPosition << endl;
for(int i = 0; i < customerPosition; i++)
{
cout << " Rep. " << i + 1 << ": ";
numberCustomers[i].print();
}
}
int Bank::findAccounttwo(char* l)
{
for(int i = 0;i < customerPosition; i++)
{
if(strcmp(numberCustomers[i].getNames(), l) == 0)
{
return i;
}
}
return -1;
}
void Bank::addAccount(Account a, int position)
{
if(position <= LAST_CUSTOMER)
{
myAccount[position] = c;
}
}
void Bank::addAccount(Account a)
{
if(customerPosition <= LAST_CUSTOMER)
{
addAccount(a, customerPosition++);
}
}
void Bank::addMoreAccounts()
{
Account a("David Ing");
addAccount(a);
Account b("Jamie Noble");
addAccount(b);
Account c("John Patterson");
addAccount(c);
Account d("Jim Rose");
addAccount(d);
Account e("Werner Frei");
addAccount(e);
Account f("Wai Yee Ing");
addAccount(f);
Account g("Steve Phillips");
addAccount(g);
Account h("Marge Simpson");
addAccount(h);
Account i("Steve Jobs");
addAccount(i);
Account j("Mary Frown");
addAccount(j);
Account k("Francis Dragon");
addAccount(k);
Account l("James Curtis");
addAccount(l);
Account m("Sylvia Szawara");
addAccount(m);
Account n("Emma Vachan Tweeney");
addAccount(n);
Account o("Victor Brakter");
addAccount(o);
Account p("Valerie Shipton");
addAccount(p);
Account q("Sandra Turner");
addAccount(q);
Account r("Zach Ballmer");
addAccount(r);
Account s("Belle Lutherman");
addAccount(s);
Account t("Adam Clyaton");
addAccount(t);
Account u("Paul Hewson");
addAccount(u);
Account v("Bonnie Chow");
addAccount(v);
Account w("John Henderson");
addAccount(w);
Account x("Huey Freeman");
addAccount(x);
Account y("Heather Heeves");
addAccount(y);
Account z("Jackie Chan");
addAccount(z);
}