Created
October 13, 2017 13:49
-
-
Save JamesBremner/e32f20d8f3ad40eff1b85538743c2d0c to your computer and use it in GitHub Desktop.
Bank Accounts for Jamie S
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <string> | |
using namespace std; | |
class Account | |
{ | |
public: | |
string name; | |
bool type; | |
int balance; | |
Account( string& n, bool t ) | |
: name( n ) | |
, type( t ) | |
, balance( 0 ) | |
{ } | |
void change_balance(int n); //create a function to change an accounts balance? | |
}; | |
// Bank stores accounts | |
class Bank | |
{ | |
public: | |
vector< Account > myAccounts; | |
/// Create and add account | |
void Create( string name, bool type ) | |
{ | |
myAccounts.push_back( Account( name, type ) ); | |
} | |
// Find account with name | |
vector< Account >::iterator Find( const string& name ) | |
{ | |
for( vector< Account >::iterator act_iter = myAccount.begin(); | |
act_iter != myAccount.end(); | |
act_iter++ ) | |
{ | |
if( act_iter->name == name ) | |
return act_iter; | |
} | |
return myAccount.end(); | |
} | |
}; | |
int main() | |
{ | |
// create bank to store accounts | |
Bank theBank; | |
for( ; ; ) | |
{ | |
cout << "enter your action ( create, transaction, remove ) "; | |
std::string action, name; | |
bool type; | |
bool value; | |
vector< Account >::iterator act_iter; | |
cin >> action; | |
switch( action[0] ) | |
{ | |
case 'c': | |
cout << " enter account name and type "; | |
cin >> name >> type; | |
theBank.Create( name, type ); | |
break; | |
case 't': | |
cout << " enter account name and transaction value "; | |
cin >> name >> value; | |
act_iter = theBank.Find( name ); | |
if( act_iter == theBank.myAccounts.end() ) | |
{ | |
cout << "No account with name: " << name << endl; | |
break | |
} | |
//... | |
break; | |
case 'r': | |
//... | |
break; | |
} | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment