Have a few errors

Pages: 1234
I have added in the lines you needed to add a vector to your program. You don't need to do anything else to it.
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
/*************
Lauren Buecker 
Project 2
BankingSystem.cpp
************/
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include "Account.h"

using namespace std;


int main()
{
   // Create a vector that holds "Account's" named myAccounts
	vect<Account> myAccounts;
	Account myAccount;
	string firstName;
	string lastName;
	string passCode;
	unsigned short selection =0;	  //Menu Selection option 
	string accountNumber;
	double startingBalance;  //need to be able to do decimal numbers like 1023.57
	double balance;

cout << "Welcome to My Banking System" << endl;
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";
while (selection !=6)
            {
		switch (selection)
		{ 
		case 1:{ 
			cout << "Account Number: " ;
			cin >> accountNumber;
			myAccount.setaccountNumber(accountNumber);
			cout << "Please Enter First Name";
			cin  >> firstName;									  
			myAccount.setfirstName(firstName);
			cout << "Please Enter Last Name";
			cin >> lastName;
			myAccount.setlastName(lastName);
			cout << "Please Enter Account password";
			cin >> passCode;
			myAccount.setpsCode(passCode);
			cout << "Enter Starting Balance";
			cin >> startingBalance;
			myAccount.setstartBalance(startingBalance);
			cout << myAccount.getaccountNumber();
			// Add this account to the vector
			myAccounts.push_back(myAccount);
			}
		break;
		case 2:
			{
			   }
		break;
		case 3:
			{
			   }
			break;
		case 4:
			{
			   }
			break;
		case 5:
			{
			   }
			break;
default:{
			   cout << "Invalid selection. Please Choice another option\n";
	   }break;
	

		}
}
system ("pause");
return 0;
}


I have bolded the new additions. You can access the accounts in the vector just like you can an array (if you want the first account added, it would be myAccounts[0], 2nd account myAccounts[1], etc.). Once you get to the pop_back part, think of it as the complete opposite of push_back, instead of adding to the back, you're removing from the back, and instead of passing an object, you're returning an object.
When I have unsigned short selection =0 it does not complete the program it just runs invalid selection.

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
/*************
Lauren Buecker 
Project 2
BankingSystem.cpp
************/
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include "Account.h"
using namespace std;
int main()
{
	vect<Account> myAccounts;
	Account myAccount;
	string myAccounts;
	string firstName;
	string lastName;
	string passCode;
	unsigned short selection =0;	  //Menu Selection option 
	string accountNumber;
	double startingBalance;  //need to be able to do decimal numbers like 1023.57
	double balance;
	vector <Account> accounts_;
cout << "Welcome to My Banking System" << endl;
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";
cin >> selection;
while (selection !=6)
            {
		switch (selection)
		{ 
		case 1:{ 
			cout << "Account Number: " ;
			cin >> accountNumber;
			myAccount.setaccountNumber(accountNumber);
			cout << "Please Enter First Name ";
			cin  >> firstName;									  
			myAccount.setfirstName(firstName);
			cout << "Please Enter Last Name ";
			cin >> lastName;
			myAccount.setlastName(lastName);
			cout << "Please Enter Account password ";
			cin >> passCode;
			myAccount.setpsCode(passCode);
			cout << "Enter Starting Balance ";
			cin >> startingBalance;
			myAccount.setstartBalance(startingBalance);
			myAccounts.push_back(myAccount);
			cout << "Account Successfully Created";
			   }						
		break;
		case 2:
			{
				cout << "Please Enter Account Number of Account to be Deleted: \n";
				cin >> accountNumber;
			
			    
			}
		break;
		case 3:
			{
			for (unsigned int i = 0; i < myAccounts.size(); i ++)
   cout << "Account " << accounts_[i].accountNumber << ": " << accounts_[i].myAccounts;   
			}
			break;
		case 4:
			{
			   }
			break;
		case 5:
			{
			   }
			break;
default:{
			   cout << "Invalid selection. Please Choose another option\n";
	   }break;
	

		}
		cout << "Please Enter a New Selection";
		cin >> selection;
}
}


