You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 13_virtual_function_and_abstract_class/05_bank.cpp
+134-6Lines changed: 134 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
// // Design a class hierarchy for a banking system with a base class Account and two derived classes SavingsAccount and CurrentAccount. Each class should have data members for account balance, account number, and an interest rate (for savings account). Implement pure virtual functions for deposit, withdraw, and display account details in Account class. Demonstrate the use of these classes by creating objects and performing transactions.
1
+
// // Design a class hierarchy for a banking system with a base class Account and two derived classes SavingsAccount and CurrentAccount. Each class should have data members for account balance, account number, and an interest rate (for savings account). Implement pure virtual functions for set account number, deposit, withdraw, and display account details in Account class. Demonstrate the use of these classes by creating objects and performing transactions.
2
2
3
3
// // Header files
4
4
#include<iostream>
@@ -13,6 +13,7 @@ class Account
13
13
{
14
14
public:
15
15
// // static member variable
16
+
staticconstint MAX_CHARS_IN_NAME = 31;
16
17
staticconstint MAX_DIGITS_IN_ACCOUNT_NUM = 6;
17
18
18
19
protected:
@@ -22,6 +23,7 @@ class Account
22
23
23
24
public:
24
25
// // pure virtual functions to be overridden by derived classes
26
+
virtualvoidsetAccountNumber(constchar *) = 0;
25
27
virtualvoiddeposit(double) = 0;
26
28
virtualvoidwithdraw(double) = 0;
27
29
virtualvoiddisplayAccountDetails() const = 0;
@@ -35,8 +37,31 @@ class SavingAccount : public Account
35
37
staticfloat rateOfInterest;
36
38
37
39
public:
40
+
SavingAccount()
41
+
{
42
+
accountBalance = 0;
43
+
}
44
+
45
+
// // override base class setAccountNumber function
0 commit comments