Have a few errors

Pages: 1234
Outline is fine be me.
the first code you posted
1
2
3
4
void BankingSystem::AddAccount(Account newAccount) {
   // We simply need to add the new account to our vector
   accounts_.push_back(newAccount);
}


Does this go above main?


No, that should go in bankingsystem.cpp. and you will also need to put this in your bankingsystem.h file:
1
2
3
4
5
6
class BankingSystem {
// Some of your code
   public:
   // Some more code
   // This is all that needs added to the bankingsystem.h file
   void AddAccount(Account newAccount);


I think your teacher is introducing too much at one time. The concept of header files and separate source files is a confusing one and not well explained very often. A general rule of thumb is this:
name_of_a_class.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//#include necessary files

class name_of_a_class {
   private:
      // Put all of the class variables here
      // Notice: they're typically started with a lowercase m or m_
      std::string mName;
      // Some more class variables
   public:
      // Put all of the class functions here
      std::string GetName();
      void SetName(std::string name);
      // Some more class functions
}; // That's all for the .h file 


name_of_a_class.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "name_of_a_class.h"

// Now you need to define each of the functions
// Notice: You must use the class name and two : to define the function
std::string name_of_a_class::GetName() {
   // Returns the value of the private variable
   return mName;
}

void name_of_a_class::SetName(std::string name) {
   mName = name;
}

// Other functions contained as well.

// Nothing else should exist here 


main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// #include necessary header files

#include "name_of_a_class.h"

// Any local function prototypes go here

int main() {
   // Create a new object pointer
   name_of_a_class *myClass = new name_of_a_class();
   // Use the -> operator to dereference the object pointer
   //    and access the public members
   myClass->SetName("Volatile Pulse");

   // Can use them however you need
   std::cout << "myClass's name is: " << myClass->GetName();
}

// Any function definitions typically go here 


Note to self: Pick a better class name next time.

I hope this cleared up the confusion about what should go into each file. I typed that in this editor so it might not be perfect, but should give you a good idea.
Ya I do believe that it did.
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
Account.h
/***********
Lauren Buecker
Project 2
Account.h
**********/
#include <string>
using namespace std;

class Account 

{	
private:
string _accountNumber;
string _passCode;
string _lastName;
string _firstName;
double _balance;
double _startingBalance;


public:

Account();   
void setfirstName( string strName );
void setlastName ( string strName);
void setaccountNumber (	string strAccount );
void setpsCode ( string strCode );
void setstartBalance( double dblBalance );

int selection;
string getfirstName ();
string getlastName();
string getaccountNumber ();
string getpassCode ();
double getstartBalance ();
};

BankingSystem.h
/************
Lauren Buecker 
Project 2
BankingSystem.h
**************/
#include <iostream>
#include <string>
#include <vector>
#include "Account.h"
using namespace std; 

class BankingSystem
{
private:
	vector <Account> accounts_; 
public:
	int selection;
	string showMenu;
	void setselection ( int selection );
	void AddAccount(Account newAccount);
	void eraseAccount(Account eraseAccount);
	string getselection ();
	string deleteAccount();
	string addAccount();
	string listAccounts();
};
Account.cpp
/***********
Lauren Buecker 
Project 2
Account.cpp
**************/
#include <iostream>
#include <string>
#include "Account.h"
using namespace std;
void Account::setfirstName( string strName )
{ 
m_firstName=strName;
}
void Account::setlastName ( string strName)
{ 
m_lastName=strName;
}
void Account::setaccountNumber ( string strAccount )
{
m_accountNumber=strAccount;
}
void Account::setpsCode ( string strCode )
{
m_passCode=strCode;
}	
void Account::setstartBalance( double balance )
{
m_startingBalance=balance;
}


string Account::getfirstName ()
{	
return m_firstName;	   
}
string Account::getlastName()
{
return m_lastName;
}
string Account::getaccountNumber ()
{ 
return m_accountNumber;
}
string Account::getpassCode ()
{
return m_passCode;
}
Account::Account()
{
	m_startingBalance=0;
	m_balance=0;
}
double Account::getstartBalance()
{
	double balance = m_balance + m_startingBalance;
	return balance;
}

BankingSystem.cpp 
/***********
Lauren Buecker 
Project 2
BankingSystem.cpp
************/
#include <iostream>
#include "BankingSystem.h"
using namespace std;

void BankingSystem::eraseAccount(Account eraseAccount)
	{ 
		erase();
}

void BankingSystem::AddAccount(Account newAccount) {
   // We simply need to add the new account to our vector
   accounts_.push_back(newAccount);
}

vector<Account> listAccounts(Account listAccount);

Account getAccount(int accountNumber);

void saveAccount(Account &account);

Main.cpp
#include <iostream> // allows program to perform input and output
#include "Account.h" // include definition of class Account
#include "BankingSystem.h" // include definition of class BankingSystem
using namespace std; // use std namespace

int displayMenu(); // function prototype
Account addAccount();
Account eraseAccount();
int main()
{
    // display welcome message
    cout << "*** Welcome to the Banking System ***\n" << endl;

    // variable declaration
    // allocate storage for object of type BankingSystem
    BankingSystem* myBankingSystem = new BankingSystem();
    int menu; // menu number chosen by user

    menu = displayMenu(); // function call to display menu and menu selection

    while ( menu != 6 ) // loop until exit is chosen
    {
        switch ( menu ) // switch statement
        {
        case 1: // add new account
            myBankingSystem->addAccount();
            break;
        case 2: // erase existing account
            myBankingSystem->eraseAccount();
            break;
        case 3: // inquire existing account
            myBankingSystem->listAccount();
            break;
        case 4: // save account info to file
            myBankingSystem->saveToFile();
            break;
        case 5: // load account info from file
            myBankingSystem->loadFromFile();
            break;
        default: // display message to choose proper menu numbers
            cout << "Incorrect menu selection.\nPlease enter menu 1,2,3,4,5, or 6 to end.\n\n";
            break;
        }

        menu = displayMenu(); // function call to display menu and menu selection

     }


    delete myBankingSystem; // free the space for the object BankingSystem
    system("PAUSE"); // display "Press any key to continue" when debag is completed
    return 0; // indicate the program ended successfully
} // end main


// function to display menu and prompt user to select
int displayMenu()
{
    int input; // variable declaration
    
    // display menu
    cout << "\n(1) Add Account\n";
    cout << "(2) Delete Account\n";
    cout << "(3) Account Inquiry\n";
    cout << "(4) Save Accounts to File\n";
    cout << "(5) Load Accounts from File\n";
    cout << "(6) Exit\n\n" << endl;

    // prompt user to input
    cout << "Enter selection: ";
    cin >> input;

    return input; // return the selection
}
Account addAccount()
{
Account newAccount;

string accountNumber;
string firstName;
string lastName;
string passCode;
double startingBalance;

std::cout << "Account Number: ";
cin >> accountNumber;
newAccount.setaccountNumber(accountNumber);
cout << "Please Enter First Name ";
cin  >> firstName;	 
newAccount.setfirstName(firstName);
cout<< "Please Enter Last Name ";
cin >> lastName;
newAccount.setlastName(lastName);
cout << "Please Enter Account password ";
cin >> passCode;
newAccount.setpsCode(passCode);
cout << "Enter Starting Balance ";
cin >> startingBalance;
newAccount.setstartBalance(startingBalance);
accounts_.push_back(newAccount);
cout << "Account Successfully Created\n";
return newAccount;
};
Account eraseAccount ()
{
	Account deleteAccount;
	string accountNumber;
	string firstName;
	string lastName;
    for (int i=0; i < accounts.size(); i++)
{
if (accounts[i].getaccountNumber() == accountNumber)
{
accounts.erase(accounts.begin()+i);
break;}
	}
}

Should I make the addAccount, eraseAccount, listAccount, all ints?
Last edited on
1>c:\users\lauren\documents\visual studio 2010\projects\mybankingsystem\mybankingsystem\main.cpp(42): error C2039: 'DeleteAccount' : is not a member of 'BankingSystem'
1> c:\users\lauren\documents\visual studio 2010\projects\mybankingsystem\mybankingsystem\bankingsystem.h(15) : see declaration of 'BankingSystem'
1>c:\users\lauren\documents\visual studio 2010\projects\mybankingsystem\mybankingsystem\main.cpp(45): error C2039: 'listAccount' : is not a member of 'BankingSystem'
1> c:\users\lauren\documents\visual studio 2010\projects\mybankingsystem\mybankingsystem\bankingsystem.h(15) : see declaration of 'BankingSystem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Main.cpp
case 2: // erase existing account
           myBankingSystem->DeleteAccount(deleteAccount());
            break;
BankingSystem.cpp
void BankingSystem::DeleteAccount(string accountNumber) 
{
	for (int i=0; i < accounts_.size(); i++)
{
if (accounts_[i].getaccountNumber() == accountNumber)
{
accounts_.erase(accounts_.begin()+i);
	break;
}
	}
}
BankingSystem.h
void DeleteAccount(string accountNumber);
In BankingSystem.h, does your declaration of BankingSystem have the line
void DeleteAccount(string accountNumber); inside it?
From that above the class BankingSystem indeed has no member DeleteAccount but deleteAccount.

C++ is case sensitive.
Last edited on
Hi Guys,

Here is my skeleton code, showing how I think the classes should work together.

Again, I have done this because there some confusion in your learning, what you need is an outline so you can see how it all should work.

Some things to note:

The system is all from the point of the bank manager, - there is no input from any customer stakeholder.

See how simple main.cpp is?

The "C" at the beginning of the class names just says that the variable is a class. The is a fairly normal convention - Qt classes start with Q, KDE classes start with K.

The CAccount class is just like a record in a data base, it has a set function and a get function and that's it. All the work is done by the CBank class. You could have a ChangePassWd function. Also note how there is no member variable StartingBalance.

I wrote the CAccount::setDetails functions so that it could also be used by the LoadFile option. The function that does this option can repeatedly call the setDetails function from a loop.

See how the getDetails returns the this pointer - how easy is that!! The InquireAcct function can use the pointer returned to access the members of the CAccount class.

So you can see now what I meant about not needing all those set & get functions, also you can see how almost everything goes in a class. There is very minimal work done by main().

With the CBank class - I had an extra function AuthBM - Authorise Bank Manager's Password - this could be used with an option 0 on the menu - BM Login.

As I said in the comments - I haven't put too much effort into the return types of the functions, maybe you guys can think about that. Try to return something so that the calling function can check that things work.

It would also be easy to write a function that returned the total bank funds - ie the sum of all the acct balances

With ShowMenu & ProcessMenu functions, I put them in main(), because they are for the whole application. As an example, If I were to create a GUI app called MyApp (that looks like a Windows Notepad) using the Qt system, it would have these files:

main.cpp
MyApp.cpp
MyApp.h

Any other classes I invent

main.cpp just runs the app & creates a window frame, not much else
MyApp.cpp creates a TextEdit Control, All the menus & Toolbars, the code that carries out these is in here too.

So the menu is in the main application.

Now, the other way to do things is to have a Menu class, however it is simple as it is now. Would be good for you to create a Menu class, as a learning exercise - after you have go this all working.

Apologies for it taking so long - I had linker problems on my system, then some other dramas to deal with today.

I hope this helps everyone to get a clear understanding - Now you could go on & write the rest of the functions.

So here is the code:
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
#include <iostream>


#include "CBank.h"

using std::cout;	//this is much better then using namespace std
using std::cin;		//I prefer to do this rather than std:: everywhere
using std::endl;


void ShowMenu();
bool ProcessMenu(const unsigned int MenuOpt, CBank* pCBank, bool
				QuitMenu);

int main() {
	
	unsigned MenuOpt = 0; //The selected Menu Option
	bool QuitMenu = false;
	
	//Create a Bank object
	
	CBank* pCBank = new CBank();
	
	
	
	
	while(!QuitMenu) {
		ShowMenu();
		cin >> MenuOpt;	//haven't done any error checking
		QuitMenu = ProcessMenu(MenuOpt, pCBank, QuitMenu);
	}
    
    return 0;
}


void ShowMenu() {
	cout << "Welcome to My Banking System\n\n" ;
	
	cout << "(1) Add account\n";
	cout << "(2) Delete Account\n";
	cout << "(3) Account Inquiry\n";
	cout << "(4) Save Accounts to File\n";
	cout << "(5) Load Accounts from File\n";
	cout << "(6) Exit\n\n";
	
	cout << "Please Enter your Selection" << endl;
}

bool ProcessMenu(const unsigned int MenuOpt, CBank* pCBank, bool QuitMenu)
{
	switch (MenuOpt)
	{
		case 1:
			//cout << "(1) Add account Option not implemented Yet\n";
			pCBank->NewAcct();
			
		break;
		
		case 2:
			cout << "(2) Delete Account Option not implemented Yet\n";
		break;
		
		case 3:
			cout << "(3) Account Inquiry Option not implemented Yet\n";
		break;
		
		case 4:
			cout << "(4) Save Accounts to File Option not implemented Yet\n";
		break;
		
		case 5: 
			cout << "(5) Load Accounts from File Option not implemented Yet\n";
		break;
		
		case 6:
			cout << "Exiting Program\n";
			QuitMenu = true;
			return QuitMenu;
			break;
			
		default:
			cout << "Invalid selection. Please Choose another option\n";
		break;
		
		
	}
}


CAccount.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
#include <string>

#ifndef CACCOUNT_H
#define CACCOUNT_H

using std::string;

class CAccount {
private:

