-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBanking System.cpp
More file actions
94 lines (81 loc) · 1.78 KB
/
Banking System.cpp
File metadata and controls
94 lines (81 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
Author: CWN221
Date: 31/10/2024
Description: Demonstrating concept of Inheritance in C++
RegNo: BSE-01-0032/2024
*/
#include <iostream>
using namespace std;
class BankAccount
{
protected:
string accountHolder;
float balance;
public:
//function 1
void setAccountHolder(string name)
{
accountHolder = name;
};
//function 2
string getAccountHolder()
{
return accountHolder;
};
//function 3
float getBalance()
{
return balance;
};
};
class SavingsAccount: public BankAccount
{
private:
float interestRate;
public:
//Constructor
SavingsAccount(string owner, float currentBalance, float rate) {
accountHolder = owner;
balance = currentBalance;
interestRate = rate;
}
//function
float calculateInterest() {
return interestRate * balance;
}
};
class CheckingAccount : public BankAccount
{
private:
float transactionFee;
public:
//constructor
CheckingAccount(string owner, float currentBalance, float fee) {
accountHolder = owner;
balance = currentBalance;
fee = transactionFee;
}
//function
void deductFee()
{
balance -= transactionFee;
}
};
int main()
{
//objects
SavingsAccount savings("Alice", 1000, 0.03);
CheckingAccount acc("Bob", 500, 2.5);
//results from SavingsAccount
cout<<"Savings Account;"<<endl;
cout<<"Account holder: "<<savings.getAccountHolder()<<endl;
cout<<"Account balance: "<<savings.getBalance()<<endl;
cout<<"Interest rate: "<<savings.calculateInterest()<<endl;
cout<<"\n"<<endl;
//results from CheckingAccount
cout<<"Checking Account;"<<endl;
cout<<"Account holder: "<<acc.getAccountHolder()<<endl;
cout<<"Balance: "<<acc.getBalance()<<endl;
cout<<"Updated balance: "<<acc.getBalance()<<endl;
return 0;
}