forked from muskan09/CppCodes
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoperators.cpp
128 lines (110 loc) · 1.93 KB
/
operators.cpp
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*overloading the unary - operator*/
/*#include <iostream>
using namespace std;
class space
{
int a;
int b;
int c;
public:
space(int,int, int);
void display(void);
//void operator-();
friend void operator-(space&);
};
space::space(int x, int y, int z)
{
a=x;
b=y;
c=z;
}
void space::display(void)
{
cout<<"The values of the member variables are: "<<endl<<a<<endl<<b<<endl<<c<<endl;
}
//void space::operator-()
void operator- (space& s)
{
/*a=-a;
b=-b;
c=-c;*/
/* s.a=-s.a;
s.b=-s.b;
s.c=-s.c;
}
int main()
{
space S(1,2,3);
S.display();
-S;
S.display();
return 0;
}*/
//Adding two complex no objects using an overloaded + operator
/*#include <iostream>
using namespace std;
class comp
{
float r;
float i;
public:
comp(){}
comp(float, float);
//comp operator+(comp);
friend comp operator+(comp, comp);
void display(void);
};
comp::comp(float R, float I)
{
r=R;
i=I;
}
//comp comp::operator+(comp c2)
comp operator+(comp c1, comp c2)
{
/*comp temp;
//temp.r = r+ c2.r;
temp.r= c1.r + c2.r;
//temp.i = i+ c2.i;
temp.i= c1.i + c2.i;
return temp;*/
/* return comp((c1.r + c2.r),(c1.i + c2.i));
}
void comp::display(void)
{
cout<<endl<<"The complex number is: "<<r<<" + "<<i<<'i'<<endl<<endl;
}
int main()
{
comp C1(1,2);
cout<<"C1:";
C1.display();
comp C2(2,3);
cout<<"C2:";
C2.display();
comp C3=C1+C2;
cout<<"SUM:";
C3.display();
return 0;
}*/
/*#include <iostream>
using namespace std;
int main()
{
int a, b;
while(cin>>a>>b)
{
cout<<a+b<<endl<<endl;
}
return 0;
}*/
/*#include <stdio.h>
int main()
{
int a, b;
while(scanf("%d%d", &a, &b))
{
printf("%d\n\n", a+b);
}
return 0;
}*/