Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Institution ID : Your name
- Course: “CIS2513”
- Term: “Fall 2016”
- Vector list of Bank Accounts [created during the online session]
- A Savings Account
- A Line of Credit Account
- A Checking Account
- Current Balance (which may be positive or negative)
- A vector list of transactions
- Transaction Type
- Credit
- Debit
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <cstring>
- #include <stdlib.h>
- using namespace std;
- class BankAccount {
- public:
- BankAccount();
- BankAccount(string usrName, string usrPassword);
- void CreateAccount(string userName, string userPassword);
- bool LoginInfo(string userName, string userPassword);
- void DepositMoney();
- void WithdrawMoney();
- void RequestBalance();
- static double savingBalance = 0.00;
- static double checkingBalance = 500.00;
- static double accountBalance = 0.0;
- double creditLine = 0.00;
- double newBalance = 0.00;
- double depositAmount, withdrawalAmount;
- private:
- string usrName;
- string usrPassword;
- };
- BankAccount::BankAccount() {
- usrName = "";
- usrPassword = "";
- return;
- }
- BankAccount::BankAccount(string user_Name, string user_Password) {
- usrName = user_Name;
- usrPassword = user_Password;
- return;
- }
- void BankAccount::CreateAccount(string userName, string userPassword){
- ofstream outFS;
- outFS.open("bankAccounts.txt");
- outFS << userName << endl;
- outFS << userPassword << endl;
- outFS.close();
- return;
- }
- bool BankAccount::LoginInfo(string userName, string userPassword){
- ifstream inFS;
- inFS.open("bankAccounts.txt");
- string name;
- string password;
- if (inFS.is_open())
- {
- while (inFS >> name)
- {
- inFS >> password;
- if (userName == name && userPassword == password){
- return true;
- }
- }
- }
- inFS.close();
- return false;
- }
- void BankAccount::BankAccount::DepositMoney(){
- char usrOption;
- char depositVal[50];
- int length;
- cout << "Amount of deposit: ";
- cin >> depositVal;
- length = strlen(depositVal);
- if(depositVal[0] == '$')
- {
- for(int i = 0; i < length; i++) {
- depositVal[i] = depositVal[i + 1];
- }
- }
- depositAmount = atof(depositVal);
- newBalance = accountBalance + depositAmount;
- accountBalance = newBalance;
- return;
- }
- void BankAccount::BankAccount::WithdrawMoney(){
- char usrOption;
- char withdrawalVal[50];
- int length;
- cout << "Amount of withdrawal: ";
- cin >> withdrawalVal;
- length = strlen(withdrawalVal);
- if(withdrawalVal[0] == '$')
- {
- for(int i = 0; i < length; i++) {
- withdrawalVal[i] = withdrawalVal[i + 1];
- }
- }
- withdrawalAmount = atof(withdrawalVal);
- newBalance = accountBalance - withdrawalAmount;
- accountBalance = newBalance;
- return;
- }
- void BankAccount::BankAccount::RequestBalance() {
- if (newBalance < 0)
- {
- creditLine = newBalance;
- savingBalance = 0.0;
- checkingBalance = 0.0;
- }
- else
- {
- creditLine = 0.0;
- }
- savingBalance = newBalance - checkingBalance;
- cout << "Your SAVINGS balance is: $" << savingBalance << endl;
- cout << "Your CHECKING balance is: $" << checkingBalance << endl;
- cout << "Your LINE OF CREDIT balance is: $" << creditLine << endl;
- cout << "Your TOTAL Balance is: $" << newBalance << endl;
- return;
- }
- int main() {
- string usrName;
- string usrPassword;
- char usrOption;
- cout << "Welcome to our ATM Machine" << endl;
- cout << endl;
- while (true){
- cout << "Please select an option:" << endl;
- cout << endl;
- cout << "l -> Login" << endl;
- cout << "c -> Create New Account" << endl;
- cout << "q -> Quit" << endl;
- cout << endl;
- cin >> usrOption;
- cout << endl;
- switch (usrOption){
- case 'l':
- case 'L':
- cout << "Please enter your user id: ";
- cin >> usrName;
- cout << "Please enter your password: ";
- cin >> usrPassword;
- if (LoginInfo(usrName, usrPassword)){
- cout << endl;
- cout << "Access Granted - " << usrName << endl;
- cout << endl;
- while (true)
- {
- cout << "d -> Deposit Money" << endl;
- cout << "w -> Withdraw Money" << endl;
- cout << "r -> Request Balance" << endl;
- cout << "x -> Exit" << endl;
- cout << endl;
- cin >> usrOption;
- cout << endl;
- switch (usrOption){
- case 'd':
- case 'D':
- DepositMoney();
- break;
- case 'w':
- case 'W':
- WithdrawMoney();
- break;
- case 'r':
- case 'R':
- RequestBalance();
- break;
- case 'x':
- case 'X':
- cout << "Thanks for banking with us, " << usrName << "!" << endl;
- exit(1);
- break;
- default:
- cout << "Invalid option. Pick again." << endl;
- break;
- }
- cout << endl;
- }
- }
- else {
- cout << endl;
- cout << "******** LOGIN FAILED! ********" << endl;
- }
- break;
- case 'c':
- case 'C':
- cout << "Please enter your user name: ";
- cin >> usrName;
- cout << "Please enter your password: ";
- cin >> usrPassword;
- CreateAccount(usrName, usrPassword);
- cout << endl;
- cout << "Thank You! Your account has been created!" << endl;
- break;
- case 'q':
- case 'Q':
- exit(1);
- break;
- default:
- cout << "Invalid option. Pick again." << endl;
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement