Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Demonstrate the ability to create and manipulate classes, data members, and memb

ID: 3533794 • 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.

Create a C++ project to do 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

- balance

Note: The data types are not specified for this problem, so as to give you 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.

- Bank() constructor with no arguments to create a bank account with a default accountNumber as 9999 and balance value of zero.

- Bank(param1, param2) constructor with two parameters to create a bank account with a specified accountNumber and balance (as param1 and param2, respectively).

- 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, otherwise display a message to the user that says

Explanation / Answer

  1. Bank.h
  2. class Bank
  3. {
  4. private:
  5.   int accountNumber;
  6.   float balance;
  7. public:
  8. Bank();
  9. Bank(int num, float bal);
  10.   void withdraw(float sum);
  11.   void deposit(float sum);
  12.   int getAccountNumber();
  13.   float getBalance();
  14. };
  15. Bank.cpp
  16. #include "Bank.h"
  17. #include <iostream>
  18. using namespace std;
  19. Bank::Bank ()
  20. {
  21. accountNumber = 9999;
  22. balance = 0.0;
  23. }
  24. Bank::Bank (int num, float bal)
  25. {
  26. accountNumber = num;
  27. balance = bal;
  28. }
  29. void Bank::withdraw (float sum)
  30. {
  31.   if (balance >= sum)
  32.   {
  33. balance -= sum;
  34.   }
  35.   else
  36.   {
  37. std::cout << "Insufficient funds" << std::endl;
  38. balance = 0;
  39.   }
  40. }
  41. void Bank::deposit (float sum)
  42. {
  43. balance += sum;
  44. }
  45. int Bank::getAccountNumber ()
  46. {
  47.   return accountNumber;
  48. }
  49. float Bank::getBalance ()
  50. {
  51.   return balance;
  52. }
  53. void displayAccountInfo (Bank acc)
  54. {
  55.   cout << "Account Number: " << acc.getAccountNumber();
  56.   cout << endl;
  57.   cout << "Balance: $" << acc.getBalance();
  58.   cout << endl;
  59. }
  60. int main()
  61. {
  62. Bank accnt1;
  63. accnt1.withdraw(500.00);
  64. Bank accnt2(1111, 1000.00);
  65. accnt2.withdraw(600.00);
  66. accnt2.withdraw(300.00);
  67. accnt2.deposit(400.00);
  68. displayAccountInfo(accnt1);
  69. displayAccountInfo(accnt2);
  70. }
  1. Bank.h
  2. class Bank
  3. {
  4. private:
  5.   int accountNumber;
  6.   float balance;
  7. public:
  8. Bank();
  9. Bank(int num, float bal);
  10.   void withdraw(float sum);
  11.   void deposit(float sum);
  12.   int getAccountNumber();
  13.   float getBalance();
  14. };
  15. Bank.cpp
  16. #include "Bank.h"
  17. #include <iostream>
  18. using namespace std;
  19. Bank::Bank ()
  20. {
  21. accountNumber = 9999;
  22. balance = 0.0;
  23. }
  24. Bank::Bank (int num, float bal)
  25. {
  26. accountNumber = num;
  27. balance = bal;
  28. }
  29. void Bank::withdraw (float sum)
  30. {
  31.   if (balance >= sum)
  32.   {
  33. balance -= sum;
  34.   }
  35.   else
  36.   {
  37. std::cout << "Insufficient funds" << std::endl;
  38. balance = 0;
  39.   }
  40. }
  41. void Bank::deposit (float sum)
  42. {
  43. balance += sum;
  44. }
  45. int Bank::getAccountNumber ()
  46. {
  47.   return accountNumber;
  48. }
  49. float Bank::getBalance ()
  50. {
  51.   return balance;
  52. }
  53. void displayAccountInfo (Bank acc)
  54. {
  55.   cout << "Account Number: " << acc.getAccountNumber();
  56.   cout << endl;
  57.   cout << "Balance: $" << acc.getBalance();
  58.   cout << endl;
  59. }
  60. int main()
  61. {
  62. Bank accnt1;
  63. accnt1.withdraw(500.00);
  64. Bank accnt2(1111, 1000.00);
  65. accnt2.withdraw(600.00);
  66. accnt2.withdraw(300.00);
  67. accnt2.deposit(400.00);
  68. displayAccountInfo(accnt1);
  69. displayAccountInfo(accnt2);
  70. }
Bank.h class Bank { private:   int accountNumber;   float balance; public: Bank(); Bank(int num, float bal);   void withdraw(float sum);   void deposit(float sum);   int getAccountNumber();   float getBalance(); }; Bank.cpp #include "Bank.h" #include <iostream> using namespace std; Bank::Bank () { accountNumber = 9999; balance = 0.0; } Bank::Bank (int num, float bal) { accountNumber = num; balance = bal; } void Bank::withdraw (float sum) {   if (balance >= sum)   { balance -= sum;   }   else   { std::cout << "Insufficient funds" << std::endl; balance = 0;   } } void Bank::deposit (float sum) { balance += sum; } int Bank::getAccountNumber () {   return accountNumber; } float Bank::getBalance () {   return balance; } void displayAccountInfo (Bank acc) {   cout << "Account Number: " << acc.getAccountNumber();   cout << endl;   cout << "Balance: $" << acc.getBalance();   cout << endl; } int main() { Bank accnt1; accnt1.withdraw(500.00); Bank accnt2(1111, 1000.00); accnt2.withdraw(600.00); accnt2.withdraw(300.00); accnt2.deposit(400.00); displayAccountInfo(accnt1); displayAccountInfo(accnt2); }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote