forked from rahulgoyal911/cPlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinaryOpOver.cpp
More file actions
146 lines (132 loc) · 1.8 KB
/
BinaryOpOver.cpp
File metadata and controls
146 lines (132 loc) · 1.8 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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//binary operator overloading
//+ - / *
//to add two complex numbers
//we will always do this with return value
//edited
using namespace std;
//
#include<iostream>
//with return value
/*
class complex
{
private:
int a,b;
public:
complex():a(0),b(0)
{
}
complex(int x,int y):a(x),b(y)
{
}
void put()
{
cout<<a<<" +i"<<b;
}
complex operator+(complex ob);
//{
//defined outside
//}
};
complex complex::operator+(complex ob)
{
//temp object or anonymous object
return complex(a+ob.a,b+ob.b);
}
int main()
{
int x,y;
cin>>x>>y;
complex c1(x,y);
cin>>x>>y;
complex c2(x,y);
complex c;
c=c1+c2;
c.put();
return 0;
}
*/
/*
//friend+return type
class complex
{
private:
int a,b;
public:
complex():a(0),b(0)
{
}
complex(int x,int y):a(x),b(y)
{
}
void put()
{
cout<<a<<" +i"<<b;
}
friend complex operator+(complex ob,complex ob1)
{
return complex(ob1.a+ob.a,ob1.b+ob.b);
}
};
int main()
{
int x,y;
cin>>x>>y;
complex c1(x,y);
cin>>x>>y;
complex c2(x,y);
complex c;
c=c1+c2;
c.put();
return 0;
}
*/
//RELATIONAL OPERAION IN STRING
#include<string.h>
class string1
{
int len;
char *name;
public:
string1()
{
len=0;
name= new char;
}
string1(char *s)
{
len=strlen(s);
name=new char[len+1];
strcpy(name,s);
}
string1 operator+(string1 &ob)
{
string1 t;
t.len=len+ob.len;
//delete name;
t.name = new char[t.len+1];
strcpy(t.name,name);
strcat(t.name,ob.name);
ob=t;
return ob;
}
void put()
{
cout<<name;
}
};
int main()
{
//we have to do typecasting here
char *h=((char *)"hello");
string1 a(h);
string1 b((char *)"bye");
string1 c;
c=a+b;
//a is calling function and b is passed as argument
// if(a==b)
// cout<<"Equal"<<endl;
// if(a<=b)
// cout<<"Less than"<<endl;
c.put();
}