Have a few errors

Pages: 1234
Just wanted to say that I'm in this same class, taking it online as well and I can attest to the fact that we have gotten almost zero direction with this stuff all semester.

Good luck Lauren, we're all gonna need it!

I've been hunting and basically using trial/error and cut/paste to scrap my way through the rest of the assignments...I can't believe this instructor actually thinks he taught us anything...or that we might even know how to do a program this complicated. I doubt it will do much good but I wasn't to happy with this class and I let them know in the course evaluation.
Depending on the schools policy, if enough students report badly on the teacher, they can offer the class free of charge again (most turn that down) with a different instructor, or they might even refund the tuition (very few schools offer that and the ones that do rarely have to act upon it).

Online programming classes are some of the hardest ones. You really need a person to interact with. Online videos and typed instructions are no where close to what a class actually should be.
I have software programming friends who have been helping me they just not always online
We don't even get online video! It's basically, "here's a powerpoint with the vocabulary which won't actually help you at all with the programming and the assignment is due in a week..."
Zq9 pm me and i can help a bit
PM sent...thanks Lauren
You guys should both read the tutorials on this site. They're well worth it.
But there is no tutorial on.vectors
You're right, there isn't, but here is a few links for vectors from the reference section here:

Overview: http://www.cplusplus.com/reference/stl/vector/
Using push_back(): http://www.cplusplus.com/reference/stl/vector/push_back/
Using the [] operator (just like an array): http://www.cplusplus.com/reference/stl/vector/operator[]/

Aside from those, if there is still some confusion, we can try to alleviate as much as possible.
We already have the private data member vector<Account>accounts_ so we have to make that public and in my code we already have all the setters and getters the contents is.going to be the contents of the.vector we are all stuck on.how to display contents of the.vector
A simple for loop will help display it (granted that it has been populated correctly:
1
2
3
4
5
6
7
8
for (int i = 0; i < accounts_.size(); i ++) {
   // Display the account number
   cout << accounts_[i].getaccountNumber() << " ";
   // Display the balance
   cout << accounts_[i].getstartBalance() << " ";
   // Display the name (last, first)
   cout << accounts_[i].getlastName() << ", " << accounts_[i].getfirstName() << endl;
}


That works, but you'll get a warning about comparing a signed int to an unsigned int. If you're not worried about it, enjoy. But if you're worried about it, the proper way is to do this for the for loop instead:
1
2
3
for (unsigned i = 0; i < accounts_.size(); i ++) {
   // The rest of the code is the same
}


Edit: All that accounts_[i] does in this situation is return the account at the index of i. Like I said, think of it just like how an array works, it might help you understand it better.
Last edited on
Okay i will upload my current code when.i get home in a bit u are a very big.help i am sure to the few from the class
Lauren, it's generally much easier to help you learn to code if you ask us about a specific problem you're having.
If you've read the tutorials you will be able to understand the reference on vectors on this site relatively easily, and should have a good idea of how to use them.
@BlackSheep
The tutorial doesn't cover the vectors though, and for someone that doesn't know the site navigation might have a hard time finding the information on the vectors. I also don't believe the references were directed towards beginners, but towards programmers with at least some knowledge on the subject or knowledge on a related subject.
Updated code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/***********
Lauren Buecker
Project 2
Main.cpp
**********/
#include <iostream>
#include <string>
#include <vector>
#include <ostream>
#include "BankingSystem.h"
int displayMenu(); // function prototype
void addAccount(vector<Account> &accounts);
void deleteAccount(vector<Account> &accounts);
void listAccounts(vector<Account> &accounts);
int selection;
int main()
{
	int menu;
	// display welcome message
    cout << "*** Welcome to the Banking System ***\n" << endl;

    // variable declaration
    // allocate storage for object of type BankingSystem

    BankingSystem* myBankingSystem = new BankingSystem(); 
	 menu = displayMenu();
	 while (selection !=6)
            {
		switch (selection)
		{ 
		case 1:{
			myBankingSystem>addAccount(accounts_);
			   }						
		break;
		case 2:
			{
			myBankingSystem>deleteAccount(accounts_);			    
			}
		break;
		case 3:
			{
				myBankingSystem>listAccounts(accounts_);
			}
			break;
		case 4:
			{
			   }
			break;
		case 5:
			{
			   }
			break;
default:{
			   std::cout << "Invalid selection. Please Choose another option\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

	}
int displayMenu()
{
    int selection; // variable declaration
    
    // display menu

std::cout << "Welcome to My Banking System" << endl;
std::cout << "(1) Add account\n"; 
std::cout << "(2) Delete Account\n";
std::cout << "(3) Account Inquiry\n";
std::cout << "(4) Save Accounts to File\n";
std::cout << "(5) Load Accounts from File\n";
std::cout << "(6) Exit" << endl;  //endl same as \n but it flushes the buffer
  std::cout << "Enter selection: ";
    cin >> selection;

    return selection; // return the selection
}

void addAccount(vector<Account> &accounts)
{ 
// Create a new account
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";
}
void deleteAccount(vector<Account> &accounts)
{
	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;
}
void listAccounts(vector<Account> &accounts);
{
	string getaccountBumber;
	double getstartBalance;
	string getlastName;

	for (unsigned i = 0; i < accounts_.size(); i ++) {
    // Display the account number
   cout << accounts_[i].getaccountNumber() << " ";
   // Display the balance
   cout << accounts_[i].getstartBalance() << " ";
   // Display the name (last, first)
   cout << accounts_[i].getlastName() << ", " << accounts_[i].getfirstName() << endl;
}
}
}

The errors to this.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1>c:\users\lauren\documents\visual studio 2010\projects\bankingsystem\bankingsystem\main.cpp(32): error C2065: 'accounts_' : undeclared identifier
1>c:\users\lauren\documents\visual studio 2010\projects\bankingsystem\bankingsystem\main.cpp(37): error C2065: 'accounts_' : undeclared identifier
1>c:\users\lauren\documents\visual studio 2010\projects\bankingsystem\bankingsystem\main.cpp(42): error C2065: 'accounts_' : undeclared identifier
1>c:\users\lauren\documents\visual studio 2010\projects\bankingsystem\bankingsystem\main.cpp(120): warning C4018: '<' : signed/unsigned mismatch
1>c:\users\lauren\documents\visual studio 2010\projects\bankingsystem\bankingsystem\main.cpp(132): error C2065: 'accounts_' : undeclared identifier
1>c:\users\lauren\documents\visual studio 2010\projects\bankingsystem\bankingsystem\main.cpp(132): error C2228: left of '.size' must have class/struct/union
1>          type is ''unknown-type''
1>c:\users\lauren\documents\visual studio 2010\projects\bankingsystem\bankingsystem\main.cpp(134): error C2065: 'accounts_' : undeclared identifier
1>c:\users\lauren\documents\visual studio 2010\projects\bankingsystem\bankingsystem\main.cpp(134): error C2228: left of '.getaccountNumber' must have class/struct/union
1>c:\users\lauren\documents\visual studio 2010\projects\bankingsystem\bankingsystem\main.cpp(136): error C2065: 'accounts_' : undeclared identifier
1>c:\users\lauren\documents\visual studio 2010\projects\bankingsystem\bankingsystem\main.cpp(136): error C2228: left of '.getstartBalance' must have class/struct/union
1>c:\users\lauren\documents\visual studio 2010\projects\bankingsystem\bankingsystem\main.cpp(138): error C2065: 'accounts_' : undeclared identifier
1>c:\users\lauren\documents\visual studio 2010\projects\bankingsystem\bankingsystem\main.cpp(138): error C2228: left of '.getlastName' must have class/struct/union
1>c:\users\lauren\documents\visual studio 2010\projects\bankingsystem\bankingsystem\main.cpp(138): error C2065: 'accounts_' : undeclared identifier
1>c:\users\lauren\documents\visual studio 2010\projects\bankingsystem\bankingsystem\main.cpp(138): error C2228: left of '.getfirstName' must have class/struct/union
1>c:\users\lauren\documents\visual studio 2010\projects\bankingsystem\bankingsystem\main.cpp(142): fatal error C1075: end of file found before the left brace '{' at 'c:\users\lauren\documents\visual studio 2010\projects\bankingsystem\bankingsystem\main.cpp(115)' was matched



Phew, there needs to be some better direction here. First, the banking system class should be set up to accept an account as a parameter. Here is an example of how that should look:
1
2
3
4
void BankingSystem::AddAccount(Account newAccount) {
   // We simply need to add the new account to our vector
   accounts_.push_back(newAccount);
}


That means that we can change the local function addAccount to return an account:
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
// It might make more sense if this function was called Create Account
Account addAccount() { 
   // Create a new account
   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);
   cout << "Account Successfully Created\n";
   // We return the account so we can add it to the banking system's vector
   return newAccount;
}


And then simply in the switch control, we can make it a little easier:
1
2
3
4
5
6
7
8
9
10
11
12
13
// Not sure why you're creating a BankingSystem pointer...
   BankingSystem* myBankingSystem = new BankingSystem(); 
   menu = displayMenu();
   while (selection !=6)
   {
      switch (selection)
      { 
         case 1:
            // If using a pointer, you need to use the -> operator
            // Remember, our local function addAccount returns an Account object
            // So we can just add that directly to our bankingsystem
            myBankingSystem->AddAccount(addAccount());
            break;


That is just one part that should make a little more sense to you. If you have any more questions, please ask.

Also, why are you doing this?
BankingSystem* myBankingSystem = new BankingSystem();

It's going to make things seem a lot different to you (if they don't already).
Last edited on
BankingSystem*myBankingSystem = new BankingSystem is required for this project.
Alright, then just remember instead of using the . operator like you normally would to call functions, you just need the -> operator.

Do the small little improvements and see if the code make a little more sense to you.
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?

Lauren wrote:

We already have the private data member vector<Account>accounts_ so we have to make that public and in my code we already have all the setters and getters the contents is.going to be the contents of the.vector we are all stuck on.how to display contents of the.vector


OK, I think the main problem so far is the design of the classes. I have mentioned a number of things in my PM to you, about how to design a class. What I will do, is post my code (An outline only) of how I think the classes should look. Hopefully won't be too long, before I get this together.

I am doing this because, is it easy to become confused when you all probably haven't been given sufficient examples in your learning so far. So what you need is a good example, so that you all can see how things work.

Edit: It is a bit of a problem, of when various people are on line to help. I am in Melbourne, Australia (GMT + 10) while my wild guess is that some of you are in Europe somewhere.
Last edited on
Pages: 1234