#include <iostream>
#include <string>
#include <vector>
#include <cctype>
usingnamespace std;
class bankAccounts{
public:
bankAccounts()
{
}
void listOptions(){
cout<< "Choose an option from the menu."<<endl;
cout<< "1 - View Balance"<<endl;
cout<< "2 - Deposit"<<endl;
cout<< "3 - Withdrawl"<<endl;
cout<< "4 - View Transactions"<<endl;
cout<< "5 - Create New Account"<<endl;
cout<< "6 - Exit Session"<<endl;
}
void bankOptions(){
}
void accountNumGenerator(){
int accNum = rand() % 999999;
cout<<"You are officially a valued member at Towson Bank! "<<accNum<< " is your account number."<<endl;
}
};
int main(){
int goBack;
static vector<string>accountTransactions;
floatstatic accBalance = 0;
float addMoney;
float subtractMoney;
bankAccounts app;
string firstName;
string lastName;
string bankCreation;
string newAcc;
int amountOfAccs[10];
int menuOptions;
int count = 0;
cout<<"Hello what is your first name?\n";
cin>>firstName;
cout<<"Hello what is your last name?\n";
cin>>lastName;
cout<<"Hello "<<firstName<<" "<<lastName<<"! Do you want to sign up for an account at Towson Bank?"<<endl;
cout<<"Type in Yes if you want to continue with the proccess or No if you want to end this session."<<endl;
cin>>bankCreation;
while(count <= 10){
if(bankCreation == "yes" || bankCreation == "Yes"){
app.accountNumGenerator();
app.listOptions();
cin>>menuOptions;
switch(menuOptions){
case 1:
cout<<"This is your account balance: \n"<<"$"<<accBalance<<endl;
cout<<"Press 1 to go back or 0 to end the session"<<endl;
cin>>goBack;
if(goBack == 0){
break;
}
elseif(goBack == 1){
app.listOptions();
app.bankOptions();
}
break;
case 2:
cout<<"How much do you want to depoist?"<<endl;
cin>>addMoney;
accBalance = accBalance + addMoney;
accountTransactions.push_back("Deposited $" + to_string(addMoney));
cout<<"Press 1 to go back or 0 to end the session"<<endl;
cin>>goBack;
if(goBack == 0){
break;
}
elseif(goBack == 1){
app.listOptions();
app.bankOptions();
}
elseif(goBack != 1 || goBack != 2){
cout<<"Invalid Entry, we will be ending this session."<<endl;
exit(1);
}
break;
case 3:
cout<<"How much do you want to withdrawl?"<<endl;
cin>>subtractMoney;
accBalance = accBalance - subtractMoney;
accountTransactions.push_back("Withdrew $" + to_string(subtractMoney));
cout<<"Press 1 to go back or 0 to end the session"<<endl;
cin>>goBack;
if(goBack == 0){
break;
}
elseif(goBack == 1){
app.listOptions();
app.bankOptions();
}
break;
break;
case 4:
cout<<"These are your account transactions."<<endl;
cout<<accountTransactions[0]<<endl;
for(int i = 0; i < accountTransactions.size(); i++){
cout<<accountTransactions[i]<< "\n";
}
cout<<"Press 1 to go back or 0 to end the session"<<endl;
cin>>goBack;
if(goBack == 0){
break;
}
elseif(goBack == 1){
app.listOptions();
app.bankOptions();
}
break;
case 5:
cout<<"New acc?"<<endl;
cin>>newAcc;
if(newAcc == "yes"){
cout<<"ok"<<endl;
}
break;
case 6:
// cin>>amountOfAcc[0];
cout<<"Thank you for being a valued member at Towson Bank!"<<endl;
exit(1);
default:
cout<<"Not a valid option, please choose again!"<<endl;
cout<< "Choose an option from the menu."<<endl;
cout<< "1 - View Balance"<<endl;
cout<< "2 - Deposit"<<endl;
cout<< "3 - Withdrawl"<<endl;
cout<< "4 - View Transactions"<<endl;
cout<< "5 - Exit Session"<<endl;
cin>>menuOptions;
app.listOptions();
app.bankOptions();
break;
}
}
elseif(bankCreation == "No" || bankCreation == "no"){
cout<<"Thank you for your time, we will be ending this session now."<<endl;
exit(1);
}
elseif(bankCreation != "No" || bankCreation != "no" || bankCreation != "Yes" || bankCreation != "yes"){
cout<<"This is not a valid entry, please put in a valid response."<<endl;
cout<<"Hello "<<firstName<<" "<<lastName<<"! Do you want to sign up for an account at Towson Bank?"<<endl;
cout<<"Type in Yes if you want to continue with the proccess or No if you want to end this session."<<endl;
cin>>bankCreation;
}
count++;
}
return 0;
}
Hey, I'm sorry I'm new to this so I don't know how to use proper code tags and my problem is I want to have multiple bankAccounts when I want to create them so if I chose to I can have another account with its own data and I can choose to go back and forth between the two without have its data shared.
Hey, I'm sorry I'm new to this so I don't know how to use proper code tags and my problem is I want to have multiple bankAccounts when I want to create them so if I chose to I can have another account with its own data and I can choose to go back and forth between the two without have its data shared.
This sounds very much like you want to implement a class BankAccount (note: no "...s" in the name!) that represents a single bank account. You can then have multipleinstances (objects) of that class, so each object has its own separate state. That is how you solve these things in object-oriented programming :-D
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
class BankAccount
{
// Write your code for a *single* (specific) bank account here !!!
public:
BankAccount(void)
{
m_value = 0;
}
void add(constint amount)
{
m_value += amount;
}
protected:
int m_value;
};
1 2 3 4 5 6 7 8 9 10 11 12
int main()
{
// Create instances
BankAccount bankAccount1; // <-- create bank account #1
BankAccount bankAccount2; // <-- create bank account #2
...
BankAccount bankAccountN; // <-- create bank account #N
// Now do something with your instances
bankAccount1.add(13); // <-- this accesses bank account #1
bankAccount42.add(666); // <-- this accesses bank account #42
}
Surely, when the number of bank accounts becomes huge, better use an array!
1 2 3 4 5 6 7 8 9 10 11 12
int main()
{
// Create instances
BankAccount *bankAccounts = new BankAccount[99991];
// Do something with your instances
bankAccounts[0].add(13); // <-- this accesses bank account #1
bankAccounts[41].add(666); // <-- this accesses bank account #42
// Clean up to avoid a memory leak!
delete[] bankAccounts;
}