-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamicIntializationofObjectsusingConstructors.cpp
More file actions
77 lines (65 loc) · 1.99 KB
/
Copy pathDynamicIntializationofObjectsusingConstructors.cpp
File metadata and controls
77 lines (65 loc) · 1.99 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
#include<iostream>
using namespace std;
class SimpleInterest
{
float principal;
float rate;
int time;
float interest;
float amount;
public:
SimpleInterest(float p,int t,float r)
{
principal=p;
time=t;
rate=((float)r)*100;
interest=(principal*rate*time)/100;
amount=principal+interest;
}
SimpleInterest(float p,int t,int R)
{
principal=p;
time=t;
rate=R;
interest=(principal*rate*time)/100;
amount=principal+interest;
}
void show()
{
cout<<"The amount for the principal investment of "<<principal<<" for "<<time<<" years "<<" at rate of "<<rate<<" is"<<amount<<endl;
}
};
int main()
{
//SimpleInterest s1,s2;
float p;
int t;
float r;
int R;
cout<<"Enter p,time in years,r(in decimal):"<<endl;
cin>>p>>t>>r;
SimpleInterest s1(p,t,r);//SimpleInterest is like a data type,see it looks as if we are declaring a variable s1 with data type SimpleInterest
s1.show();
cout<<"Enter p,time in years,R(in %):"<<endl;
cin>>p>>t>>R;
SimpleInterest s2(p,t,R);//SimpleInterest is like a data type,see it looks as if we are declaring a variable s1 with data type SimpleInterest
s2.show();
return 0;
}
/*we can also do like below just replace BankDeposit with SimpleInterest
int main(){
BankDeposit bd1, bd2, bd3;//if we get errors by doing this way then make a default constructor in class and it will have nothing in the body
int p, y;
float r;
int R;
cout<<"Enter the value of p y and r"<<endl;
cin>>p>>y>>r;//dynamic intialization of objects happening here
bd1 = BankDeposit(p, y, r);
bd1.show();
cout<<"Enter the value of p y and R"<<endl;
cin>>p>>y>>R;
bd2 = BankDeposit(p, y, R);
bd2.show();
return 0;
}
*/