an epic.

Okay, so this is a lot, i know. Thank you * million, in advance! I'm going to post all three parts of the code (a header and two .cpp). I'm writing a banking code for school and I will appeal to the expertise and good will of this forum to help me with some specific questions or general ironing out while I'm at work today and then come home to toil ever more.
In addition to the following questions if anyone can teach me a classy way to compartmentalize this monster and test it function by function that would be great! Specific questions: 1. In the additional Account function implementations (Get/Set Passcode, firstName, etc.) was I wrong to phrase them as Account::SetPasscode as opposed to something like passcode::SetPasscode.? Can I have one of them as an example if I have done this incorrectly?
2. In the DeleteAccount section of bankingSystem.cpp, was I wrong to call BankingSystem.FindAccount instead of something like b.FindAccount? Were the arguments in parenthesis incorrect?
3. How do I output the contents of this array? Do I need to give some sort of this element through this element instruction. I'd like all the contents of the array so I just went with cout << a[0],
I didn't see it declared otherwise so I assume that the Account array is just called a. Feel free to debunk that also if that seems like stupidity.
I took out the header to allow myself to publish this thing!
I'll post it in comments to allow y'all to see how this thing is working but the
header was provided and should be the least eronious of this whole mess!
Thanks for looking!


[/code]

bankingSystemDriver.cpp (partial code)

*/

#include <iostream>
#include "bankingSystem.h"

//Print a menu of options to the user.

void PrintMenu()
{

std::cout << "\n(1) Add Account\n";
std::cout << "(2) Delete Account\n";
std::cout << "(3) Print Accounts\n";
std::cout << "(4) Deposit\n";
std::cout << "(5) Withdrawal\n";
std::cout << "(6) Exit\n";
std::cout << "\nEnter selection: ";

}

//Start your main program loop here.

int main()
{

//All class functions are called through a BankingSystem object.

BankingSystem b;
int selection;



std::cout << "\n*** Welcome to the Banking System ***\n";
PrintMenu();
std::cin >> selection;

switch ( selection )
{

case 1:
b.CreateAccount();
break;

case 2:
b.DeleteAccount();
break;

case 3:
b.PrintAccounts();
break;

case 4:
b.Deposit();
break;

case 5:
b.Withdrawal();
break;

case 6:
break;

}







//*** TO DO: Add a loop that prints a menu and
//processes the user's selection.

return 0;

}
[code]
bankingSystem.cpp (partial code)

*/

#ifndef _BANKINGSYSTEM_CPP
#define _BANKINGSYSTEM_CPP

#include <iostream>
#include <string>
#include <cstdlib>
#include "bankingSystem.h"

void Account::SetAccountID(unsigned accountID)
{

accountID_ = accountID;

}

unsigned Account::GetAccountID()
{

return accountID_;

}

//*** TO DO: Add the rest of your Account function implementations here. *NS* I'm doing void Account instead of Void
//Passcode because I know that all of these are supposed to go under one element of an array. Not sure of the necessity of that?
//Same for the following Account function implementations.
void Account::SetPasscode(unsigned passcode)
{
passcode_ = passcode;
}

unsigned Account::GetPasscode()
{
return passcode_;
}

void Account::SetFirstName(const std::string& firstName)
{
firstName_ = firstName;
}

unsigned Account::GetFirstName()
{
return firstName_;
}

void Account::SetLastName(const std::string& lastName)
{
lastName_ = lastName;
}

unsigned Account::GetLastName()
{
return lastname_;
}

void Account::SetBalance(double balance)
{
balance_= balance;
}

unsigned Account::GetBalance()
{
return balance_;
}

//Default constructor just initializes
//current number of accounts to 0;

BankingSystem::BankingSystem() : current_num_accounts_(0)
{}

//Find an account by accountID.
//Return the array index if found, current_num_accounts_ otherwise.

size_t BankingSystem::FindAccount(size_t accountID)
{

for (size_t i = 0; i < current_num_accounts_; ++i)
if (accounts_[i].GetAccountID() == accountID)
return i;

return current_num_accounts_;

}

//Match the passcode at a given index with the given passcode.
//Return true for a match, false otherwise.

