-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path25object_in_func_arg.cpp
More file actions
44 lines (40 loc) · 858 Bytes
/
Copy path25object_in_func_arg.cpp
File metadata and controls
44 lines (40 loc) · 858 Bytes
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
#include<iostream>
using namespace std;
class complex
{
int a, b;
public:
void setData(int i, int r)
{
a = r;
b = i;
}
void complexsum(complex ob1, complex ob2) //here we passed objects as formal arguments in a class function
{
a = ob1.a + ob2.a;
b = ob1.b + ob2.b;
}
void printcomplex()
{
cout<<"z1 + z2 = "<<a<<" + "<<b<<"i"<<endl;
}
void printcomplexz1()
{
cout<<"z1 = "<<a<<" + "<<b<<"i"<<endl;
}
void printcomplexz2()
{
cout<<"z2 = "<<a<<" + "<<b<<"i"<<endl;
}
};
int main()
{
complex z1, z2, z3;
z1.setData(3, 7);
z1.printcomplexz1();
z2.setData(9, 5);
z2.printcomplexz2();
z3.complexsum(z1, z2); //here we passed objects as actual arguments in a class function
z3.printcomplex();
return 0;
}