-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass16.cpp
More file actions
50 lines (45 loc) · 935 Bytes
/
Copy pathclass16.cpp
File metadata and controls
50 lines (45 loc) · 935 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
45
46
47
48
49
50
//overloading of Insertion<< and Extraction>> operators
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
class complex
{
private:
int a,b;
public:
void setData(int x,int y)
{
a = x;
b = y;
}
void showData()
{
cout<<" a = "<<a<<" b = "<<b<<endl;
}
//for overloading friend function defining here
friend ostream& operator<<(ostream&,complex);
friend istream& operator>>(istream&,complex&);
};
//defining outside of the class
ostream& operator<< (ostream &dout,complex c)
{
cout<<endl<<"a = "<<c.a<<" b = "<<c.b;
return dout;
}
istream& operator>>(istream &din,complex &c)
{
cin>>c.a>>c.b;
return din;
}
int main(int argc, char const *argv[])
{
system("cls");
complex c1;
cout<<"Enter complex number ";
cin>>c1;
cout<<" you have entered ";
cout<<c1;
system("pause");
return 0;
}