Account.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
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
#include <iostream>
#include <string>
#include <vector>
using namespace std;

class Account 
	
{	
private:
	string _accountNumber;
	string _passCode;
	string _lastName;
	string _firstName;
	double _balance;
	double _startBalance;
	vector <Account> accounts_;
public:
	string myAccounts;
	string lastName;
	string firstName;
	double balance;
	string accountNumber;
	double startBalance;
	int accounts_;
	void setfirstName( string firstName )	  
	{ 
		_firstName=firstName;
	}
	void setlastName ( string lastName)
	{ 
		_lastName=lastName;
	}
	void setaccountNumber (	 string accountNumber )
	{
		_accountNumber=accountNumber;
	}
	void setpsCode ( string passCode )
	{
		_passCode=passCode;
	}	
	void setstartBalance( double startBalance )
	{
			_startBalance=startBalance;
		}
string getfirstName ()
{			
	return _firstName;	   
}
string getlastName()
{
	return _lastName;
}
 string getaccountNumber ()
 { 
	 return _accountNumber;
 }
 string getpassCode ()
 {
	return _passCode;
 }
 double getstartBalance ()
 {
	 return _startBalance;
 }
vector <string> userAccounts;
vector <Account> myAccounts;
};


1>c:\users\lauren\documents\visual studio 2010\projects\banksystem\banksystem\account.h(65): error C2371: 'Account::myAccounts' : redefinition; different basic types
1>c:\users\lauren\documents\visual studio 2010\projects\banksystem\banksystem\bankingsystem.cpp(14): error C2065: 'vect' : undeclared identifier
1>c:\users\lauren\documents\visual studio 2010\projects\banksystem\banksystem\bankingsystem.cpp(14): error C2275: 'Account' : illegal use of this type as an expression
1> c:\users\lauren\documents\visual studio 2010\projects\banksystem\banksystem\account.h(8) : see declaration of 'Account'
1>c:\users\lauren\documents\visual studio 2010\projects\banksystem\banksystem\bankingsystem.cpp(14): error C2065: 'myAccounts' : undeclared identifier
1>c:\users\lauren\documents\visual studio 2010\projects\banksystem\banksystem\bankingsystem.cpp(53): error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::push_back' : cannot convert parameter 1 from 'Account' to 'char'
Last edited on
When I have unsigned short selection =0 it does not complete the program it just runs invalid selection.


You need to ask for a selection with cin. Or hard code it to 1 for now. At the moment it is set to zero so that means it goes to the default part of the switch.

Not sure whether you had removed these, or not. They are in the header file.
1
2
3
4
5
6
string firstName;
	string lastName;
	string passCode;
string accountNumber;
	double startingBalance;  //need to be able to do decimal numbers like 1023.57
	double balance;
Looking over the code, I didn't realize how much work there was to be done on this. I have a feeling you've been struggling with C++ for at least a few weeks now, if not months, and are doing what you can just to get by. I'll give you some pointers, show you your code, cleaned up, and add in comments to explain why I did what I did. I'll reply back as soon as possible. And I don't want you to take credit for it without understanding what changed and why.

You might get an A on this program, but your instructor will know it's not your own work, trust me. And even if you happen to fool them, your grades will continue to reflect your own work.
We were posting at the same time:

Here what I mean:


Account.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//#include <iostream> //not needed for this file
#include <string>
//#include <vector>  //not needed for this file
using namespace std; 

class Account 
	
{	
private:
	string accountNumber;
	string passCode;
	string lastName;
	string firstName;
	double balance;
	double startBalance;
	
public:
	
