need help seems everyone is scared to help me

Define a class to represent a bank account. Include the following members.

Data members

Name of the depositor

Account number

Type of account ( Savings or Checking)

Account status (active or inactive)

Balance amount in the account

Write member functions to:

a) Assign initial values depending on the type of account (use constructors). Assume initial balance is

$500 in the case of savings, $1000 in the case of current account.

b) Activate an account if it is inactive.

c) Deposit an amount and update balance. Before depositing check that the account is active as you

cannot deposit money in an inactive account.

d) Withdraw an amount after checking if the account is active and the balance. After withdrawal, the account

balance should be updated. (note: If the balance is less than requested amount ask the user to reenter

the withdraw amount again)

e) Display account holders first name, last name, account number, status and balance.

Write a main program to achieve the above functionalities. Create an array of 5 account details, then

use a loop to display the contents of each account. Once your program runs successfully, comment the

array creation and loop display section. Finally, create a menu to allow the users to select their type of

transaction (deposit or withdrawal) for a particular account. The program must continue till the user

selects Exit option in the menu interface.

Sample menu:

1. Deposit

2. Withdraw

3. Exit
............................................




Here what i have so far:
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
#define BANKACCOUNT_H
#include <iostream>
#include <string>
#include <ctime>



using namespace std;



class BankAccount

{

private:


	string acnt_type;

	string owners_name;

	int acnt_number;
	bool status;

	double current_balances;
	double current_balancec;


public:

	
	BankAccount()
	{
		acnt_type = "savings";
		owners_name = "AAAAA";
		acnt_number = 0;
		status = 1;
		current_balances=500.0f;
		current_balancec = 1000.0f;
	}


	BankAccount(string acnt_type, string owners_name, int acnt_number, bool status, double current_balances, double current_balancec)
	{
		this->acnt_type = acnt_type;
		this->owners_name = owners_name;
		this->acnt_number = acnt_number;
		this->status = status;
		this->current_balances = current_balances;
		this->current_balancec = current_balancec;

	}

	BankAccount(const BankAccount & object)
	{
		acnt_type = object.acnt_type;
		owners_name = object.owners_name;
		acnt_number = object.acnt_number;
		status = object.status;
		current_balances = object.current_balances;
		current_balancec = object.current_balancec;

	}

	/*~Product()
	{
	cout << "Object destructor executing ..." << endl;
	this->display();
	cout << "Object destroyed and removed from memory." << endl;
	}*/

	void setacntType(string acnt_type)
	{
		this->acnt_type = acnt_type;
	}

	string getacntType() const
	{
		return acnt_type;
	}

	void setOwnersName(string owners_name)
	{
		this->owners_name = owners_name;
	}

	string getOwnersName() const
	{
		return owners_name;
	}

	void setAcntNumber(int acnt_number)
	{
		this->acnt_number = acnt_number;
	}

	int getAcntNumber() const
	{
		return acnt_number;
	}

	

	void setCurrentBals(double current_balances)
	{
		this->current_balances = current_balances;
	}

	double getCurrentBals() const
	{

		
		return current_balances;
	}

	void setCurrentBalc(double current_balancec)
	{
		this->current_balancec = current_balancec;
	}

	double getCurrentBalc() const
	{


		return current_balancec;
	}


	void setStatus(bool status)
	{


		this->status = status;
	}

	bool getStatus() const
	{
		if (status == 1)

		{

			cout << "Active" << endl;
		}

		else {

			cout << "Inactive" << endl;
		}

		return status;
	}



	void display()

	{
	

		cout << "Account Name: " << owners_name;

		cout	<< "Account Number: " << acnt_number;

		cout << "Account Status:" << status;

		cout << "Current Balance savings: " << current_balances;
		cout << "Current Balance Current: " << current_balancec;
	}

};




















Last edited on
Please use code tags on your code. Hint: Edit your post, then select your code and use the <> icon on the right side of the post.
in the main.cpp i have this:

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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#include "BankAccount.h"
#include <string>
#include <iostream>


