-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet_Set.cpp
More file actions
86 lines (66 loc) · 1.53 KB
/
Get_Set.cpp
File metadata and controls
86 lines (66 loc) · 1.53 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
#include<iostream>
using namespace std;
class Complex{
int real, img;
public:
//CONSTRUCTOR
Complex();
Complex(int real, int img);
//DESTRUCTOR
~Complex(){
cout<<"Destructor called "<<this<<endl<<endl;
}
//GETTER
int getReal();
int getImg();
//SETTER
void setReal(int real);
void setImg(int img);
//FACILITATOR
void accept();
void disp();
};
Complex::Complex(){
real=10;
img=20;
}
Complex::Complex(int real, int img){
this->real=real;
this->img=img;
}
int Complex::getReal(){
return this->real;
}
int Complex::getImg(){
return this->img;
}
void Complex::setReal(int real){
this->real=real;
}
void Complex::setImg(int img){
this->img=img;
}
void Complex::accept(){
cout<<"Enter real value: ";
cin>>this->real;
cout<<"Enter imaginary value: ";
cin>>this->img;
}
void Complex::disp(){
cout<<"\nReal value = "<<real<<" Imaginary value = "<<img<<endl<<endl;
}
int main(){
Complex c;
c.setImg(400); //set individual/specific value
c.disp();
Complex c1(100,200);
int r=c1.getReal(); //fetch individual/specific value
cout<<"Real value of object c1 = "<<r<<endl;
int i=c1.getImg();
cout<<"Imaginary value object c1 = "<<i<<endl<<endl;
Complex c2;
c2.accept();
c2.setImg(90);
c2.disp();
return 0;
}