	void setfirstName( string strName )	  
	{ 
		firstName=strName;
	}
	void setlastName ( string strName)
	{ 
		lastName=strName;
	}
	void setaccountNumber (	 string strAccount )
	{
		accountNumber=strAccount;
	}
	void setpsCode ( string strCode )
	{
		passCode=strCode;
	}	
	void setstartBalance( double dblBalance )
	{
			startBalance=dblBalance;
	}


string getfirstName ()
{			
	return firstName;	   
}
string getlastName()
{
	return lastName;
}
 string getaccountNumber ()
 { 
	 return accountNumber;
 }
 string getpassCode ()
 {
	return passCode;
 }
 double getstartBalance ()
 {
	 return startBalance;
 }

};



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
/*************
Lauren Buecker 
Project 2
BankingSystem.cpp
************/
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include "Account.h"
using namespace std;
int main()
{
	vect<Account> myAccounts;
	Account myAccount;
	
	unsigned short selection =1;	  //Menu Selection option  //hard coded for now
	
	//vector <Account> accounts_; //no need for this, that's what MyAccounts is for

cout << "Welcome to My Banking System" << endl;   //put all this into ShowMenu function
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";

cin >> selection;

while (selection !=6)
            {
		switch (selection)
		{ 
		case 1:{ 
			cout << "Account Number: " ;
			cin >> accountNumber;
			myAccount.setaccountNumber(accountNumber);
			cout << "Please Enter First Name ";
			cin  >> firstName;									  
			myAccount.setfirstName(firstName);
			cout << "Please Enter Last Name ";
			cin >> lastName;
			myAccount.setlastName(lastName);
			cout << "Please Enter Account password ";
			cin >> passCode;
			myAccount.setpsCode(passCode);
			cout << "Enter Starting Balance ";
			cin >> startingBalance;
			myAccount.setstartBalance(startingBalance);

			myAccounts.push_back(myAccount);

			cout << "Account Successfully Created";
			   }						
		break;
		case 2:
			{
				cout << "Please Enter Account Number of Account to be Deleted: \n";
				cin >> accountNumber;
			
			    
			}
		break;
		case 3:   //this option needs to call a PrintAcct function just to be tidy
			{
			for (unsigned int i = 0; i < myAccounts.size(); i ++)  {
                               cout << "Account:  " << myAccounts[i].getaccountNumber << endl; 
                               cout << "Balance:  " << myAccounts[i]. << endl; //need a getBalance function
                                                                                                         //in the header file
                         }  
		}
			break;
		case 4:
			{
			   }
			break;
		case 5:
			{
			   }
			break;
default:{
			   cout << "Invalid selection. Please Choose another option\n";
	   }break;
	

		}
		cout << "Please Enter a New Selection"; //need a while loop around the whole thing to
                                                                               // accomplish this
		cin >> selection;
}
}


See how I have changed it to call your functions, rather than alter the variables directly. This goes back to what i was saying about the public & private functions, in my earlier post.

Also, you should create the Account.cpp file, so you don't have code in the header file
What I meant about being tidy:

Instead of having 10 lines of code in a case statement, put that code into a function.

So case 1: would call the function AddAccount. The function would be declared in Account.h and defined in Account.cpp. The same applies to the ShowMenu function and the rest of the case statements.

That way your switch statement won't be 5 pages long, once completed.

Hope this helps
We're apparently stealing each other's ideas -.-

Anyways, here is my reformatted versions, except I made the changes instead =/
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
/* start program file */
// Formatted entire code using Astyle
/*************
Lauren Buecker
Project 2
BankingSystem.cpp
************/
// removed duplicate #includes
#include <iostream>
#include <iomanip>
#include <vector>
/* start header file */
#include <string>
using namespace std;

