Hello, I have uploaded my code on pastebin: http://pastebin.com/r21nnvX1. Everyt
ID: 642422 • Letter: H
Question
Hello, I have uploaded my code on pastebin: http://pastebin.com/r21nnvX1. Everything in the code is working alright except for lines 86-88. The acct.depositBalance(deposit) needs to deposit money into the linked list and I cannot seem to get that to work. It formerly deposited money into an array but I cannot for the life of me convert it.
The c_bank.dat file is here: https://www.dropbox.com/s/plojy929zt84yqm/c_bank.dat?dl=0
I just need the above function to work correctly with the linked list. Any help would be greatly appreciated. It's important that any solutions please use the code that I already have linked on pastebin. Everything is working except three functions (and fix one of those, all three are extremely similar).
Explanation / Answer
#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
/***********
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
/***********
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 *** " << 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. Please enter menu 1,2,3,4,5, or 6 to end. ";
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 << " (1) Add Account ";
cout << "(2) Delete Account ";
cout << "(3) Account Inquiry ";
cout << "(4) Save Accounts to File ";
cout << "(5) Load Accounts from File ";
cout << "(6) Exit " << 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 ";
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;}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.