using namespace std;


void run();
void menu();
BankAccount findaccount(int, BankAccount[], int);
bool saveaccount(int, BankAccount, BankAccount[], int);
BankAccount withdraw();
BankAccount desposit();

int main()
{

	run();

	return 0;

}

void run()
{
	const int size = 10;
	int option, itemCount = 0;
	BankAccount item;
	BankAccount items[size];

	do{

		menu();
		cin >> option;

		switch (option)
		{
		case 1:
			item = withdraw();
			if (saveaccount(itemCount, item, items, size))
			{
				itemCount++;
			}
			break;

		case 2:
			item = desposit();
			if (saveaccount(itemCount, item, items, size))
			{
				itemCount++;
			}
			break;


		case 3:
			cout << "Enter Account Number ";
			int acnt_number;
			cin >> acnt_number;
			findaccount(acnt_number, items, size).display();
			break;

		case 4:
			cout << "End of Program.\n";
			exit(0);
			break;

		default:
			cout << "Invalid menu option entered ..." << endl;
			break;
		}

	} while (option != 4);


}

void menu()
{
	cout << "System Menu" << endl;
	cout << "1 - Input Book Details" << endl;
	cout << "2 - Print Book Details" << endl;
	cout << "3 - Rent Book" << endl;
	cout << "4 - Return Book" << endl;
	cout << "5 - Exit" << endl;
	cout << "Select option: ";
}

BankAccount findaccount(int bankacnt_number, BankAccount  list[], int listSize)
{
	BankAccount account;

	for (int idx = 0; idx < listSize; idx++)
	{
		if (list[idx].getAcntNumber() == bankacnt_number)
		{
			account = list[idx];
			break;
		}
	}

	return account;
}

bool saveaccount(int count, BankAccount item, BankAccount list[], int listSize)
{
	if (count >= listSize || count < 0 || list[count].getAcntNumber() != 0)
	{
		return false;
	}

	list[count] = item;

	return true;
}

//Deposite()

BankAccount withdraw()
{
	string acnt_type;

	string owners_name;

	int acnt_number;
	bool status = 1;

	double current_balances = 500.0f;
	double current_balancec = 1000.0f;

	double w_amount, bal;

	cout << "Enter the name:";
	cin >> owners_name;
	cout << "Enter account Number:";
	cin >> acnt_number;
	cout << "Enter Account Type**savings or current";
	cin >> acnt_type;
	if (acnt_type == "savings")
	{
		if (current_balances>500)
		{
			cout << "\nenter withdraw amount";
			cin >> w_amount;
			if ((current_balances - w_amount) >= 500)
			{
				cout << "\namount is withdraw successfully";
				bal = current_balances - w_amount;
				cout << "\nAvailable balance is:" << bal;
			}
		}
		else
			cout << "\naccount balance is less than 500 withdraw cancled";
	}
	else
	{
		if (current_balancec>1000)
		{
			cout << "\nenter withdraw amount";
			cin >> w_amount;
			if ((current_balancec - w_amount) >= 1000)
			{
				cout << "\namount withdraw successfully";
				bal = current_balancec - w_amount;
				cout << "\nAvailable balance is:" << bal;
			}
		}
		else
			cout << "\naccount balance is less than 1000 withdraw cancled";
	}
	return BankAccount(acnt_type, owners_name, acnt_number, status, current_balances, current_balancec);
}

