#include <bits/stdc++.h>
using namespace std;
vector<string> menu_items= {
"New", "Withdrawal", "Deposit", "Check Balance", "Display All", "Fund Transfer", "Exit"
};
const int EXIT_CODE = menu_items.size();
typedef struct {
int id;
string name;
float balance;
} MyAccount;
map<int, MyAccount> accounts;
void add();
void withdraw(){};
void deposite(){};
void checkBalance();
void displayAll();
void fundTransfer();
void loadDataTable();
int ran = 0;
int menu() {
if (ran == 0) {
loadDataTable();
++ran;
}
int op = 0;
int items = menu_items.size();
cout << "<----- MENU ----->\n";
for (int i = 0; i < items; i++) {
cout << '\t' << i+1 << ". " << menu_items[i] << '\n';
}
printf("Enter your choice (1-%d): ", items);
cin >> op;
if ( !(op >= 1 && op <= items) ) {
cout << "Invalid Choice! Please select again!\n";
menu();
}
return op;
}
int main() {
int op = menu();
if (op == EXIT_CODE) {
cout << "<----- Program Exit ----->\n";
return 0;
}
cout << "\n\n\t<----- " << menu_items[op-1] << " ----->\n";
switch (op) {
case 1: add(); break;
case 2: withdraw(); break;
case 3: deposite(); break;
case 4: checkBalance(); break;
case 5: displayAll(); break;
}
main();
return 0;
}
void add() {
MyAccount ac;
while(true) {
cout << "Enter your account ID: ";
cin >> ac.id;
if (accounts.find(ac.id) == accounts.end()) break;
cout << "This account already exists! Enter a different ID.\n";
}
cout << "Enter your name: ";
cin >> ac.name;
cout << "Enter your deposite amount: ";
cin >> ac.balance;
accounts[ac.id] = ac;
cout << "\n\t\tAccount creation successful!\n";
return;
}
void checkBalance() {
cout << "Enter your account ID: ";
int id;
cin >> id;
if (accounts.find(id) == accounts.end()) {
cout << "Account not found!\n\n";
return;
}
cout << "\n\n\tOwner name: " << accounts[id].name << '\n';
cout << "\tBalance: " << accounts[id].balance << '\n';
cout << "\n\n";
}
void displayAll() {
for (auto ac: accounts) {
cout << "\n\n\tAccount ID: " << ac.second.id << '\n';
cout << "\tAccount Owner Name: " << ac.second.name << '\n';
cout << "\tBalance: " << ac.second.balance << '\n';
}
cout << "\n\n";
}
void fundTransfer() {
// validify sender and receiver accounts.
}
void loadDataTable() {
ifstream file("accounts.txt");
while(!file.eof()) {
MyAccount ac;
file >> ac.id >> ac.name >> ac.balance;
accounts[ac.id] = ac;
}
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}