class Account {
   private:
      // _accountNumber is a number, but can start with a 0
      string _accountNumber;
      // a passCode can have 0s starting at the beginning
      string _passCode;
      string _lastName;
      string _firstName;
      double _balance;
      double _startBalance;
      // Don't need to store multiple accounts in one account
      // removed vector
   public:
      // You don't have a constructor for your class, and don't need one
      //   but it is highly suggested.
      // You don't need to declare the parameters here
      // they're declared in the functions
      // removed public variables
      void setfirstName(string firstName) {
         _firstName = firstName;
      }
      void setlastName(string lastName) {
         _lastName = lastName;
      }
      void setaccountNumber(string accountNumber) {
         _accountNumber = accountNumber;
      }
      void setpsCode(string passCode) {
         _passCode = passCode;
      }
      void setstartBalance(double startBalance) {
         _startBalance = startBalance;
      }
      string getfirstName() {
         return _firstName;
      }
      string getlastName() {
         return _lastName;
      }
      string getaccountNumber() {
         return _accountNumber;
      }
      string getpassCode() {
         return _passCode;
      }
      double getstartBalance() {
         return _startBalance;
      }
      // Don't need vectors here
      // removed vectors
};
/* End header file */

/* Start program file */
// removed the using namespace since it was already declared in the header file
int main() {
   // create a vector to easily access all accounts
   // Changed vector name to reflect yours
   vector<Account> accounts_;
   // create an account variable used to add the accounts to the vector
   Account myAccount;
   // What is this for?
   // removed myAccounts as string
   string firstName;
   string lastName;
   string passCode;
   unsigned short selection = 0;   //Menu Selection option
   string accountNumber;
   double startingBalance;  //need to be able to do decimal numbers like 1023.57
   double balance;
   // Already created a vector to hold accounts.
   // Moved while loop here so you can see the menu each time
   while (selection != 6) {
      cout << "Welcome to My Banking System" << endl;
      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";
      cin >> selection;
      switch (selection) {
         case 1: {
               // Fill in account information
               cout << "Account Number: " ;
               cin >> accountNumber;
               myAccount.setaccountNumber(accountNumber);
               cout << "Please Enter First Name ";
               cin  >> firstName;
               myAccount.setfirstName(firstName);
               cout << "Please Enter Last Name ";
               cin >> lastName;
               myAccount.setlastName(lastName);
               cout << "Please Enter Account password ";
               cin >> passCode;
               myAccount.setpsCode(passCode);
               cout << "Enter Starting Balance ";
               cin >> startingBalance;
               myAccount.setstartBalance(startingBalance);
               // changed vector name to match
               accounts_.push_back(myAccount);
               cout << "Account Successfully Created";
            }
            break;
         case 2: {
               cout << "Please Enter Account Number of Account to be Deleted: \n";
               cin >> accountNumber;
               // You will need to search through the vector like in case 3:
               //   to find the account number that exactly matches accountNumber
               // Once found, you will need to set the "popped" back account
               //   at that index.
            }
            break;
         case 3: {
               // Changed vector name to match
               for (unsigned int i = 0; i < accounts_.size(); i ++)
                  cout << "Account " << accounts_[i].getaccountNumber() << ": " << accounts_[i].getstartBalance();
            }
            break;
         case 4: {
            }
            break;
         case 5: {
            }
            break;
         // Added case 6 since if entered it would still display invalid selection
         case 6: {
            }
            break;
         default: {
               cout << "Invalid selection. Please Choose another option\n";
            }
            break;
      }
      // No longer need this, replays menu until 6 is entered
   }
}
Last edited on
1
2
// Doesn't need to be a string, unless I missed something
   string accountNumber;


I suggested it be a string because we are not doing maths on it.

A real world program would draw new acct numbers from a predetermined list.

You make acct number an unsigned int or long, but then you would have to check it was in range. New acct number could be last acct number + 10 say.

Any way, for now that's not a big problem, let the user put in anything for the acct number string. Concentrate on getting other things done.
in the header file what does this mean? startBalance=dblBalance;?
1
2
3
4
5
		}
		cout << "Please Enter a New Selection"; //need a while loop around the whole thing to
                             // accomplish this
		cin >> selection;
}

If i did not have this statement in there, how will i be able to select another statement?
Last edited on
Hi Lauren,

