-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug2.cpp
More file actions
185 lines (144 loc) · 2.68 KB
/
debug2.cpp
File metadata and controls
185 lines (144 loc) · 2.68 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// Debug Program 2
#include <iostream>
#include <string>
using namespace std;
// Base class
class Account
{
private:
int accNo;
double balance;
public:
Account(int a, double b)
{
accNo = a;
balance = b;
}
void setbalance(int b)
{
balance=b;
}
void deposit(double amt)
{
balance = balance + amt;// missing the semicolon
}
void withdraw(double amt)
{
if (amt > balance)
cout << "Insufficient Balance" << endl;
else
balance = balance - amt;
}
void display()
{
cout << "Account No: " << accNo << endl;
cout << "Balance: " << balance << endl;
}
double getBalance()
{
return balance;
}
~Account()
{
cout << "Account closed" << endl;
}
};
// Derived class
class Savings : public Account
{
protected:
double interestRate;
public:
Savings(int a, double b, double r) : Account(a, b)
{
interestRate = r;
}
void addInterest()
{
double interest = getBalance() * interestRate / 100;
deposit(interest);
}
};
// Another derived class
class PremiumSavings : public Savings
{
private:
int rewardPoints;
public:
PremiumSavings(int a, double b, double r, int p)
: Savings(a, b, r)
{
rewardPoints = p;
}
void showDetails()
{
display();
cout << "Interest Rate: " << interestRate << endl;
cout << "Reward Points: " << rewardPoints << endl;
}
};
// Friend function
class Bank;
class Auditor
{
public:
void audit(Bank b);
};
class Bank
{
private:
double totalFunds;
public:
Bank()
{
totalFunds = 0;
}
void addFunds(double amt)
{
totalFunds += amt;
}
friend void Auditor::audit(Bank b);
};
void Auditor::audit(Bank b)
{
cout << "Total Bank Funds: " << b.totalFunds << endl;
}
// Utility class
class Logger
{
public:
static int logCount;
void log(string msg)
{
cout << "LOG: " << msg << endl;
logCount++;
}
};
int Logger::logCount = 0;
int main()
{
Savings s1(1001, 5000, 5);
s1.deposit(1000);
s1.addInterest();
s1.display();
PremiumSavings p1(2001, 10000, 7, 200);
p1.showDetails();
Logger l1;
l1.log("Account Created");
Logger l2;
l2.log("Transaction Done");
cout << "Total Logs: " << Logger::logCount << endl;
Bank b1;
b1.addFunds(50000);
b1.addFunds(25000);
Auditor a;
a.audit(b1);
s1.setbalance(10000);
s1.display();
//Account a1;
Savings p2 = s1;
s1.deposit(-500);
cout << p1.interestRate << endl;
s1.~Savings();
return 0;
}