-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractice_06.cpp
More file actions
47 lines (46 loc) · 892 Bytes
/
Practice_06.cpp
File metadata and controls
47 lines (46 loc) · 892 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
// Write a program that overloads the comparison operators == to work with String class. The result of comparison must be 1 if two strings are of same length and 0 otherwise.
#include<iostream>
#include<string>
using namespace std;
class String
{
private:
string str;
public:
String()
{
str = "";
}
void in()
{
cout<<"Enter String: ";
getline(cin, str);
}
void show()
{
cout<<str<<endl;
}
int operator ==(String s)
{
if(str == s.str){
return 1;
}
else{
return 0;
}
}
};
int main(){
String s1, s2;
s1.in();
s2.in();
cout<<"s1 = ";
s1.show();
cout<<"s2 = ";
s2.show();
if (s1 == s2)
cout<<"Both strings are of equal length!";
else
cout<<"Both strings are of different length!";
return 0;
}