in the header file what does this mean? startBalance=dblBalance;?


I changed the name of the arguments in the function definitions, mainly to avoid having

startBalance=_startBalance

The name of an argument variable can be anything, I put dbl at the front to say that the variable is of type double. It is the same idea for the other variables I renamed in the set functions.

If i did not have this statement in there, how will i be able to select another statement?


My bad, the statements are inside the while loop, so that is fine.

How are you going ? Have you made the Account.cpp file yet?
I have made it but have not linked anything yet I had to work this mornin. when i get home i will do my best and upload what i have so far. i wanted some clarification when i deleted the strings from main it did not like the variables
i wanted some clarification when i deleted the strings from main it did not like the variables


this is because the variables are now private. So the best thing to do is have a CreateAcct function, the declaration in the Account.h header file and the code in Account.cpp. That way the function will have access to the private variables. Then the case 1: will call the CreateAcct function via an Account object.

The same applies with all the other cases.

All this is what I was saying earlier.

The idea behind having a class is to encapsulate everything into that class, with minimal stuff in main().

The things that go in main() are:

Create the object.
Function calls via the object.

HTH
New 4 files of my program

Accounts.cpp(main)
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
/*************
Lauren Buecker 
Project 2
Accounts.cpp
************/
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include "Account.h"
#include "BankingSystem.h"
void addAccount(vector<Account> &accounts);
void deleteAccount(vector<Account> &accounts);
int main()
{
	string accountNumber;
	unsigned short selection =0;	  //Menu Selection option 
	vector <Account> accounts_;


    BankingSystem* myBankingSystem = new BankingSystem(); 
	
cout << "Welcome to My Banking System" << endl;
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";
cin >> selection;
while (selection !=6)
            {
		switch (selection)
		{ 
		case 1:{
			addAccount(accounts_);
			   }						
		break;
		case 2:
			{
			deleteAccount(accounts_);			    
			}
		break;
		case 3:
			{
   
					}
			break;
		case 4:
			{
			   }
			break;
		case 5:
			{
			   }
			break;
default:{
			   cout << "Invalid selection. Please Choose another option\n";
	   }break;
	

		}
		cout << "Please Enter a New Selection";
		cin >> selection;
}


    delete myBankingSystem; 

}

Account.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
/*************
Lauren Buecker
Project 2
Account.cpp
************/
#include <iostream>
#include <vector>
#include <string>
#include "Account.h"
using namespace std;

void Account::setfirstName( string strName )
{ 
_firstName=strName;
}
void Account::setlastName ( string strName)
{ 
_lastName=strName;
}
void Account::setaccountNumber ( string strAccount )
{
_accountNumber=strAccount;
}
void Account::setpsCode ( string strCode )
{
_passCode=strCode;
}	
void Account::setstartBalance( double dblBalance )
{
_startingBalance=dblBalance;
}


string Account::getfirstName ()
{	
return _firstName;	   
}
string Account::getlastName()
{
return _lastName;
}
string Account::getaccountNumber ()
{ 
return _accountNumber;
}
string Account::getpassCode ()
{
return _passCode;
}
double Account::getstartBalance ()
{
return _startingBalance;
}
void addAccount(vector<Account> &accounts)
	{ 
// Create a new account
Account newAccount;

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

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";
}
void deleteAccount(vector<Account> &accounts)
{
	Account deleteAccount;
	string accountNumber;
	string firstName;
	string lastName;
    cout << "Please Enter Account Number to be Deleted: ";
	cin >> accountNumber;
	for (int i=0; i < accounts.size(); i++)
{
if (accounts[i].getaccountNumber() == accountNumber)
{
accounts.erase(accounts.begin()+i);
break;
}
}
	cout << "Account Deleted Successfully\n";
}

Account.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
/***********
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:

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


string getfirstName ();
string getlastName();
string getaccountNumber ();
string getpassCode ();
double getstartBalance ();

};

BankingSystem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*************
Lauren Buecker 
Project 2
BankingSystem.cpp
************/
#include <iostream>
#include "Account.h"
#include "BankingSystem.h"
using namespace std;

