Creating Bank accounts using classes

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********************************
Last edited on
You need to use code tags and properly format your code
http://www.cplusplus.com/articles/z13hAqkS/
As Yanson said, use code tags, this is almost unreadable in it's current state.

What sort of errors are you actually getting? We need a little more information before anyone can be of any help.
Thanks for the link. I didn't know about that. i hope now its fine
Last edited on
Line 132 to 166 of your main function is commented out so you will get some unresolved external errors and Your read_accts function needs to return a value after that it should compile.
@Yanson Thank you so much for your help! I fixed that and it worked but now im stuck on the print_accts function, it doesn't execute. I will copy the whole main program again in case
i have implemented the following code:

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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#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;

	/* 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:
			cout << "Invalid choice - try again\n\n";
			break;
		}
		// give user a chance to look at output before printing menu
		mypause();
	} while (not_done);


	//  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 &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\\Bank Accounts using classes\\inputfile.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 count;
}

int print_accts(const BankAccount account[], int num_accts)
{
	Name name;
	acc_info acct_info;

	// open output file
	ofstream outfile("con");                    //un-comment for debugging

	outfile << "\t\tMember in the Bank\n\n";
	outfile << "Name\t\tSSN\tAccount no\tAccount type\tAccount Balance\n\n";
	for (int count = 0; count < num_accts; count++)
	{
		name = account[count].getName();
		acct_info = account[count].getacc_info();

		outfile << name.getFirstname();
		outfile << " " << name.getLastname();
		outfile << "\t" << acct_info.getSSN();
		outfile << "\t" << acct_info.getacc_num();
		outfile << "\t" << acct_info.getacc_type();
		outfile << "\t" << acct_info.getacc_bal();
		outfile << endl;
	}

	outfile.close();
	return;
};

int findacct(const BankAccount account[], int num_accts)
{
	return num_accts;
};

int withdrawal(BankAccount account[], int num_accts)
{
	return num_accts;
};

int deposit(BankAccount account[], int num_accts)
{
	return num_accts;
};
int new_acct(BankAccount account[], int num_accts)
{
	return num_accts;
};
int close_acct(BankAccount account[], int num_accts)
{
	return num_accts;
};
void balance(const BankAccount account[], int num_accts)
{
	return;
};
void account_info(const BankAccount account[], int num_accts)
{
	return;
};

void mypause()
{
	system("pause");
	return;
};

Last edited on
Topic archived. No new replies allowed.