	bool m_CleanAcct;
	string m_AcctNum; 
	string m_FirstName;
	string m_LastName;
	string m_PinNum;	
	double m_Balance;

public:
CAccount();
~CAccount();

bool setDetails(string AcctNum, string FName, 
				string LName, string Pin, 
				double StartBal) ;
				
CAccount* getDetails() ;
};

#endif // CACCOUNT_H



CAccount.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
#include <string>

#ifndef CACCOUNT_H
#define CACCOUNT_H

using std::string;

class CAccount {
private:

	bool m_CleanAcct;
	string m_AcctNum; 
	string m_FirstName;
	string m_LastName;
	string m_PinNum;	
	double m_Balance;

public:
CAccount();
~CAccount();

bool setDetails(string AcctNum, string FName, 
				string LName, string Pin, 
				double StartBal) ;
				
CAccount* getDetails() ;
};

#endif // CACCOUNT_H


CBank.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
#include <string>

#ifndef CACCOUNT_H
#define CACCOUNT_H

using std::string;

class CAccount {
private:

	bool m_CleanAcct;
	string m_AcctNum; 
	string m_FirstName;
	string m_LastName;
	string m_PinNum;	
	double m_Balance;

public:
CAccount();
~CAccount();

bool setDetails(string AcctNum, string FName, 
				string LName, string Pin, 
				double StartBal) ;
				
CAccount* getDetails() ;
};

#endif // CACCOUNT_H


CBank.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
#include <iostream>
#include "CBank.h"
//#include "CAccount.h"

using std::cout;	//this is much better then using namespace std
using std::cin;		//I prefer to do this rather than std:: everywhere
using std::endl;

CBank::CBank() {	//constructor - called everytime an object
					//of this type is created
	BMPassWd = "$BM2012$";
}

CBank::~CBank() {	//destructor - called when object is destroyed

}


void CBank::NewAcct() {
	
	string AcctNum(6, '0');
	string FName = ""; 
	string LName = "";
	string Pin(4, '0'); 
	double StartBal = 0.0;
	
	//create a CAccount object
	//if you want to use new here change AllAccts to vector of ptrs to Acct
	CAccount EmptyAcct;	//NewAcct is an obj of type CAccount
	
	cout << "Please Enter Account Number: 6 Digits \n" ;
	cin >> AcctNum;
	
	cout << "Please Enter First Name: \n";
	cin  >> FName;
	
	cout<< "Please Enter Last Name: \n";
	cin >> LName;
	
	cout << "Please Enter Account PIN: 4 digits \n";
	cin >> Pin;
	
	cout << "Enter Starting Balance \n";
	cin >> StartBal;
	
	//put all this info into the CAccount object
	EmptyAcct.setDetails(AcctNum, FName, LName, Pin, StartBal);
	
	AllAccts.push_back(EmptyAcct);
	cout << "Account Successfully Created\n";
}
void CBank::DelAcct() {
	cout << "(2) Delete Account Option not implemented Yet\n";
}


CAccount * CBank::InquireAcct() { //Get all the details of an acct
	cout << "(3) Account Inquiry Option not implemented Yet\n";
}

void CBank::SaveAcct() {
	cout << "(4) Save Accounts to File Option not implemented Yet\n";
}


void CBank::LoadAcct() {
	cout << "(5) Load Accounts from File Option not implemented Yet\n";
}



bool CBank::AuthBM() {  //Authorise Bank Managers Password

}

CAccount * CBank::FindAcct() {
	
}



Edit Sorry I messed up the filenames,
Last edited on
Right here's another go at putting the right code in:


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
#include <iostream>


#include "CBank.h"

using std::cout;	//this is much better then using namespace std
using std::cin;		//I prefer to do this rather than std:: everywhere
using std::endl;


void ShowMenu();
bool ProcessMenu(const unsigned int MenuOpt, CBank* pCBank, bool
				QuitMenu);

int main() {
	
	unsigned MenuOpt = 0; //The selected Menu Option
	bool QuitMenu = false;
	
	//Create a Bank object
	
	CBank* pCBank = new CBank();
	
	
	
	
	while(!QuitMenu) {
		ShowMenu();
		cin >> MenuOpt;	//haven't done any error checking
		QuitMenu = ProcessMenu(MenuOpt, pCBank, QuitMenu);
	}
    
    return 0;
}


void ShowMenu() {
	cout << "Welcome to My Banking System\n\n" ;
	
	cout << "(1) Add account\n";
	cout << "(2) Delete Account\n";
	cout << "(3) Account Inquiry\n";
	cout << "(4) Save Accounts to File\n";
	cout << "(5) Load Accounts from File\n";
	cout << "(6) Exit\n\n";
	
	cout << "Please Enter your Selection" << endl;
}

bool ProcessMenu(const unsigned int MenuOpt, CBank* pCBank, bool QuitMenu)
{
	switch (MenuOpt)
	{
		case 1:
			//cout << "(1) Add account Option not implemented Yet\n";
			pCBank->NewAcct();
			
		break;
		
		case 2:
			cout << "(2) Delete Account Option not implemented Yet\n";
		break;
		
		case 3:
			cout << "(3) Account Inquiry Option not implemented Yet\n";
		break;
		
		case 4:
			cout << "(4) Save Accounts to File Option not implemented Yet\n";
		break;
		
		case 5: 
			cout << "(5) Load Accounts from File Option not implemented Yet\n";
		break;
		
		case 6:
			cout << "Exiting Program\n";
			QuitMenu = true;
			return QuitMenu;
			break;
			
		default:
			cout << "Invalid selection. Please Choose another option\n";
		break;
		
		
	}
}


CAccount.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
#include <string>

#ifndef CACCOUNT_H
#define CACCOUNT_H

using std::string;

class CAccount {
private:

	bool m_CleanAcct;
	string m_AcctNum; 
	string m_FirstName;
	string m_LastName;
	string m_PinNum;	
	double m_Balance;

public:
CAccount();
~CAccount();

bool setDetails(string AcctNum, string FName, 
				string LName, string Pin, 
				double StartBal) ;
				
CAccount* getDetails() ;
};

#endif // CACCOUNT_H


CAccount.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
#include "CAccount.h"
CAccount::CAccount() {
//inialise member variales - this is the default constructor function
 m_CleanAcct = true;	//so we don't overwrite an existing acct'
 m_AcctNum ="000000"; 
 m_FirstName = "";
 m_LastName = "";
 m_PinNum = "AAAA";	//length 4 init to "AAAA"
 m_Balance = 0.0;

}

CAccount::~CAccount() {

}
bool CAccount::setDetails(string AcctNum, string FName, 
						  string LName, string Pin, 
						  double StartBal) {
	if (!m_CleanAcct) {	//braces not needed, but I do it as defensive measure
						//if more code is addded later
		return false;	//acct exists so don't overwrite
	}
	else {
		m_CleanAcct = false;	//acct is new, so set the vars
		
		m_AcctNum = AcctNum;
		m_FirstName = FName;
		m_LastName = LName;
		m_PinNum = Pin;
		m_Balance = StartBal;
		
		return true;
	
	}

}
CAccount* CAccount::getDetails() {
	return this;	//returns a pointer to this CAccount object
					//you can then use the pointer to access the member
					//variables
}


CBank.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
39
40
41
#ifndef CBANK_H
#define CBANK_H

#include <string>
#include <vector>

#include "CAccount.h"


using std::string;
using std::vector;

class CBank {
	
private:
	//vector of individual accounts
vector<CAccount> AllAccts;

string BMPassWd;  
	
bool AuthBM () ;	//Authorise Bank Managers Password
CAccount* FindAcct() ;	//return an acct found in vector

public:
 CBank();	//default constructor
 ~CBank();	//default destructor
	
