Created
April 14, 2020 00:26
-
-
Save vivekkumar198/fa09a04a0110a0c19ea077dd0ebb910d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #ifndef Bank_h | |
| #define Bank_h | |
| #include <iostream> | |
| #include "BankAccount.h" | |
| #include <string> | |
| class Bank:public Bankaccount | |
| { | |
| private: | |
| string name; | |
| string address; | |
| string workingHours; | |
| vector<Bankaccount> accounts; // vector is being used instead of an array because size is not given. | |
| Bankaccount object1; | |
| public: | |
| // Bankaccount object is declared here to call the menu in Bankaccount. | |
| void fillVector(){ // fill vector is used to make a vector of objects of accounts. | |
| string firstName; | |
| string lastName; | |
| string SSN; | |
| cout << "Enter the first name of the account holder: "; | |
| cin >> firstName; | |
| cout << "Enter the last name of the account holder: "; | |
| cin >> lastName; | |
| cout << "Enter the SSN of the account holder: "; | |
| cin >> SSN; | |
| cout << endl; | |
| Bankaccount account(firstName,lastName,SSN); //account is the object and general constructor as well. | |
| accounts.push_back(account); // push_back() pushes the first object of type class Bankaccount back and adds new object. | |
| } | |
| void printVector(){ // print vector is being used here to print the info such as first name,last name, SSN. | |
| for(unsigned int i = 0;i<accounts.size();i++){ | |
| accounts.at(i).printInfo(); | |
| } | |
| } | |
| Bank(){ // default constructor. | |
| } | |
| Bank(string name,string address,string workingHours){ // assigning of the variables using general constructor. | |
| this->name = name; | |
| this->address = address; | |
| this->workingHours = workingHours; | |
| } | |
| void printInfo(){ // prints the info. | |
| cout << " | Bank name: "<< name << endl; | |
| cout << " | Bank address: "<< address << endl; | |
| cout << " | Bank working hours: "<< workingHours << endl; | |
| // cout << " | Aggregated Balance: " << (Bankaccount::getsavingBalance() + Bankaccount::getcheckingBalance()) << endl; | |
| cout << " | Consists of " << accounts.size() <<" Bank-accounts" << endl; | |
| } | |
| void mainMenu(){ // main menu function displays the list of services. | |
| char choice; | |
| do{ | |
| cout << "Eligible services for " << name << endl; | |
| cout <<" A -- Number of Bank-Accounts" << endl; | |
| cout <<" S -- Number of Saving-Accounts" << endl; | |
| cout <<" H -- Number of Checking-Accounts" << endl; | |
| cout <<" O -- Open Bank-Account" << endl; | |
| cout <<" C -- Close Bank-Account" << endl; | |
| cout <<" M -- Modify Bank-Account" << endl; | |
| cout <<" D -- Detailed Bank-Accounts" << endl; | |
| cout <<" B -- Brief Bank-Accounts Info Sorted Based on Aggregated Balances" << endl; | |
| cout <<" E -- Exit" << endl; | |
| cout << "Please enter your selection: "; | |
| cin >> choice; | |
| cout << endl; | |
| if((choice == 'A') || (choice == 'a')){ | |
| cout << "Number of Bank-Accounts: " << accounts.size() << endl; // accounts.size() is used to display number of accounts. | |
| } | |
| else if((choice == 'S') || (choice == 's')){ | |
| cout << "Number of Saving-Accounts: " << Bankaccount::getsavingAccountcount() << endl; // getsavingAccountcount() displays the number of saving accounts. | |
| } | |
| else if((choice == 'H') || (choice == 'h')){ | |
| cout << "Number of Checking-Accounts: " << Bankaccount::getcheckingAccountcount() << endl; //getcheckingAccountcount() displays the number of checking accounts. | |
| } | |
| else if((choice == 'O') || (choice == 'o')){ | |
| fillVector();// fillvector function is called here to open a new bank account. | |
| object1.menu();// after opening a new bankaccount another menu of services automatically gets displayed. | |
| } | |
| else if((choice == 'C') || (choice == 'c')){ | |
| accounts.pop_back(); // used to close an account permanently. | |
| } | |
| else if((choice == 'M')|| (choice == 'm')){ | |
| object1.menu(); // The menu is again called for modifications if any. | |
| } | |
| else if((choice == 'D')|| (choice == 'd')){// called to print first name, last name , SSN, and Bankaccount number. displays detailed info regarding the bank. | |
| printInfo(); | |
| cout << endl; | |
| printVector(); | |
| cout << endl; | |
| object1.printsavingVector(); | |
| cout << endl; | |
| object1.printcheckingVector(); | |
| } | |
| else if((choice == 'B')|| (choice == 'b')){//displays brief info such as bank's name,address and working hours.// Also displays aggregated balance for number of subaccounts. | |
| printInfo(); | |
| cout << endl; | |
| object1.printAggregatedBalance(); | |
| } | |
| else{ | |
| cout <<" | End of service for " << name << endl; | |
| } | |
| } | |
| while(choice != 'E'); | |
| } | |
| }; | |
| #endif /* Bank_h */ | |
This file contains hidden or 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
| #ifndef BankAccount_h | |
| #define BankAccount_h | |
| #include <iostream> | |
| #include <string> | |
| #include <algorithm> | |
| #include <list> | |
| //#include <utility> | |
| #include "SavingSubAccount.h" | |
| #include "CheckingSubAccount.h" | |
| #include<vector> | |
| class Bankaccount:protected Savingsubaccount, protected Checkingsubaccount | |
| { | |
| private: | |
| string firstName; | |
| string lastName; | |
| string SSN; | |
| static unsigned int accountNum; | |
| static string variable; | |
| string bankAccountnum; | |
| char input; | |
| vector <Savingsubaccount> savingAccounts; // A vector is being used to store number of saving accounts. | |
| vector <Checkingsubaccount> checkingAccounts;// A vector or list is being used to store number of checking accounts. | |
| static unsigned int savingAccountcount; // static variables used here are for keeping the count of saving accounts.Static so that can be accessed anywhere. | |
| static unsigned int checkingAccountcount; | |
| Checkingsubaccount checkingObject; | |
| vector<Savingsubaccount> savObjects; | |
| Savingsubaccount savingObject; | |
| vector<Checkingsubaccount> checkObjects; | |
| int deposit = 0,withdraw = 0; | |
| int balance = 0; | |
| public: | |
| static unsigned int getsavingAccountcount(){ | |
| return savingAccountcount; | |
| } | |
| static unsigned int getcheckingAccountcount(){ | |
| return checkingAccountcount; | |
| } | |
| Bankaccount(){ // default constructor | |
| } | |
| Bankaccount(string firstName,string lastName,string SSN){ // general constructor | |
| this->firstName = firstName; | |
| this->lastName = lastName; | |
| this->SSN = SSN; | |
| accountNum++; // accountNum++ increments whenever a new account is opened. | |
| bankAccountnum = variable + to_string(accountNum); // to_string function is being used to convert an integer into a string so that it can be assigned to bankAccountnum. | |
| cout <<" | A new Bank Account "<< bankAccountnum <<" was successfully created." << endl; | |
| cout << endl; | |
| } | |
| void setfirstName(string firstName){ //setters. | |
| this->firstName = firstName; | |
| } | |
| void setlastName(string lastName){//setters. | |
| this->lastName = lastName; | |
| } | |
| void setSSN(string SSN){//setters. | |
| this->SSN = SSN; | |
| } | |
| string getfirstName(){//getters. | |
| return this->firstName; | |
| } | |
| string getlastName(){ //getters. | |
| return this->lastName; | |
| } | |
| string getSSN(){//getters. | |
| return this->SSN; | |
| } | |
| bool compareBalance(Savingsubaccount& savingAccounts,Checkingsubaccount& checkingAccounts){ | |
| return savingAccounts.getsavingBalance() > checkingAccounts.getcheckingBalance(); | |
| } | |
| void fillSavingVector(){ //function is used to add saving sub accounts. | |
| cout <<" | Enter the intial balance: "; | |
| cin >> balance; | |
| Savingsubaccount savingAccount(balance,deposit,withdraw); //a constructor is being used here. | |
| savingAccounts.push_back(savingAccount); // push_back to add saving subaccounts. | |
| savingObject.setsavingBalance(balance); | |
| savObjects.push_back(savingObject); | |
| savingAccountcount++; | |
| } | |
| void fillCheckingVector(){ //function is used to add checking sub accounts. | |
| int maxCapacity = 0; | |
| int balance2; | |
| cout << " | Enter the intial balance: "; | |
| cin >> balance2; | |
| cout << " | Enter the desired maximum capacity: "; | |
| cin >> maxCapacity; | |
| cout << " | Define the intial state: (L - locked,otherwise - unlocked) "; | |
| cin >> input; | |
| cout << endl; | |
| Checkingsubaccount checkingAccount(balance2,maxCapacity,input);//a constructor is being used here. | |
| checkingAccounts.push_back(checkingAccount); | |
| checkingObject.setcheckingBalance(balance2); | |
| checkingObject.setmaximumCapacity(maxCapacity); | |
| checkObjects.push_back(checkingObject); | |
| checkingAccountcount++; | |
| } | |
| void printsavingVector(){// printsaving vector function prints the saving sub account info. | |
| for(int i = 0;i<savingAccounts.size();i++){ | |
| savingAccounts.at(i).savingprintInfo(); | |
| savObjects.at(i).savingprintInfo(); | |
| } | |
| } | |
| void printcheckingVector(){//printchecking vector function prints the checking sub account info. | |
| for (int i =0;i<checkingAccounts.size();i++) { | |
| checkingAccounts.at(i).checkingprintInfo(); | |
| checkingObject.checkingprintInfo(); | |
| } | |
| } | |
| void printAggregatedBalance(){ //prints aggregated balance of subaccounts. | |
| if((savingAccounts.size() >= 1) && (checkingAccounts.size() == 0)){ | |
| cout <<" | Aggregated balance of the bank account: "<< variable + to_string(accountNum) << " with " << savingAccounts.size()+checkingAccounts.size() << " Sub accounts is " << savingObject.getsavingBalance() << endl; | |
| } | |
| else if((savingAccounts.size() == 0) && (checkingAccounts.size() >= 1)){ | |
| cout <<" | Aggregated balance of the bank account: "<< variable + to_string(accountNum) << " with " << savingAccounts.size()+checkingAccounts.size() << " Sub accounts is " << checkingObject.getcheckingBalance() << endl; | |
| } | |
| else{ | |
| cout <<" | Aggregated balance of the bank account: "<< variable + to_string(accountNum) << " with " << savingAccounts.size()+checkingAccounts.size() << " Sub accounts is " << (savingObject.getsavingBalance() + checkingObject.getcheckingBalance()) << endl; | |
| } | |
| } | |
| void printInfo(){//prints customers info such as name , ssn, bankaccount number, balance and how many sub accounts it consists of. | |
| cout << " | Account Holder Full Name: " << firstName <<" "<< lastName << endl; | |
| cout << " | Account Holder SSN: " << SSN << endl; | |
| cout << " | Bank account number: " << bankAccountnum << endl; | |
| cout << " | Aggregated balance: " << savingObject.getsavingBalance() + checkingObject.getcheckingBalance() << endl; | |
| cout << " | Consists of "<< getsavingAccountcount() + getcheckingAccountcount() <<" Sub-Accounts" << endl; | |
| } | |
| void menu(){ // This menu consist of other services regarding the Bank account. | |
| char choice1; | |
| do{ | |
| cout << "Eligible services for Bank account " << variable + to_string(accountNum) << endl; | |
| cout <<" S -- Open Saving Sub-Account" << endl; | |
| cout <<" C -- Open Checking Sub-Account" << endl; | |
| cout <<" M -- Modify a Sub-Account" << endl; | |
| cout <<" E -- Close a Sub-Account" << endl; | |
| cout <<" D -- Detailed Bank Account Info Sorted Based on Balances of Sub-Accounts" << endl; | |
| cout <<" B -- Brief Bank Account Info" << endl; | |
| cout <<" X -- Exit" << endl; | |
| cout << "Please enter your selection: " << endl; | |
| cin >> choice1; | |
| if((choice1 == 'S') || (choice1 == 's')){ | |
| fillSavingVector(); | |
| } | |
| else if((choice1 == 'C') || (choice1 == 'c')){ | |
| fillCheckingVector(); | |
| } | |
| else if((choice1 == 'M') || (choice1 == 'm')){ | |
| string subAccount; | |
| cout << "Enter the sub-account number to modify: "; | |
| cin >> subAccount; | |
| cout << endl; | |
| if (subAccount == Savingsubaccount::variable1 + to_string(savingNum)){//if statement for saving | |
| savingObject.savingMenu(); | |
| } | |
| else if(subAccount == variable2 + to_string(checkingNum)){ | |
| checkingObject.checkingMenu(); | |
| } | |
| } | |
| else if((choice1 == 'E') || (choice1 == 'e')){ | |
| string accountClosed; | |
| cout << "Enter the sub-account number to be closed: "; | |
| cin >> accountClosed; | |
| cout << endl; | |
| if(accountClosed == variable1 + to_string(savingNum)){ | |
| savingAccounts.pop_back(); | |
| cout << " | sub-account " << accountClosed <<" was successfully closed" << endl; | |
| } | |
| else if(accountClosed == variable2 + to_string(checkingNum)) { | |
| checkingAccounts.pop_back(); | |
| cout << " | sub-account " << accountClosed <<" was successfully closed" << endl; | |
| } | |
| } | |
| else if((choice1 == 'D') || (choice1 == 'd')){ | |
| printsavingVector(); | |
| cout << endl << endl; | |
| printcheckingVector(); | |
| } | |
| else if((choice1 == 'B') || (choice1 == 'b')){ | |
| printAggregatedBalance(); | |
| } | |
| else { | |
| cout <<" | End of service for bank-account " << variable + to_string(accountNum) << endl; | |
| } | |
| } | |
| while (choice1 != 'X'); | |
| } | |
| }; | |
| unsigned int Bankaccount::accountNum = 9999; | |
| string Bankaccount::variable = "BNK"; | |
| unsigned int Bankaccount::checkingAccountcount = 0; | |
| unsigned int Bankaccount::savingAccountcount = 0; | |
| #endif /* BankAccount_h */ | |
This file contains hidden or 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
| #ifndef CheckingSubAccount_h | |
| #define CheckingSubAccount_h | |
| class Checkingsubaccount{ | |
| private: | |
| int maximumCapacity; | |
| int checkingBalance = 0; | |
| bool lock = false; | |
| string checkingAccountnum; | |
| char input; | |
| protected: | |
| static unsigned int checkingNum; | |
| static string variable2; | |
| public: | |
| Checkingsubaccount(){//default constructor. | |
| } | |
| Checkingsubaccount(int checkingBalance,int maximumCapacity,char input){ // general constructor is used here for assigning. | |
| this->checkingBalance = checkingBalance; | |
| this->maximumCapacity = maximumCapacity; | |
| this->input = input; | |
| // this->lock = lock; | |
| checkingNum++; | |
| checkingAccountnum = variable2 + to_string(checkingNum); | |
| cout <<" | A new Checking Sub-Account "<< checkingAccountnum <<" was successfully created." << endl; | |
| cout << endl; | |
| } | |
| void setcheckingBalance(int checkingBalance){ | |
| this->checkingBalance = checkingBalance; | |
| } | |
| int getcheckingBalance(){ | |
| return this->checkingBalance; | |
| } | |
| void setmaximumCapacity(int maximumCapacity){ | |
| this->maximumCapacity = maximumCapacity; | |
| } | |
| int getmaximumCapacity(){ | |
| return maximumCapacity; | |
| } | |
| bool Locked(char input){ | |
| if((input == 'L') || (input == 'l')){ | |
| return true; | |
| } | |
| else{ | |
| return false; | |
| } | |
| } | |
| void checkingprintInfo(){ | |
| cout << " | sub-account number: " << variable2 + to_string(checkingNum) << endl; | |
| cout << " | Balance: " << getcheckingBalance() << endl; | |
| cout << endl; | |
| cout << " | The maximum capacity is: " << maximumCapacity << endl; | |
| if(Locked(input) == true){ | |
| cout << " | The sub-account is locked. " << endl; | |
| } | |
| else{ | |
| cout << " | The sub-account is not locked. " << endl; | |
| } | |
| cout << endl; | |
| } | |
| void checkingDeposit(int deposit,int &checkingBalance){ | |
| checkingBalance = checkingBalance + deposit; | |
| } | |
| void checkingWithdraw(int withdraw,int &checkingBalance){ | |
| checkingBalance = checkingBalance - withdraw; | |
| } | |
| void checkingMenu(){ | |
| char character; | |
| do{ | |
| cout << "Eligible services for sub-account " << variable2 + to_string(checkingNum) << endl; | |
| cout <<" D -- Deposit" << endl; | |
| cout <<" W -- Withdraw" << endl; | |
| cout <<" C -- Max Capacity" << endl; | |
| cout <<" L -- Lock sub-Account" << endl; | |
| cout <<" U -- Unlock sub-Account" << endl; | |
| cout <<" X -- Exit" << endl; | |
| cin >> character; | |
| if((character == 'D') || (character == 'd')){ | |
| int deposit; | |
| cout << " | Enter the amount to deposit: "; | |
| cin >> deposit; | |
| cout << endl; | |
| if(Locked(input) == true){ // if locked true then deposit wont be possible. | |
| cout << " | The account is currently locked! " << endl; | |
| cout << " | The deposit was unsuccessful. " << endl; | |
| } | |
| else{ | |
| checkingDeposit(deposit,checkingBalance); // else deposit if not locked and display current balance. | |
| cout << " | Deposit was successful. "<< endl; | |
| cout << " | The current balance is: " << getcheckingBalance() << endl; | |
| cout << endl; | |
| } | |
| } | |
| else if((character == 'W') || (character == 'w')){ | |
| int withdraw; | |
| cout << " | Enter the amount to withdraw: "; | |
| cin >> withdraw; | |
| cout << endl; | |
| if(Locked(input) == true){// if locked true then withdraw wont be possible. | |
| cout << " | The account is currently locked! " << endl; | |
| cout << " | The deposit was unsuccessful. " << endl; | |
| } | |
| else{ // else withdraws if not locked and displays current balance. | |
| checkingWithdraw(withdraw,checkingBalance); | |
| cout << " | Withdraw was successful. " << endl; | |
| cout << " | The current balance is: " << getcheckingBalance() << endl; | |
| } | |
| } | |
| else if((character == 'C') || (character == 'c')){ | |
| if(getcheckingBalance() > getmaximumCapacity()){ | |
| cout << " | Deposit was denied!" << endl; | |
| } | |
| } | |
| else if((character == 'L') || (character == 'l')){ | |
| input = character; | |
| if(Locked(input) == true){ | |
| cout << " | The sub-account "<< variable2 + to_string(checkingNum) <<" has been locked now! " << endl; | |
| } | |
| } | |
| else if((character == 'U') || (character == 'u')){ | |
| input = character; | |
| if(Locked(input) == false){ | |
| cout << " | The sub-account "<< variable2 + to_string(checkingNum) <<" has been unlocked now! " << endl; | |
| } | |
| } | |
| else { | |
| cout <<" | End of service for sub-account " << variable2 + to_string(checkingNum) << endl; | |
| } | |
| } | |
| while(character != 'X'); | |
| } | |
| }; | |
| unsigned int Checkingsubaccount::checkingNum = 5999; | |
| string Checkingsubaccount::variable2 = "CHK"; | |
| #endif /* CheckingSubAccount_h */ |
This file contains hidden or 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 "Bank.h" | |
| int main(){ | |
| string name; | |
| string address; | |
| string workingHours; | |
| cout << "Enter the name of the bank: "; | |
| getline(cin,name); //getline function is used here to get a line for name. | |
| cout << "Enter the address of the bank: "; | |
| getline(cin,address);//getline function is used here to get a line for address. | |
| cout << "Enter the working hours: "; | |
| getline(cin,workingHours);//getline function is used here to get a line for working hours. | |
| cout << endl; | |
| Bank object(name,address,workingHours); // a general constructor is used here to pass values. | |
| object.mainMenu(); // an object of Bank is declared and is used to call main menu. | |
| // object.printInfo(); | |
| } |
This file contains hidden or 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
| #ifndef SavingSubAccount_h | |
| #define SavingSubAccount_h | |
| #include <iostream> | |
| #include <string> | |
| using namespace std; | |
| class Savingsubaccount{ | |
| private: | |
| int bonus = 100; | |
| string savingAccountnum; | |
| int savingBalance = 0; | |
| int deposit; | |
| int withdraw; | |
| protected: | |
| static unsigned int savingNum; | |
| static string variable1; | |
| public: | |
| Savingsubaccount(){ //default constructor | |
| } | |
| Savingsubaccount(int savingBalance,int deposit,int withdraw) { // a general constructor is used to assign savingBalance. | |
| this->savingBalance = savingBalance; | |
| this->deposit = deposit; | |
| this->withdraw = withdraw; | |
| savingNum++; | |
| savingAccountnum = variable1 + to_string(savingNum); | |
| cout <<" | A new Saving Sub-Account "<< savingAccountnum <<" was successfully created." << endl; | |
| cout << endl; | |
| } | |
| void setsavingBalance(int balance) {// a setter is used to assign balance to savingBalance. | |
| savingBalance = balance; | |
| } | |
| int getsavingBalance() const{ //a getter is used here. | |
| return this->savingBalance;//returns savingBalance. | |
| } | |
| int getBonus(){ | |
| if(variable1 + to_string(savingNum) == "SAV1000"){ | |
| return bonus; | |
| } | |
| else{ | |
| return 0; | |
| } | |
| } | |
| void savingDeposit(int deposit){ //saving deposit function for deposit of saving sub account. | |
| cout << " | Enter the amount to deposit: "; | |
| cin >> deposit; | |
| cout << endl; | |
| savingBalance = savingBalance + deposit + getBonus(); | |
| cout << " | Deposit was successful." << endl; | |
| cout << " | The current balance is: " << getsavingBalance() << endl; | |
| cout << endl; | |
| } | |
| void savingWithdraw(int withdraw){ //saving with function for withdraw of saving sub account | |
| cout <<" | Enter the amount to withdraw: "; | |
| cin >> withdraw; | |
| cout << endl; | |
| savingBalance = savingBalance - withdraw; | |
| cout << " | Withdraw was successful. " << endl; | |
| cout << " | The current balance is: " << getsavingBalance() << endl; | |
| cout << endl; | |
| } | |
| virtual void savingprintInfo() const { //prints the saving sub-account number and balance. | |
| cout <<" | Sub-account number: " << variable1 + to_string(savingNum) << endl; | |
| cout <<" | Balance: "<< getsavingBalance() << endl; | |
| } | |
| void savingMenu(){ | |
| char character; | |
| do{ | |
| cout << "Eligible services for sub-account " << variable1 + to_string(savingNum) << endl; | |
| cout <<" D -- Deposit" << endl; | |
| cout <<" W -- Withdraw" << endl; | |
| cout <<" X -- Exit" << endl; | |
| cin >> character; | |
| if((character == 'D') || (character == 'd')){ | |
| savingDeposit(deposit); | |
| } | |
| else if((character == 'W') || (character == 'w')){ | |
| savingWithdraw(withdraw); | |
| } | |
| else{ | |
| cout <<" |End of service for sub-account " << variable1 + to_string(savingNum) << endl; | |
| } | |
| }while(character != 'X'); | |
| } | |
| }; | |
| unsigned int Savingsubaccount::savingNum = 999; | |
| string Savingsubaccount::variable1 = "SAV"; | |
| #endif /* SavingSubAccount_h */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment