forked from angminsheng/Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OVERLOAD.CPP
102 lines (102 loc) · 1.78 KB
/
OVERLOAD.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
#include<iostream.h>
#include<process.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
class str
{
char a[40],b[40],c[40];
public:
str()
{
strcpy(a,"\0");
strcpy(b,"\0");
strcpy(c,"\0");
}
void get1();
void get2();
void get3();
void operator+(str);
void operator=(str);
int operator==(str);
};
void str::operator+(str s1)
{
str s2;
strcat(a,s1.a);
strcat(s2.a,a);
cout<<"\nThe concatenated string is:";
cout<<s2.a;
}
void str::operator=(str s1)
{
strcpy(s1.c,c);
cout<<"\nThe original string is:"<<c;
cout<<"\nThe copied string is:"<<s1.c;
}
int str::operator==(str s1)
{
if(strcmp(b,s1.b)==0)
return 1;
else
return 0;
}
void str::get1()
{
cout<<"\nEnter value:";
gets(a);
cout<<"\nThe length of the string is:"<<strlen(a);
cout<<"\n**********************************\n";
}
void str::get2()
{
cout<<"\nEnter value:";
gets(b);
cout<<"\nThe length of the string is:"<<strlen(b);
cout<<"\n**********************************\n";
}
void str::get3()
{
cout<<"\nEnter value:";
gets(c);
cout<<"\nThe length of the string is:"<<strlen(c);
cout<<"\n**********************************\n";
}
void main()
{
clrscr();
int ch;
str o1,o2;
while(1)
{
cout<<"\nString operators in the choice are:";
cout<<"\n1.concatenation\n2.Comparision\n3.Copy\n4.Exit\n";
cout<<"\nEnter your choice:";
cin>>ch;
switch(ch)
{
case 1: cout<<"\nValue for object 1:";
o1.get1();
cout<<"\nValue for object 2:";
o2.get1();
o1+o2;
break;
case 2: cout<<"\nValue for object 1:";
o1.get2();
cout<<"\nValue for object 2:";
o2.get2();
if(o1==o2)
cout<<"\nThe two strings are equal";
else
cout<<"\nThe two strings are not equal";
break;
case 3: cout<<"\nValue for object 1:";
o1.get3();
o1=o2;
break;
case 4: exit(0);
break;
}
}
getch();
}