I am creating a bank account using classes. I have created the classes and now implementing them in my main program. I haven't written anything in the withdraw, find acct and all functions except "read account: read_acct()" because i wanna test if it reading the data from my .txt file or not. Dont know whats wrong with the program its not executing. Would let know that i'm new to classes and objects.
I am extremely sorry if its too long but i really need help.
Following is the code:
****************************************************
*************MAIN PROGRAM*************************
****************************************************
****Bank Accounts.cpp****
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib> //needed to use system() function
#include "BankAccount.h"
using namespace std;
const int MAX_NUM = 50;
void menu(void);
int read_accts(BankAccount[], int &);
int findacct(const BankAccount[], int);
int withdrawal(BankAccount[], int);
int deposit(BankAccount[], int);
int new_acct(BankAccount[], int);
int close_acct(BankAccount[], int);
void balance(const BankAccount[], int);
void account_info(const BankAccount[], int);
int print_accts(const BankAccount[], int);
void mypause(void);
int main(){
BankAccount account[MAX_NUM];
int num_accts;
char choice;
bool not_done = true;
// open output file
ofstream outfile("con"); //un-comment for debugging
outfile.setf(ios::fixed, ios::floatfield);
outfile.precision(2); //set decimal precision
/* first part */
/* fill and print initial database */
//read_accts(account, num_accts);
//print_accts(account, num_accts);
/* second part */
/* prompts for a transaction and then */
/* call functions to process the requested transaction */
do {
menu();
cin >> choice;
switch (choice)
{
case 'q':
case 'Q':
not_done = false;
print_accts(account, num_accts);
break;
case 'b':
case 'B':
balance(account, num_accts);
break;
case 'd':
case 'D':
deposit(account, num_accts);
break;
case 'w':
case 'W':
withdrawal(account, num_accts);
break;
case 'n':
case 'N':
num_accts = new_acct(account, num_accts);
break;
case 'x':
case 'X':
num_accts = close_acct(account, num_accts);
break;
default:
outfile << "Error: '" << choice << "' is an invalid selection - try again" << endl << endl;
break;
}
// give user a chance to look at output before printing menu
mypause();
} while (not_done);
outfile.close(); // close output file
// system("pause");
return 0;
}
void menu()
{
cout << endl << endl;
cout << "Select one of the following transactions:" << endl;
cout << "\t****************************" << endl;
cout << "\t List of Choices " << endl;
cout << "\t****************************" << endl;
cout << "\t W -- Withdrawal" << endl;
cout << "\t D -- Deposit" << endl;
cout << "\t N -- New Account" << endl;
cout << "\t B -- Balance Inquiry" << endl;
cout << "\t X -- Delete Account" << endl;
cout << "\t Q -- Quit" << endl;
cout << endl << "\tEnter your selection: ";
return;
}
int read_accts(BankAccount Account[], int num_accts, int &count)
{
string lastname, firstname;
char acc_type, SSN, acc_num;
double acc_bal;
count = 0; //initialize count
// open input file
ifstream cfile("C:\\Users\\Smart PC\\Documents\\Visual Studio 2013\\Projects\\HW 2 _Bank Accounts(Struct and classes)\\client_info_2.txt"); //comment-out for debugging
// ifstream cfile("con"); //un-comment for debugging
while (cfile >> lastname) {
cfile >> firstname;
Account[count].setName(lastname, firstname);
cfile >> SSN;
cfile >> acc_num;
cfile >> acc_type;
cfile >> acc_bal;
Account[count].setacc_info(SSN, acc_num, acc_type, acc_bal);
count++;
}
cfile.close();
return;
}
/*int findacct(const BankAccount account[], int num_accts)
{
};
int withdrawal(BankAccount account[], int num_accts)
{
};
int deposit(BankAccount account[], int num_accts)
{
};
int new_acct(BankAccount account[], int num_accts)
{
};
int close_acct(BankAccount account[], int num_accts)
{
};
void balance(const BankAccount account[], int num_accts)
{
};
void account_info(const BankAccount account[], int num_accts)
{
};
int print_accts(const BankAccount account [], int num_accts)
{
};
*/
void mypause()
{
system("pause");
return;
};
|
********End of Main Program********
------------------------------------------------------------------------------
****************************************************
*************Name.h*************************
****************************************************
/* Name Class Specification */
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#ifndef NAME_H
#define NAME_H
#include <string>
using namespace std;
//Name class declarations
class Name {
string last;
string first;
public:
// mutators (or setter member functions)
void setLastname(string);
void setFirstname(string);
// accessors (or getter member functions)
string getLastname() const;
string getFirstname() const;
};
#endif
|
********End of Name.h**********
------------------------------------------------------------------------------
****************************************************
*************Name.cpp*************************
****************************************************
/* Name Class Implementation */
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <string>
#include "Name.h"
using namespace std;
void Name::setLastname(string lastname)
{
last = lastname;
return;
}
void Name::setFirstname(string firstname)
{
first = firstname;
return;
}
string Name::getLastname() const
{
return (last);
}
string Name::getFirstname() const
{
return (first);
}
|
************End of Name.cpp***********
------------------------------------------------------------------------
****************************************************
*************BankAccount.h*************************
****************************************************
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
/* Contestant Class Specification */
#ifndef BANKACCOUNT_H
#define BANKACCOUNT_H
#include <string>
#include "Name.h"
#include "Account_info.h"
using namespace std;
class BankAccount{
Name name;
acc_info Account;
public:
void setName(string lastname, string firstname);
void setacc_info(char SSN, char acc_num, double acc_bal, char acc_type);
Name getName() const;
acc_info getacc_info() const;
};
#endif
|
******End of BankAccount.h******
------------------------------------------------------------------------------
****BankAccount.cpp****
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
/* BankAccount Class Implementation */
#include "BankAccount.h"
using namespace std;
void BankAccount::setName(string lastname, string firstname)
{
name.setLastname(lastname);
name.setFirstname(firstname);
return;
}
void BankAccount::setacc_info(char SSN, char acc_num, double acc_bal, char acc_type)
{
Account.setSSN(SSN);
Account.setacc_num(acc_num);
Account.setacc_bal(acc_bal);
Account.setacc_type(acc_type);
return;
}
Name BankAccount::getName() const
{
return (name);
}
acc_info BankAccount::getacc_info() const
{
return (Account);
}
|
*******End of BankAccount.cpp**********
*****************************
*************Account_info.h******
********************************
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#ifndef ACCOUNT_INFO_H
#define ACCOUNT_INFO_H
using namespace std;
class acc_info{
char SSN;
char acc_num;
double acc_bal;
char acc_type;
public:
// mutators (or setter member functions)
void setSSN(char);
void setacc_num(char);
void setacc_bal(double);
void setacc_type(char);
// accessors (or getter member functions)
char getSSN() const;
char getacc_num() const;
double getacc_bal() const;
char getacc_type() const;
};
#endif
|
********End of Account_info.h**********
-------------------------------------------------------------------------
******Account_info.cpp******
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
#include "Account_info.h"
using namespace std;
void acc_info::setSSN(char ssn)
{
SSN = ssn;
return;
}
void acc_info::setacc_num(char Acc_Num)
{
acc_num = Acc_Num;
return;
}
void acc_info::setacc_bal(double Acc_Bal)
{
acc_bal = Acc_Bal;
}
void acc_info::setacc_type(char Acc_Type)
{
acc_type = Acc_Type;
}
char acc_info::getSSN() const
{
return (SSN);
}
char acc_info::getacc_num() const
{
return (acc_num);
}
double acc_info::getacc_bal() const
{
return (acc_bal);
}
char acc_info::getacc_type() const
{
return (acc_type);
}
|
*******************************End of Program********************************