Have a few errors

Pages: 1234
I am starting my last assignment which is a banking system project. I have just one function down and 5 more functions to go. But i have a few problems
Bankingsystem.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
/*************
Lauren Buecker 
Project 2
BankingSystem.cpp
************/
#include <iostream>
#include <iomanip>
#include <string>
#include "Account.h"
;using namespace std;

int main()
{
	char firstName;
	char lastName;
	int selection =0;	   
	int accountNumber;
	int passCode;
	int startingBalance;
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:{ 
			Account myAccount;
			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 << Account::getaccountNumber();
			}
		
			   
		case 2:
			{
			   }
		case 3:
			{
			   }
		case 4:
			{
			   }
		case 5:
			{
			   }
default:{
			   cout << "Invalid selection. Please Choice another option\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
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
#include <iostream>
#include <string>
#include <vector>
using namespace std;

class Account 
	
{	
private:
	int _accountNumber;
	int _passCode;
	char _lastName;
	char _firstName;
	int _balance;
	int _startBalance;
public:
	Account();
	Account(const int *ptr);
	char lastName;
	char firstName;
	int balance;
	int accountNumber;
	int startBalance;
	void setfirstName( char firstName )	  
	{ 
		_firstName=firstName;
	}
	void setlastName ( char lastName)
	{ 
		_lastName=lastName;
	}
	void setaccountNumber (	 int accountNumber )
	{
		_accountNumber=accountNumber;
	}
	void setpsCode ( int passCode )
	{
		_passCode=passCode;
}	
	void setstartBalance( int startBalance )
	{
			_startBalance=startBalance;
		}
char getfirstName ()
{			
	return _firstName;	   
}
char getlastName()
{
	return _lastName;
}
 int getaccountNumber ()
 { 
	 return _accountNumber;
 }
 int getpassCode ()
 {
	return _passCode;
 }
 int getstartBalance ()
 {
	 return _startBalance;
 }
}

These are my errors, i have also been getting this too
1
2
3
4
Error	2	error C2352: 'Account::getaccountNumber' : illegal call of non-static member function	c:\users\lauren\documents\visual studio 2010\projects\banksystem\banksystem\bankingsystem.cpp	48	1	banksystem
	3	IntelliSense: a nonstatic member reference must be relative to a specific object	c:\users\lauren\documents\visual studio 2010\projects\banksystem\banksystem\bankingsystem.cpp	48	12	banksystem

Error	2	error C2143: syntax error : missing ';' before 'using' 


I just wanted to test to see if it stores the value right before i continue.
Hi Lauren,

change this

cout << Account::getaccountNumber();

to this

cout <<myAccount.getaccountNumber();

I wouldn't have put this in the switch statement.

Account myAccount;


For this bit, the first ; shouldn't be needed, not sure why it's giving you an error.
;using namespace std;

A trivial thing, This could be a ShwMenu function

1
2
3
4
5
6
7
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";


HTH
case statements are missing break.
I am just trying to get it to work and return a value so i can make sure that works and then on to the next thing. I have been get these two errors the entire time

Error 1 error LNK2019: unresolved external symbol "public: __thiscall Account::Account(void)" (??0Account@@QAE@XZ) referenced in function _main C:\Users\Lauren\Documents\Visual Studio 2010\Projects\banksystem\banksystem\BankingSystem.obj banksystem

Error 2 error LNK1120: 1 unresolved externals C:\Users\Lauren\Documents\Visual Studio 2010\Projects\banksystem\Debug\banksystem.exe 1 1 banksystem

Error 1 error C2143: syntax error : missing ';' before 'using' c:\users\lauren\documents\visual studio 2010\projects\banksystem\banksystem\bankingsystem.cpp 11 1 banksystem
Last edited on
Lauren,

Error 1 is fixed by this, as I said earlier:

cout <<myAccount.getaccountNumber();

You can't call

Account::getaccountNumber();

from main() ,It has to be through an object (myAccount)

Error 2 is probably because of Error 1.

Hope this Helps


it has been fixed

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()
{
	char firstName;
	char lastName;
	int selection =0;	   
	int accountNumber;
	int passCode;
	int startingBalance;
	int balance;
	Account myAccount;
	unsigned int i;
	vector <int> first(accountNumber);
	vector <int> second(passCode);
	vector <char> third(firstName) ;
	vector <char> fourth (lastName);
	vector <int> fifth(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();
			}
		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;
}


1>------ Build started: Project: banksystem, Configuration: Debug Win32 ------
1> BankingSystem.cpp
1>c:\users\lauren\documents\visual studio 2010\projects\banksystem\banksystem\bankingsystem.cpp(11): error C2143: syntax error : missing ';' before 'using'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

i am new to vectors but saw it on this site think i did it wrong but do not know.

Hi Lauren,



In Account.h, Is this a problem? Could be the cause of the missing ; error.

1
2
3
4
5
6
7
8
	void setpsCode ( int passCode )
	{
		_passCode=passCode;
}	//this was meant to be the end of the class, but it is the end of setpsCode
	void setstartBalance( int startBalance )
	{
			_startBalance=startBalance;
		}


Also, don't put code into header files.

1
2
3
4
void setfirstName( char firstName )	  
	{ 
		_firstName=firstName;
	}


Header files are for declaring variables and functions. Implementation code goes in the .cpp file. The problem is you don't have a Account.cpp file. Your IDE should create the .h and .cpp files automatically when you create a new class. My guess is you created the files manually. There should be a tool bar button that runs a new class wizard - this is the easiest way of doing it.

Hope this is easier.
what code?
Ok, this should be different


1
2
3
4
5
vector <int> first(accountNumber);
	vector <int> second(passCode);
	vector <char> third(firstName) ;
	vector <char> fourth (lastName);
	vector <int> fifth(balance);



balance should be a float or double, the others could be strings.

vector<char> is really just a string.
accountNumber and passcode should be a strings, because you aren't doing any maths on it ( like a phone number)

something like this:

1
2
3
4
5
6
7
        string firstName;
	string lastName;
	unsigned short selection =0;	  //Menu Selection option 
	string accountNumber;
	string passCode;
	double startingBalance;  //need to be able to do decimal numbers like 1023.57
	double balance;


So far this code will deal with one account - that's fine for now, get everything working, then extend it to handle multiple accounts. For this you need either a vector or a list of account objects.

so i only need int if i am doing math?

changed all of that in both

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

class Account 
	
{	
private:
	string _accountNumber;
	string _passCode;
	string _lastName;
	string _firstName;
	double _balance;
	double _startBalance;
public:
	string lastName;
	string firstName;
	double balance;
	string accountNumber;
	double startBalance;
	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;
 }
}


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

using namespace std;


int main()
{
	
	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();
			}
		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;
}

