Demonstrate the ability to create and manipulate classes, data members, and memb
ID: 3687792 • Letter: D
Question
Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines. Create a C++ project to implement a simplified banking system. Step 1: Create a header file Bank.h to define a Bank class with the following members: Data members: The program should implement data hiding, so please define data members accordingly. - accountNumber - name - balance Note: The data types are not specified for this problem, so you have flexibility to design the program in your way. Member functions: Please include only the declaration of the member functions in the header file. The implementation of member functions will later be done in the Bank.cpp file. (You may inline get and set functions.) - Bank() constructor with no arguments creates a bank account with a default accountNumber as 9999, a name of an empty string, and balance value of zero. - Bank(param1, param2, param3) constructor with three parameters creates a bank account with a specified accountNumber, name and balance. - withdraw(param1) function to withdraw a specified amount (param1) from the account. The function should first check if there is sufficient balance in the account. If the balance is sufficient, withdrawal is processed and the current balance is returned as a string. Otherwise return a string to the caller that says “Insufficient balance” and leave the balance unchanged. - deposit(param1) function to deposit a specified amount of money (param1) to the account. - setName(param1) mutator function that changes the name on the account. - getAccountNumber(): An accessor function that returns the account number. This function is later called by the displayAccountInfo() function from inside another independent function called displayAccountInfo(). - getName(): An accessor function that returns the name on the account. - getBalance(): An accessor function that returns the account balance. This function is later called by the displayAccountInfo() function from inside another independent function called displayAccountInfo(). Step 2: Create a Bank.cpp file and implement the member functions of the Bank class. Step 3: Also define an independent displayAccountInfo(Bank obj) function which takes a Bank object (obj) as a parameter and displays the accountNumber, name, and balance of the bank account specified by this Bank object. The displayAccountInfo() function is later called by the main function. Note: The displayAccountInfo() function IS NOT a member function of the Bank class. It is an independent function that is called from inside the main function. Step 4: Finally, create a main.cpp file to display a menu with the following options: 1. Create Bank object with values for accountNumber, name, and balance 2. Create Bank object with no parameters. 3. Deposit to Bank account (request account number and amount) 4. Withdraw from Bank account (request account number and amount) 5. Display information for all accounts 6. Exit the program. To test: • Create a bank account - say accnt1- with no parameters. Try to withdraw $500 from this account. • Create another bank account - say accnt2- with accountNumber: 1111, your name, and $1000 balance. Withdraw $600, then withdraw $300, and then deposit $400 to this account. • Display all account information Note: There will never be more than 10 accounts. Show an error message if the user tries to deposit to or withdraw from an account number that doesn’t exist. Show an error message if the user attempts to create an account number that already exists. Show any messages returned from the withdraw() function.Explanation / Answer
Create a C++ project to implement a simplified banking system class Account { double balance; double add(double sum) { balance += sum; return sum; } double withdraw(double sum) { if (sum > balance) { balance -= 5; return -5; // this will come in handy in Prob. 6 } else { balance -= sum; return balance; // Notice: always >= 0 (never < 0) } } double inquire() { return balance; } Account() { balance = 0; } Account(double sum) { balance = sum; } double interest (double rate) { return rate * balance; } } class Bank { Account checking; Account savings; void deposit(double amount, String account) { if (account.equals("C")) checking.add(amount); else // my default savings.add(amount); } void withdraw(double amount, String account) { if (account.equals("C")) checking.withdraw(amount); else // my default savings.withdraw(amount); } void transfer (double amount, String account) { if (account.equals("C")) if (checking.withdraw(amount) >= 0) savings.add(amount); else checking.add(5); // somewhat fault-tolerant else // default if (savings.withdraw(amount) >= 0) checking.add(amount); else savings.add(5); // no penalty for transfers } void printBalances() { System.out.println( "Checking: " + checking.inquire() + " Savings: " + savings.inquire() ); } } class Account{ String name,acc_type; int Acc_num,Acc_Balance; Account(){ } Account(String n,int acc_num,int b,String a_t){ name=n; Acc_num=acc_num; Acc_Balance=b; acc_type=a_t; } } // end class class create_account extends Account{ create_account(String n,int acc_num,int b,String a_t){ // pass name and account type name=n; Acc_num=acc_num; Acc_Balance=b; acc_type=a_t; } create_account(){ super(); } void insert(String n,int acc_num,String a_t){ // input user name, account number and type name=n; acc_type=a_t; Acc_num=acc_num; // generate random number Acc_Balance=0; } void display_details(){ System.out.println("Depositor Name :" +name); System.out.println("Account Number : "+Acc_num); System.out.println("Account Balance : "+Acc_Balance); System.out.println("Account Type : "+acc_type); } void deposite(int acc_num,int money){ Acc_Balance=money; } int withdraw(int withd){ Acc_Balance=Acc_Balance-withd; return Acc_Balance; } } // end class public class Main { public static void main(String args[]){ String user_name=null,type; type = null; int balance=0,tmp=0; int withd=0,cb=0; // to generate Random Account Number int aNumber = 0; aNumber = (int)((Math.random() * 9000)+1000); create_account user = new create_account("user",0,0,"savings"); // initilaize -- name,acc_number,Balance,Type Scanner in = new Scanner(System.in); Scanner strng=new Scanner(System.in); int userChoice; boolean quit = false; do { System.out.println("1. Create Account"); System.out.println("2. Deposit money"); System.out.println("3. Withdraw money"); System.out.println("4. Check balance"); System.out.println("5. Display Account Details"); System.out.println("0. to quit: "); System.out.print("Enter Your Choice : "); userChoice = in.nextInt(); switch (userChoice) { case 1: System.out.print("Enter your Name : "); user_name=strng.nextLine(); System.out.print("Enter Accout Type : "); type=in.next(); user.insert(user_name, aNumber, type); // inserted System.out.println(" Your Account Details Dont Forget Account Number "); System.out.println("**************************"); user.display_details(); break; case 2: // deposite System.out.print("Enter your account Number : "); tmp=in.nextInt(); if(tmp==user.Acc_num){ System.out.print("Enter Amount Of Money : "); balance=in.nextInt(); user.Acc_Balance=balance; System.out.println(" Successfully Deposited."); } else System.out.println("Wrong Accoount Number."); break; case 3: // withdraw money System.out.print("Enter your account Number : "); tmp=in.nextInt(); if(tmp==user.Acc_num){ if(user.Acc_Balance==0) System.out.print("Your Account is Empty."); else{ System.out.print("Enter Amout Of Money : "); withd=in.nextInt(); if(withd>user.Acc_Balance){ System.out.print("Enter Valid Amout of Money : "); withd=in.nextInt(); } else cb= user.withdraw(withd); System.out.println("Your Current Balance : "+cb); } } else System.out.println("Wrong Accoount Number."); break; case 4: // check balance System.out.print("Enter your Account Number : "); tmp=in.nextInt(); if(tmp==user.Acc_num){ System.out.println("Your Current Balance : "+user.Acc_Balance); } else System.out.println("Wrong Accoount Number."); break; case 5: // display all info System.out.print("Enter your Account Number :"); tmp=in.nextInt(); if(tmp==user.Acc_num){ user.display_details(); }else System.out.println("Wrong Accoount Number."); break; case 0: quit = true; break; default: System.out.println("Wrong Choice."); break; } System.out.println(" "); } while (!quit); System.out.println("Thanks !"); } // end main function } // end mian classRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.