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