1>------ Build started: Project: banksystem, Configuration: Debug Win32 ------
1> BankingSystem.cpp
1>c:\users\lauren\documents\visual studio 2010\projects\banksystem\banksystem\bankingsystem.cpp(12): error C2143: syntax error : missing ';' before 'using'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Last edited on
OK

1
2
3
4
5
6
7
8
9
10
11
12
13
private:
	string _accountNumber;
	string _passCode;
	string _lastName;
	string _firstName;
	double _balance;
	double _startBalance;
public:
	string lastName;
	string firstName;
	double balance;
	string accountNumber;
	double startBalance;


Now you have you variables twice (though with slightly different names), and you also have them again in main().
You really only need them once as private variables - that is the purpose of have get and set functions.

The idea is to have all the variables and functions private (they can be accessed directly by the functions in the account class. Then you have public get functions to access the variables (only the ones you need) from the object (myAccount). The same applies to set functions.

Obviously you are not going to have public getPassCode or setPassCode functions. The same applies for the other variables.

Think about the real life situation. You wouldn't want anyone to go to your bank and be able to change the account name, number, balance, pass code etc for your bank account. Say you wish to change your passcode. So the bank verifies that it is you ( they have a procedure) the change is done via a ChangePassCode function not by directly changing the PassCode variable. Same thing with account balance, this is done via Deposit and Withdrawal functions,with appropriate verification.

I hope this explains some of the ideas better.

I know it's a bit of a pain, but I would seriously recommend crating the Account.cpp file.

Just looks like you're missing that pesky semicolon at the end of the Account class in your Account.h file.
Okay those pesky errors are gone. now i need to start vector <Account> accounts_;
It needs account number, first name, last name and balance in that vector. Can you guys help me. The book for the class has two paragraphs for it and basically explains it is a better array.
A vector really is a better array. It can dynamically resize when you add something to it (arrays have a fixed size) and can contain and object you want (Accounts in your case).

To create a vector, you first need to include the header file:
#include <vector>

You need to create a vector next:
1
2
3
// Template for a vector is:
// std::vector<type> vectorName;
std::vector<Account> myAccounts;


Next you need to put some values in the vector:
1
2
3
4
5
Account userAccount;
// Fill in the account members...
// ...
// Put the user Account in the vector
myAccounts.push_back(userAccount);

** All that pushing back does is resizes the vector and pushes the object (userAccount) to the very end of the vector

Then you need to access the vector:
1
2
3
4
5
6
7
8
9
10
// We can loop through the vector with a for loop
for (unsigned int i = 0; i < myAccounts.size(); i ++)
   std::cout << "Account " << myAccounts[i].accountNumber << ": " << myAccounts[i].name;

// The vector is accessible using the [] operator
//    and can resize dynamically.
// The vector is more powerful than the array
//    but can cause issues when it starts getting large.
// Remember that the Account at myAccounts[i] is just like
//    an Account by itself. 
Last edited on
ok so what i should put in the vector is

1
2
3
4
5
6
Account myAccounts;
        vector <int> first(accountNumber);
	vector <char> third(firstName) ;
	vector <char> fourth (lastName);
	vector <int> fifth(balance);
accounts_.push_back(myAccounts);

because the vectors name has to be vector <Account> accounts_;

Once I can get the vector up I need to be able to delete an account with the push_back() function.
Last edited on
Lauren,

The Account class should be like this, as I mentioned before, and the implementation as Volatile Pulse has described.


1
2
3
4
5
6
7
private:
	string accountNumber;
	string passCode;
	string lastName;
	string firstName;
	double balance;
	double startBalance;


I have removed the leading underscores, I prefer not to name a variable that way.
TheIdeasMan

I have not changed the private data members.

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


What you need to do is create an account (you do this in case one). Once you have created an account, you can then add that account to your vector (refer to my previous post on how to set up the vector) using the push_back() method. This will add that account to your vector. I believe when you delete an account, you actually want to pop_back() that account. This leads you to one of the first limitations of vectors.

Vectors are very similar to arrays, but also have a lot of the same limitations. Vectors allow you to add objects and remove them, but only from the back (note the push_back() function). This means you can only remove the very last account in the vector. Let's say you have a vector of 10 accounts, you can only remove the tenth account. The way to work around this is to receive the item returned from the pop_back method and set it equal to the account that you actually wanted to remove. Again, it's a clumsy workaround, but it does work.
Lauren,

I am confused why you want to do this:

1
2
3
4
5
6
Account myAccounts;
        vector <int> first(accountNumber);
	vector <char> third(firstName) ;
	vector <char> fourth (lastName);
	vector <int> fifth(balance);
accounts_.push_back(myAccounts);


Once you have defined what an account is (In account.h) then just do what Volatile has said:

1
2
3
// Template for a vector is:
// std::vector<type> vectorName;
std::vector<Account> myAccounts;


Once I can get the vector up I need to be able to delete an account with the push_back() function.


The push_back function puts objects into the vector, it doesn't remove them. Google "C++ vector example" and read about C++ algorithms. Algorithms do things to containers like vectors. push_back adds an object to the end of your vector.
Next you need to put some values in the vector:

Account userAccount;
// Fill in the account members...
// ...
// Put the user Account in the vector
myAccounts.push_back(userAccount);

Can you please clarify on this. Can I put it in the .cpp file around the first case?
Pages: 1234