BankingSystem myBankingSystem();
{
cout << "Welcome to My Banking System" << endl;
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";
cin >> selection;
}

BankingSystem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/***********
Lauren Buecker 
Project 2
BankingSystem.h
************/
#include <iostream>
#include <string>

class BankingSystem
{
private:
public:
 BankingSystem();
};



1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppClean.targets(74,5): warning : The process cannot access the file 'C:\PROGRAMDATA\BPROTECTORFORWINDOWS\2.1.419.7\BPROTECT.SETTINGS' because it is being used by another process.
1> BankingSystem.cpp
1>c:\users\lauren\documents\visual studio 2010\projects\banksystem\banksystem\bankingsystem.cpp(12): error C2447: '{' : missing function header (old-style formal list?)
1> Accounts.cpp
1> Account.cpp
1>c:\users\lauren\documents\visual studio 2010\projects\banksystem\banksystem\account.cpp(91): warning C4018: '<' : signed/unsigned mismatch




Ok, making some progress.

I would have 3 files:

1 Account.h
2 Account.cpp #include Account.h
3 BankingSystem - Main is in this file #include Account.h

Now that you have all your functions in the class, you can get rid of all those set & get functions.

To think about why that is, consider this work flow:

1: Create the private functions you need
2: Create the private variables the functions need. If the variable is something only that function will need it can be local to that function ( that is, declared inside it)
3: Decide which functions should be public, that is can be called by the object in main say
4: If there are any variables that need to be public, provide a public function that returns the private variable.

Remember, a private variable can be accessed by any function in the class, that is why we don't need all those get & set functions.

The code you have in your current BankingSystem.cpp is the ShowMenu function - this should go in the same file as main().

I am guessing that this project implements a simple banking system in that Deposit or withdraw functions only alter the account balance, the transactions themselves aren't stored. If you do want to store transactions you will need some more classes.

So my reason it goes in the main application file and not in either of the Account files, is that the menu applies to the whole system and not just to one class.

Now the next improvement, would be to have a ProcessMenu function (also in the main application file). This would contain the switch statement that calls the functions to carry out each menu option.

Then you could have something like this in main():

1
2
3
4
5
6
7
8
9
10
11
12
13
14
while (selection !=6) {
      ShowMenu();
      cout << "Please Enter a New Selection";
		cin >> selection;
      ProcessMenu(selection);

}

You can see how the above snippet is easy to understand as a unit, rather than say 200 lines of code.

This should be in main(), not in Account.cpp

[code]// Create a new account
Account newAccount;


The idea is to create the object in main, then use it to call the objects functions.

[/code]

before main()

1
2
3
4
5
6
7
//////////////////////////////////////
//Function declarations
/////////////////////////////////////

void  ShowMenu();
void ProcessMenu(unsigned short selection);


After main()

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
void  ShowMenu() {  //this function is easy to understand as a unit
    cout << "Welcome to My Banking System" << endl;
    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" << endl;  //endl same as \n but it flushes the buffer
}

void ProcessMenu(unsigned short selection) { //this is easy as well, the work is carried out by
                                                                         //the class functions  

     switch (selection)
     { 
		case 1:
			//call the CreateAcct function  - better name than AddAccount 
                        NewAccount.CreateAcct()						
		        break;
		case 2:
			//call the DeleteAcct function - better name
                        NewAccount.DeleteAcct()   
		        break;
		case 3:
			break;
		case 4:
			break;
		case 5:
			break;
		case 6:
                         cout << "Exiting program"
                         exit(0); //exits the whole program
			break;
                 default:
			   cout << "Invalid selection. Please Choose another option\n";
                         break;
          }
}


Now I really wish you wouldn't name your variables with underscores.

1
2
3
4
5
6
7
private:
string _accountNumber;
string _passCode;
string _lastName;
string _firstName;
double _balance;
double _startingBalance;