	//some of these return types could be changed to make better
	//that is return something so you can check it worked
 
void NewAcct();		//Create new account object, push into vector
void DelAcct() ;		//Remove acct from vector
CAccount * InquireAcct() ; 

void LoadAcct() ;  	//Load accounts from File
void SaveAcct() ;	//Save all accts to file

};

#endif // CBANK_H


CBank.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
#include <iostream>
#include "CBank.h"
//#include "CAccount.h"

using std::cout;	//this is much better then using namespace std
using std::cin;		//I prefer to do this rather than std:: everywhere
using std::endl;

CBank::CBank() {	//constructor - called everytime an object
					//of this type is created
	BMPassWd = "$BM2012$";
}

CBank::~CBank() {	//destructor - called when object is destroyed

}


void CBank::NewAcct() {
	
	string AcctNum(6, '0');
	string FName = ""; 
	string LName = "";
	string Pin(4, '0'); 
	double StartBal = 0.0;
	
	//create a CAccount object
	//if you want to use new here change AllAccts to vector of ptrs to Acct
	CAccount EmptyAcct;	//NewAcct is an obj of type CAccount
	
	cout << "Please Enter Account Number: 6 Digits \n" ;
	cin >> AcctNum;
	
	cout << "Please Enter First Name: \n";
	cin  >> FName;
	
	cout<< "Please Enter Last Name: \n";
	cin >> LName;
	
	cout << "Please Enter Account PIN: 4 digits \n";
	cin >> Pin;
	
	cout << "Enter Starting Balance \n";
	cin >> StartBal;
	
	//put all this info into the CAccount object
	EmptyAcct.setDetails(AcctNum, FName, LName, Pin, StartBal);
	
	AllAccts.push_back(EmptyAcct);
	cout << "Account Successfully Created\n";
}
void CBank::DelAcct() {
	cout << "(2) Delete Account Option not implemented Yet\n";
}


CAccount * CBank::InquireAcct() { //Get all the details of an acct
	cout << "(3) Account Inquiry Option not implemented Yet\n";
}

void CBank::SaveAcct() {
	cout << "(4) Save Accounts to File Option not implemented Yet\n";
}


void CBank::LoadAcct() {
	cout << "(5) Load Accounts from File Option not implemented Yet\n";
}



bool CBank::AuthBM() {  //Authorise Bank Managers Password

}

CAccount * CBank::FindAcct() {
	
}

Last edited on
I forgot to put a delete to go with the new CBank in main().

For every object created with new, there should be a corresponding delete (or delete[] for arrays), otherwise there will be memory leaks.

Not a particular problem at the moment, there is only 1 CBank obj (it's destroyed anyway), but is good practice to use delete regardless.

This problem is most noticeable if lot's of objects are being created.

HTH
1
2
3
CAccount * CBank::InquireAcct() { //Get all the details of an acct
	cout << "(3) Account Inquiry Option not implemented Yet\n";
}


This part is confusing me...it says that it "must return a value" what about it is causing it to say that?
zq8 wrote:
This part is confusing me...it says that it "must return a value" what about it is causing it to say that?


You are right. My design has a FindAcct function because it needs to be used in several places - so this saves having to rewrite this code every time you want to do something with an account.

The FindAcct function should return a pointer to an CAccount class, so that a function like InquireAcct() can use it to call the relevant get function in CAccount . You might need to have more get functions in CAccount, as you can't access private members via a pointer. The InquireAcct function could be void, or get it to return something so you can check that it worked. As I said n my comments, I hadn't thought about what args or return types functions should have - I was leaving that up to you guys to think abbout.

Can one of you please post the full assignment question?

It's just that if there is action required from the customer stakeholder, this will alter the design a bit. If there are withdraw & deposit functions that are needed, is it going to be a simple system where these just alter the account balance, or do we need to keep transactions & be able to produce bank statements?

The design will alter because we need more functions in CAccount, and we might need a CTransaction class, a CTransactionList class, and a CStatement class. We need to think about how the customer and the Bank Manager are going to interact with the account and each other.

Look forward to your replies.
Last edited on
Project 2

Description: In this project, you will combine the experience from previous assignments and projects to create your largest program. You will also gain experience using vectors, reading and writing files, and formatting output.

Details: Write a program to simulate a simple banking system.

Your first task is to create a class called Account. This class will store a person's account ID, passcode, last name, first name, and balance.

For your second task, you will create a class called BankingSystem. This class must have at least the following functionality:

Add a new account.
Delete an existing account.
Inquire on an existing account (or all accounts).
Save accounts to a file.
Load accounts from a file.

BankingSystem must also use a private data member that is declared as follows:

vector <Account> accounts_;

Your third task will be to develop a driver program. The driver program will print some type of menu allowing the user to choose the option they want. Instead of using a BankingSystem object, you must use a pointer to a BankingSystem object with the new operator. So, in your driver program (int main()), you would write the following:

BankingSystem* myBankingSystem = new BankingSystem();

At the end of your program (end of main() before returning), you have to free this memory explicitly by writing the following:

delete myBankingSystem;

Unlike previous assignments and projects, this one is very open-ended. Besides my explicit requirements, you are free to make your own design decisions. But, remember to use good programming practices such as those pertaining to formatting, commenting, and file organization (i.e. header, implementation, driver).

Programming Tips: This project rolls everything together into one. So, it is important to know the concepts from the previous assignments and projects. It may be helpful to create one function at a time in BankingSystem and test it before proceeding. Remember from the chapter on arrays that a vector is really just a "better" array. Vector's can make life easier than arrays for tasks like searching, adding, and removing items. Another good reference you can find online is http://www.cplusplus.com/reference/stl/vector/. For adding an account, you will find the push_back() function useful. For removing an account, you will find the erase() function useful.

If you would rather not use vectors, which are recommended, they can be substituted using arrays. Due note that arrays cannot grow and shrink as a vector can, so there may be some additional complexity that may prove more difficult.

That said, here are some vector code snippets....

Similar to an array, to create a vector that will store account objects, you'll need to:

vector <Account> accounts_;

If you need more storage in your vector to hold additional account information, you can do so by dynamically creating a new position:

accounts_.push_back( bankAccount );

As with an array, you can iterate through each position of your vector by using the size() function in your for loop. In order to access an object stored in the vector, just use the same indexing method that you'd use for an array.

for( int i = 0; i < accounts_.size(); i++ )
{
bankAccount = accounts_[ i ];

...... Your Code ......
}

Basically, once you come to understand the initial syntax of using a vector, working with them is not that much different that working with an array.

Sample Output:

*** Welcome to the Banking System ***

(1) Add Account
(2) Delete Account
(3) Account Inquiry
(4) Save Accounts to File
(5) Load Accounts from File
(6) Exit

Enter selection: 1

Enter the accountID: 1
Enter the passcode: 1
Enter the first name: Yosemite
Enter the last name: Sam
Enter the starting balance: $2.45

Account added successfully.

(1) Add Account
(2) Delete Account
(3) Account Inquiry
(4) Save Accounts to File
(5) Load Accounts from File
(6) Exit

Enter selection: 1

Enter the accountID: 2
Enter the passcode: 2
Enter the first name: Bugs
Enter the last name: Bunny
Enter the starting balance: $2.50

Account added successfully.

(1) Add Account
(2) Delete Account
(3) Account Inquiry
(4) Save Accounts to File
(5) Load Accounts from File
(6) Exit

Enter selection: 1

Enter the accountID: 3
Enter the passcode: 3
Enter the first name: Daffy
Enter the last name: Duck
Enter the starting balance: $45.00

Account added successfully.

(1) Add Account
(2) Delete Account
(3) Account Inquiry
(4) Save Accounts to File
(5) Load Accounts from File
(6) Exit

Enter selection: 3

Enter the account ID (-1 for all): -1

Account ID Passcode Last Name First Name Balance
================================================================
1 1 Sam Yosemite 2.45
2 2 Bunny Bugs 2.50
������ 3 3 Duck Daffy 45.00

(1) Add Account
(2) Delete Account
(3) Account Inquiry
(4) Save Accounts to File
(5) Load Accounts from File
(6) Exit

Enter selection: 4

Enter the filename: bankaccounts.txt

File bankaccounts.txt saved successfully.

(1) Add Account
(2) Delete Account
(3) Account Inquiry
(4) Save Accounts to File
(5) Load Accounts from File
(6) Exit

Enter selection: 2

Enter the accountID: 1

Account erased.

(1) Add Account
(2) Delete Account
(3) Account Inquiry
(4) Save Accounts to File
(5) Load Accounts from File
(6) Exit

Enter selection: 2

Enter the accountID: 2

Account erased.

(1) Add Account
(2) Delete Account
(3) Account Inquiry
(4) Save Accounts to File
(5) Load Accounts from File
(6) Exit

Enter selection: 2

Enter the accountID: 3

Account erased.

(1) Add Account
(2) Delete Account
(3) Account Inquiry
(4) Save Accounts to File
(5) Load Accounts from File
(6) Exit

Enter selection: 3

Enter the account ID (-1 for all): -1

Account ID Passcode Last Name First Name Balance
================================================================

(1) Add Account
(2) Delete Account
(3) Account Inquiry
(4) Save Accounts to File
(5) Load Accounts from File
(6) Exit

Enter selection: 5

Enter the filename: bankaccounts.txt

File bankaccounts.txt loaded successfully.

(1) Add Account
(2) Delete Account
(3) Account Inquiry
(4) Save Accounts to File
(5) Load Accounts from File
(6) Exit

Enter selection: 3

Enter the account ID (-1 for all): -1

Account ID Passcode Last Name First Name Balance
================================================================
1 1 Sam Yosemite 2.45
2 2 Bunny Bugs 2.50 3 3 Duck Daffy 45.00

(1) Add Account
(2) Delete Account
(3) Account Inquiry
(4) Save Accounts to File
(5) Load Accounts from File
(6) Exit

Enter selection: 6

Bonus Challenge:

Add the ability to withdraw money from an account (5 points).
Add the ability to deposit money into an account (5 points).



Submission:

As always, make sure to include your header in each file:
/***********************
Your Name
Project 2
***********************/



Zip up the coded files and title the zip with the following format: lastname, first initial, underscore, proj2 (ie John Doe would submit DoeJ_proj2.zip)

Submit the zip file.
OK, thanks Lauren.

We were posting at the same time.

So there is no involvement from the customer stakeholder.(as per your original description of the problem.)

So ignore all that stuff about transactions etc.

What I was saying about the FindAcct still holds though.


If you have a function in CAccount that prints the details of the account, then you still won't need get functions.

I am interested to hear anyone's comments about the code I posted. I might not have had all the details right, but I hope the layout of what goes where was right.



Topic archived. No new replies allowed.
Pages: 1234