Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- enum type_acc {customer, staff};
- class Account {
- public:
- std::string username;
- std::string password;
- double balance;
- type_acc account_type;
- bool operator==(const Account& rhs);
- };
- class BankInterface {
- public:
- static Account loggedinaccount;
- static std::vector<Account> registered_accounts;
- static void LoginMenu();
- static void RegisterAccount();
- static void Login();
- static void MainMenu();
- static void DisplayBalance();
- static void MakeWithdrawal();
- static void MakeDeposit();
- static type_acc AccountType(std::string uc);
- };
- class StaffInterface {
- public:
- static void StaffMenu();
- static void CustomerBalance();
- static void AccountShutdown();
- };
- Account BankInterface::loggedinaccount;
- std::vector<Account> BankInterface::registered_accounts;
- // AccountSystem.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include "pch.h"
- #include "AccountSystem.h"
- void BankInterface::LoginMenu() {
- std::cout << "Please select an option: n 1. Register a new account. n 2. Login to account.n";
- std::string user_choice;
- std::cin >> user_choice;
- if (user_choice == "1") {
- RegisterAccount();
- }
- else if (user_choice == "2") {
- Login();
- }
- else {
- std::cout << "We did not recognise your input, please try again...n";
- LoginMenu();
- }
- }
- type_acc BankInterface::AccountType(std::string uc) {
- if (uc == "y") {
- return staff;
- }
- else if (uc == "n") {
- return customer;
- }
- else {
- std::cout << "We did not recognise your input, please try again.n";
- std::string user_choice;
- std::cin >> user_choice;
- return AccountType(user_choice);
- }
- }
- void BankInterface::RegisterAccount() {
- Account new_account;
- std::cout << "Please enter the desired username of your account: n";
- std::cin >> new_account.username;
- std::cout << "Please enter your desired password for your account.n";
- std::cin >> new_account.password;
- std::cout << "Please enter your initial balance for your account.n";
- std::cin >> new_account.balance;
- std::cout << "Are you a member of staff? y/n?n";
- std::string user_choice;
- std::cin >> user_choice;
- new_account.account_type = BankInterface::AccountType(user_choice);
- registered_accounts.push_back(new_account);
- std::cout << "Account created.n";
- for (auto &account : registered_accounts) {
- std::cout << account.username << "n";
- }
- LoginMenu();
- }
- void BankInterface::Login() {
- std::cout << "Please enter your username.n";
- std::string username;
- std::cin >> username;
- for (auto &account : registered_accounts) {
- if (account.username == username) {
- std::cout << "Please enter your password.n";
- std::string password;
- std::cin >> password;
- if (account.password == password) {
- loggedinaccount = account;
- if (loggedinaccount.account_type == customer) {
- MainMenu();
- }
- else {
- StaffInterface::StaffMenu();
- }
- }
- }
- }
- std::cout << "That username does not exist in our system.n";
- Login();
- }
- void BankInterface::MainMenu() {
- std::cout << " 1. Check account balance.n 2. Make a withdrawal.n 3. Make a deposit. n";
- int user_choice = 0;
- std::cin >> user_choice;
- switch (user_choice) {
- case 1:
- DisplayBalance();
- break;
- case 2:
- MakeWithdrawal();
- break;
- case 3:
- MakeDeposit();
- break;
- default:
- std::cout << "We did not understand your input, please try again.";
- MainMenu();
- break;
- }
- }
- void BankInterface::DisplayBalance() {
- std::cout << "Your balance is: " << loggedinaccount.balance << "n";
- MainMenu();
- }
- void BankInterface::MakeWithdrawal() {
- std::cout << "Please enter the amount you wish to withdraw: n";
- double amt;
- std::cin >> amt;
- if (amt > loggedinaccount.balance) {
- std::cout << "You do not have this much money in your account, please input a feasible sum to withdraw. n";
- MakeWithdrawal();
- }
- else if (amt <= 0) {
- std::cout << "You cannot withdraw a negative amount, or zero, dollars, please try again.n";
- MakeWithdrawal();
- }
- else {
- loggedinaccount.balance -= amt;
- std::cout << "Money withdrawn, new balance: " << loggedinaccount.balance << "n";
- MainMenu();
- }
- }
- void BankInterface::MakeDeposit() {
- std::cout << "How much money do you wish to deposit? n";
- double amt;
- std::cin >> amt;
- if (amt <= 0) {
- std::cout << "You cannot deposit a negative amount of, or zero, dollars. Please try again.n";
- MakeDeposit();
- }
- else {
- loggedinaccount.balance += amt;
- std::cout << "Your new balance is: " << loggedinaccount.balance << "n";
- MainMenu();
- }
- }
- void StaffInterface::StaffMenu() {
- std::cout << "1. View customer's balance.n2. Shut down customer's account.n";
- int staff_choice = 0;
- std::cin >> staff_choice;
- switch (staff_choice) {
- case 1:
- CustomerBalance();
- break;
- case 2:
- AccountShutdown();
- break;
- default:
- std::cout << "We did not understand your input, please try again.";
- StaffMenu();
- break;
- }
- }
- void StaffInterface::CustomerBalance() {
- std::cout << "Enter the customer's username to view their balance: n";
- std::string cust_name;
- std::cin >> cust_name;
- for (auto &account : BankInterface::registered_accounts) {
- if (cust_name == account.username) {
- std::cout << account.balance << "n";
- StaffMenu();
- }
- else {
- std::cout << "We could not detect an account with that username, please try again.n";
- CustomerBalance();
- }
- }
- }
- bool Account::operator==(const Account& rhs) {
- if (username == rhs.username) {
- return true;
- }
- else {
- return false;
- }
- }
- void StaffInterface::AccountShutdown() {
- std::cout << "Enter the customer's username of the account you want to delete.n";
- std::string username_del;
- std::cin >> username_del;
- for (auto &account : BankInterface::registered_accounts) {
- if (username_del == account.username) {
- std::cout << "Account detected, are you sure you wish to delete this account? y/n n";
- std::string confirmation;
- bool ans = false;
- while (ans != true) {
- std::cin >> confirmation;
- if (confirmation == "y") {
- auto pos = find(BankInterface::registered_accounts.begin(), BankInterface::registered_accounts.end(), account);
- BankInterface::registered_accounts.erase(pos);
- std::cout << "Account deleted, returning to main staff menu. n";
- ans = true;
- StaffMenu();
- }
- else if (confirmation == "n") {
- ans = true;
- StaffMenu();
- }
- else {
- std::cout << "We did not recognise that option, please try again.n";
- }
- }
- }
- }
- }
- int main()
- {
- BankInterface::LoginMenu();
- }
Add Comment
Please, Sign In to add comment