BankAccount deposit()
{
	string acnt_type;

	string owners_name;

	int acnt_number;
	bool status = 1;

	double current_balances = 500.0f;
	double current_balancec = 1000.0f;
	double d_amount, bal;

	cout << "Enter the name:";
	cin >> owners_name;
	cout << "Enter account Number:";
	cin >> acnt_number;
	cout << "Enter Account Type**savings or current";
	cin >> acnt_type;

	cout << "Enter account status 1=active 2=inactive:";
	cin >> status;

	if (status == 0){
		cout << "acount is inactive Cannot continue";
		exit(0);

	}

	if (acnt_type == "savings")
	{
		cout << "\nEnter the deposite amount:";
		cin >> d_amount;
		if ((current_balances + d_amount) >= 500)
		{
			bal = (current_balances + d_amount);
			cout << "\nThe available balance is:" << bal;
		}
		else
			cout << "\nThe deposition cancled, amount is less than 500";
	}
	else
	{
		cout << "\nEnter the deposite amount:";
		cin >> d_amount;
		if ((current_balancec + d_amount) >= 1000)
		{
			bal = (current_balancec + d_amount);
			cout << "\nThe available balance is:" << bal;
		}
		else
			cout << "\nThe deposition cancled, amount is less than 1000";
	}

	return BankAccount(acnt_type, owners_name, acnt_number, status, current_balances, current_balancec);
}
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/177789/
Except for one error in line 48 of your application, I was surprised your code even compiled. To suggest people are afraid to help you, it would be more accurate to say they are not the least inclined as it's obvious you just cut and pasted a bunch of stuff together in hopes someone would come along and make it work. First clue, your menu function is all about books, not bank accounts. In the event your still interested in help though, let's start with this.

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 _BANKING_
#define _BANKING_

#include <string>
using namespace std;

class Account {
  private:	
	unsigned AcctType : 1;			// 0 = Savings, 1 = Chequing
	unsigned   Active : 1;			// 1 = Active, 0 otherwise

	string UserNme;		// Owner of account
	string AcctNum;		// Assuming account number is alphanumeric
	double Balance;
	
  public:
	Account  () { AcctType = 0; Active = 0; Balance = 0; }
	Account  ( string, bool, string, double );
	bool  Deposit  ( double );
	bool Withdraw ( double );
	     Show ();
};

#endif 

There is a lot to be said about keeping functions separate from definition, but as line 17 shows, there are exceptions to this rule. Why?
ok i have changed the code do you want the source code
and i am sorry i just needed to draw some attention javascript:editbox2.editPreview()to the matter no disrespect
THis is the Main.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#include "BankAccount.h"
#include <string>
#include <iostream>


//GROUP MEMBERS ROGER REYNOLDS AND LEIGHTON FORD
void run();
void menu();
BankAccount findaccount(int, BankAccount[], int);

BankAccount withdraw();
BankAccount deposit();


using namespace std;


int main()
{
	

	

	run();

	cin.get();
	cin.get();
	return 0;

}


void run()
{
	const int size = 5;
	int option, itemCount = 0;
	BankAccount item;
	BankAccount acntaccount[size];
	int acnt_number;
	do{

		menu();
		cin >> option;

		switch (option)
		{
		case 1:
			cout << "Enter Account Number ";
			
			cin >> acnt_number;

			findaccount(acnt_number, acntaccount, size).display();
			item = withdraw();
		


			break;

		case 2:
			cout << "Enter Account Number ";
			cin >> acnt_number;
			findaccount(acnt_number, acntaccount, size).display();

			item = deposit();

			break;


		case 3:
			cout << "End of Program.\n";
			exit(0);
			break;

		default:
			cout << "Invalid menu option entered ..." << endl;
			break;
		}

	} while (option != 4);


}


void menu()
{
	cout << "System Menu" << endl;
	cout << "1 - Withdraw" << endl;
	cout << "2 - Deposit" << endl;
	cout << "3 - Exit" << endl;
	cout << "Select option: ";
}





BankAccount findaccount(int bankacnt_number, BankAccount acntaccount[], int listsize)
{
	BankAccount account;


	//account 1
	BankAccount ac1("savings", "mario ling", 123, 0, 500.0);


	//account 2

	BankAccount ac2("savings", "orrin jones", 124, 1, 1000.0);

	//account 3

	BankAccount ac3("current", "Shean Peart", 125, 1, 1000.0);
	//account 4

	BankAccount ac4("current", "Lisa Hanna", 126, 0, 1000.0);

	//account 5
	BankAccount ac5("savings", "Leighton Ford", 127, 1, 500.0);

	acntaccount[0] = ac1;
	acntaccount[1] = ac2;
	acntaccount[2] = ac3;
	acntaccount[3] = ac4;
	acntaccount[4] = ac5;


	for (int idx = 0; idx < listsize; idx++)
	{
		if (acntaccount[idx].getAcntNumber() == bankacnt_number)
		{
			account = acntaccount[idx];
			break;
		}
	}

	return account;
}



