-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path32dynamic_constr.cpp
More file actions
97 lines (92 loc) · 2.31 KB
/
Copy path32dynamic_constr.cpp
File metadata and controls
97 lines (92 loc) · 2.31 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
#include <iostream>
using namespace std;
class BankDeposit
{
int principal;
int year;
float interestRate;
float returnValue;
public:
//Reason of creating an empty constructor :
//if an object is passed without any initialized values to show or display, it will run the program by initializing that object
//without it, the empty object will throw error since compiler won't be able to find from where to catch the values from
BankDeposit() {}
BankDeposit(int p, int y, float r);
BankDeposit(int p, int y, int r);
void show();
};
BankDeposit ::BankDeposit(int p, int y, float r)
{
principal = p;
year = y;
interestRate = r;
returnValue = principal;
for (int i = 0; i < y; i++)
{
returnValue *= (1 + interestRate);
}
}
BankDeposit ::BankDeposit(int p, int y, int r)
{
principal = p;
year = y;
interestRate = float(r) / 100;
returnValue = principal;
for (int i = 0; i < y; i++)
{
returnValue *= (1 + interestRate);
}
}
void BankDeposit ::show()
{
cout << "The principal amount deposited in year 0 : " << principal << endl
<< " timeline for deposition : " << year << endl
<< "computes the return value to : " << returnValue << endl;
}
int main()
{
BankDeposit user[5];
int p, y, r_d;
float r_p;
bool per = true;
cout << "Enter your Principal amount, year and rate (in percentage or decimal value) user :" << endl;
cout << "??Decimal : 0 ??Percentage : 1" << endl;
cin >> per;
if (per = 1)
{
for (int i = 0; i < 3; i++)
{
cout << "Principal : ";
cin >> p;
cout << "Year : ";
cin >> y;
cout << "Interest Rate : ";
cin >> r_p;
user[i] = BankDeposit(p, y, r_p);
}
for (int i = 0; i < 3; i++)
{
user[i].show();
cout << endl;
}
}
else
{
for (int i = 0; i < 3; i++)
{
cout << "Principal : ";
cin >> p;
cout << "Year : ";
cin >> y;
cout << "Interest Rate : ";
cin >> r_d;
user[i] = BankDeposit(p, y, r_d);
}
for (int i = 0; i < 3; i++)
{
user[i].show();
cout << endl;
}
}
return 0;
}