The thing to do, is name your member variables with m_ at the start and capitalise the first letter of each word in the variable name like this:

1
2
3
4
5
6
7
private:
string m_AccountNumber;
string m_PassCode;
string m_LastName;
string m_FirstName;
double m_Balance;
double m_StartingBalance;


That way, if you do have functions that take arguments, the arguments won't be confused with the member variables.

I think the reason you are doing it is because you want to have a similar name for function arguments. The thing is you don't need arguments for these functions - the variables are already there in the class.

There is no need to declare these functions, they should be in the class.

1
2
3
void addAccount(vector<Account> &accounts);
void deleteAccount(vector<Account> &accounts);
int main()




The other confusion is, there are 2 things: One, the account object (NewAcct) say, and Two, a group of (vector) account objects. The vector of account objects could be in main(), then you need logic to handle dealing with a particular account. I would recommend getting every thing to work for 1 acct, then extend it to handle multiple accts with a vector or list. Another way would be to have another class that stored the list of accts - I might have to think about how that would work.

Ok, I hope that this has sorted out the framework for the app, & you can understand how things work with classes.

Good luck, I look forward to helping out some more.





Come on, read the words from the compiler. It's all there.

c:\users\lauren\documents\visual studio 2010\projects\banksystem\banksystem\bankingsystem.cpp(12):

Hmm, this seems to indicate that there's a problem around line 12 of the file bankingsystem.cpp - let's take a look at that.

1
2
3
BankingSystem myBankingSystem();
{
cout << "Welcome to My Banking System" << endl

Well, there's a function definition starting, let's just have a look - hey, what's that semi-colon doing there? That shouldn't be there. Lucky I read the error message or it might have taken me ages to find that.

>c:\users\lauren\documents\visual studio 2010\projects\banksystem\banksystem\account.cpp(91):

Hmm, this seems to indicate that there's a problem around line 91 of the file account.cpp - let's take a look at that. It says it's just a warning, but it's worth checking. It says:
warning C4018: '<' : signed/unsigned mismatch

Well, let's see the line of code in question:
for (int i=0; i < accounts.size(); i++)

Oh yes, there is the '<' symbol. I am comparing a signed integer, i, to an unsigned integer returned by accounts.size(). It it warnig me that comparing a signed to an unsigned is risky. I could fix that by making i an unsigned int.
Last edited on
Can I have two different classes in the account.h file. I do have to have a bankingsystem class.
Last edited on
Yes, your banking system class can be in the same header file as the account class. Header files really just organize your code for reusability. Since the banking system relies on the account class, they can go together, or they can go in separate files and the banking system can include the accounts header file by itself.
Here is a loop I reread the instructions for the project. I need a driver program the only problem with that is the book has a two sentence explanation with no examples so I do not get it.
I believe by driver program they mean you need your main .cpp file (typically called main.cpp). The idea behind it is that it calls your other classes (banksystem and accounts) and does the work based on a per need system. Essentially, the banksystem and accounts files will be reusable regardless of which "driver program" you use.

I'm not sure if that makes sense, but a better way to look at it would be this: Let's say in a month you come back to this same program. You're to reuse the accounts and banksystem header files and create a new "driver program" that acts as a different bank. You'll no long use this one (or you're at least use a modified version of this program) and need to use something different. You won't need to change the account/banksystem files since they were designed for resuability. Your needs for the physical program might have changed though (you are supposed to display the information in a different matter, you're supposed to be able to link multiple accounts to one person, or you simple have a different numbering scheme for account numbers).

Hope this clarifies what a driver program is.
OK, managed to reply. helios pointed out how to refresh bypassing the cache - use Ctrl-Shift-R in firefox.

Lauren, did you see the thread I started (about your thread). "Msg to Lauren Buecker"

Edit:
http://www.cplusplus.com/forum/beginner/76624/#msg411919
Last edited on
Pages: 1234