//withdraw

BankAccount withdraw()
{

	BankAccount ac;
	string acnt_type;

	string owners_name;

	int acnt_number = 0;

	bool status = 0;

	double w_amount, bal;



	if (ac.getStatus() == 0){
		cout << "\nAccount status in Inactive Please Actvivate the account pressing 1:";
		cin >> status;
	}
	 else if (ac.getBalc()== 500.0)
	{

		cout << "savings account" << endl;
		cout << "\nenter withdraw amount: ";
		cin >> w_amount;
		bal = 500;
		bal = bal - w_amount;
		cout << "\namount is withdraw successfully\n";
		cout << "\nAvailable balance is:" << bal <<endl;
		cout << "\n" << endl;
	}

	 else if (ac.getBalc() == 1000.0)
	 
		cout << "current account" << endl;
	cout << "\nenter withdraw amount: ";
	cin >> w_amount;
	bal = 1000;
	bal = bal - w_amount;
	cout << "\namount is withdraw successfully\n";
	cout << "\nAvailable balance is:" << bal <<endl;
	cout << "\n" << endl;
	 

	return BankAccount(acnt_type, owners_name, acnt_number, status, bal);
}

//Deposit
BankAccount deposit()
{
	BankAccount ac;
	string acnt_type;

	string owners_name;

	int acnt_number = 0;
	bool status = 0;

	double d_amount, bal;



	if (ac.getStatus() == 0){
		cout << "\nAccount status in Inactive Please Actvivate the account pressing 1:";
		cin >> status;
	}
	else if (acnt_type == "savings")
	{
		cout << "savings account" << endl;
		cout << "\nenter Deposit amount: ";
		cin >> d_amount;
		bal = 500;
		bal = bal + d_amount;
		cout << "\namount is Deposited successfully\n";
		cout << "\nAvailable balance is:" << bal <<endl;
		cout << "\n" << endl;
	}

	else
		cout << "current account" << endl;
	cout << "\nenter Deposit amount: ";
	cin >> d_amount;
	bal = 1000;
	bal = bal + d_amount;
	cout << "\namount is Deposited successfully\n";
	cout << "\nAvailable balance is:" << bal <<endl;
	cout << "\n" << endl;


	return BankAccount(acnt_type, owners_name, acnt_number, status, bal);
}


Header Class file
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
#define BANKACCOUNT_H
#include <iostream>
#include <string>


//GROUP MEMBERS ROGER REYNOLDS AND LEIGHTON FORD

using namespace std;



class BankAccount

{

private:


	string acnt_type;

	string owners_name;

	int acnt_number;
	bool status;

	double bal;

public:

	
	BankAccount()
	{
		acnt_type = "type";
		owners_name = "AAAAA";
		acnt_number = 0;
		status = 1;
		bal = 0.0f;
	}


	BankAccount(string acnt_type, string owners_name, int acnt_number, bool status, double bal)
	{
		this->acnt_type = acnt_type;
		this->owners_name = owners_name;
		this->acnt_number = acnt_number;
		this->status = status;
		this->bal = bal;
	}

	BankAccount(const BankAccount & object)
	{
		acnt_type = object.acnt_type;
		owners_name = object.owners_name;
		acnt_number = object.acnt_number;
		status = object.status;
		bal = object.bal;
	}



	void setacntType(string acnt_type)
	{
		this->acnt_type = acnt_type;
	}

	string getacntType() const
	{
		

		return acnt_type;
	}

	void setOwnersName(string owners_name)
	{
		this->owners_name = owners_name;
	}

	string getOwnersName() const
	{
		return owners_name;
	}