bool BankingSystem::MatchPasscode(unsigned passcode, size_t index)
{

return accounts_[index].GetPasscode() == passcode;

}

//Add an account.

void BankingSystem::CreateAccount()
{

Account account;
unsigned accountID;
unsigned passcode;
std::string firstName;
std::string lastName;
double balance;

//Get the account ID and make sure it doesn't already exist.

std::cout << "\nEnter the account ID: ";
std::cin >> accountID;

if (FindAccount(accountID) != current_num_accounts_)
{

std::cout << "\nAccount already exists!\n";

return;
}


account.SetAccountID(accountID);
std::cout << "\nEnter the passcode: ";
account.SetPasscode(passcode);
std::cout << "\nEnter the first name: ";
account.SetFirstName(firstName);
std::cout << "\nEnter the last name: ";
account.SetLastName(lastName);
std::cout << "\nEnter the starting balance: ";
account.SetBalance(balance);

//Set this info into your Account object.
//Add the account to your array and increment the count of accounts.

accounts_[current_num_accounts_] = account;
++current_num_accounts_;

std::cout << "\nAccount added successfully!\n";

}

//Delete an account.
void BankingSystem::DeleteAccount()
{

size_t index;
unsigned accountID;
unsigned passcode;

//*** TO DO: Get the account ID and verify it exists.
std::cout << "/nEnter the account ID: ";
BankingSystem.FindAccount(size_t accountID);/**-NS-maybe instead of BankingSystem.F... I should be implementing b.FindAccount...?
or maybe the (size-t accountID) is the wrong argument?*/

//*** TO DO: Get the passcode and verify it matches.
std::cout << "/nEnter the passcode: ";
BankingSystem.MatchPasscode(unsigned passcode, size_t index)/**-NS-same concerns as with above BankingSystem.FindAccount**/


//Remove the account. First, shift everything over to the left.

for (size_t i = index; i < current_num_accounts_ - 1; ++i)
accounts_[i] = accounts_[i + 1];

//Then, decrement the count of accounts.

--current_num_accounts_;

std::cout << "\nAccount erased!\n";

}

//*** TO DO: Add your remaining BankingSystem function implementations here.

void BankingSystem::PrintAccounts()
//NS- There is a standard cout Accounts, Name, Balance, etc. Here but firstly, I have no clue how to even go about printing out
//the contents of this array. I assume it's called "a" because I don't remember declaring it otherwise or seeing it declared
//otherwise. I can output the standard cout header and adjust the alignment after figuring out how to even print this array.

{
std::cout << a[0];
}


#endif
[code]
header, if it's helpful!
[code]
bankingSystem.h

*/

#ifndef _BANKINGSYSTEM_H
#define _BANKINGSYSTEM_H

#include <iostream>
#include <string>
#include <cstdlib>

//Class Account holds an account ID, passcode,
//first name, last name, and balance. All variables
//are kept private. Access/changes are made through
//public set and get functions.

class Account
{

public:

void SetAccountID(unsigned accountID);
unsigned GetAccountID();

void SetPasscode(unsigned passcode);
unsigned GetPasscode();

void SetFirstName(const std::string& firstName);
std::string GetFirstName();

void SetLastName(const std::string& lastName);
std::string GetLastName();

void SetBalance(double balance);
double GetBalance();

private:

unsigned accountID_;
unsigned passcode_;
std::string firstName_;
std::string lastName_;
double balance_;

};

//Assume a max of 100 accounts.

const size_t MAX_NUM_ACCOUNTS = 100;

//Class BankingSystem uses an array of Account.
//You can create, delete, print, deposit, and withdraw.

class BankingSystem
{

public:

BankingSystem();

void CreateAccount();
void DeleteAccount();
void PrintAccounts();
void Deposit();
void Withdraw();

private:

Account accounts_[MAX_NUM_ACCOUNTS];
size_t current_num_accounts_;

//Use these auxiliary functions if you want.
//See bankingSystem.cpp for more info.

size_t FindAccount(unsigned accountID);
bool MatchPasscode(unsigned passcode, size_t index);

};

#endif
Can you repost the code a little cleaner by using the scource code format.
Topic archived. No new replies allowed.