	void setAcntNumber(int acnt_number)
	{
		this->acnt_number = acnt_number;
	}

	int getAcntNumber() const
	{
		return acnt_number;
	}

	

	

	void setBalc(double bal)
	{
		/*float w_amount;
		if (acnt_type == "savings"){

			bal = 500;
			bal = bal - w_amount;

		}
		*/
		this->bal = bal;
	}

	double getBalc() const
	{

		

		return bal;
	}


	void setStatus(bool status)
	{


		this->status = status;
	}

	bool getStatus() const
	{
		if (status == 1)

		{

			cout << "Active" << endl;
		}

		else {

			cout << "Inactive" << endl;
		}

		return status;
	}



	void display()

	{
	
		cout << "\n*******Account information*******\n" << endl;
		cout << "Account Name:   " << owners_name <<endl;

		cout << "Account Number:	" << acnt_number << endl;

		cout << "Account Status:	"; getStatus();
		cout << "Account Type:	" << acnt_type << endl;

		cout << "Balance is :	" << bal << endl;
		
	}

};
Cant get the withdraw and deposit to minus and add from the accounts i placed in the arrays .
Let's simplify things by abandoning your code and building from this.

Bank.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
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef _BANKING_
#define _BANKING_

#include <string>
using namespace std;

	#define SAVINGS   0
	#define CHEQUING  1
	
class Account {
  private:	
	unsigned AcctType : 1;			// 0 = Savings, 1 = Chequing
	unsigned   Active : 1;			// 1 = Active, 0 otherwise

	string UserNme;		// Owner of account
	string AcctNum;		// Assuming account number is alphanumeric
	double Balance;
	
  public:
	Account  () { AcctType = 0; Active = 0; Balance = 0; }
	void   Create ( string, unsigned, string );
	bool  Deposit ( double );
	bool Withdraw ( double );
	void Show (void);
};

/* Member functions outside class definition */
void Account::Create ( string AcctN, unsigned Type, string Owner ) {
	Active = 1;			// Activate account
	AcctNum = AcctN;
	AcctType = Type;
	UserNme = Owner;
	
	if ( Type == CHEQUING )
		Balance = 1e3; else Balance = 5e2;
}

#endif 


Bank.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include "Bank.h"

using namespace std;

	Account Acct [5];
	
int main (void) {
	
	// Parts (a) & (b) of assignment. Initialize and active five accounts.
	Acct [0].Create ( "123", 0, "Mario Ling" );
	Acct [1].Create ( "124", 0, "Orrin Jones" );
	Acct [2].Create ( "125", 1, "Shean Peart" );
	Acct [3].Create ( "126", 1, "Lisa Hanna" );
	Acct [4].Create ( "127", 0, "Leighton Ford" );
	
	return 0;
}


From now on, only show the parts that are new or changed and not include the entire listing each time.

1: Add your menu to Bank.cc and switch statement
2: Implement procedure in Bank.h to display account details.
Ok am gonna do that now.
Can you reply to let me know that your there please
Thanks but I need to did the account in the array when I select withdraw from the menu function and so on.
Can you copy and paste the code that I did and try compile it and see how I works and the problems I am having with withdraw and deposit when I type the account number and enter the amount I want to withdraw. It's not selecting the correct account type to withdraw or deposit the money from. It's using current rather than savings for the calculations. @shiftleft
Last edited on
I did compile your code and only came up with one warning. int option, itemCount and your not using itemCount anywhere.

At first glance, I would have never guessed it would work and when I trace through it, it's nothing but a bunch of random code that just does stuff. So to make it work as is, is impossible without a rewrite from scratch. That the compiler is satisfied that your code is syntactically correct, doesn't not mean it's a workable application.

In any event, if you trace through findaccount () you should be able to see right away why balance is not being updated properly.
On the second code I did my best in terms of getting it to function I rewrote the whole thing and the deposit and withdraw functions I did those myself but its still not working. Am trying my best.
Topic archived. No new replies allowed.