define a string class. overload the operator == to compare
two strings

Answers were Sorted based on User's Feedback



define a string class. overload the operator == to compare two strings..

Answer / mostafizur rahman

define a string class. overload the operator == to compare
two strings

Is This Answer Correct ?    59 Yes 30 No

define a string class. overload the operator == to compare two strings..

Answer / moin khan

#include <iostream>
using namespace std;
#include <string.h>
class String{
private:
enum { SZ = 80 };
char str[SZ];
public:
String(){ strcpy(str, ""); }
String( char s[] ){ strcpy(str, s); }
void display() const{ cout << str; }
void getstr(){ cin.get(str, SZ); }
bool operator == (String ss) const{
return ( strcmp(str, ss.str)==0 ) ? true : false;
}
};
int main(){
String s1 = "yes";
String s2 = "no";
String s3;

cout << "\nEnter 'yes' or 'no': ";
s3.getstr();

if(s3==s1)
cout << "You typed yes\n";
else if(s3==s2)
cout << "You typed no\n";
else
cout << "You didn't follow instructions\n";
return 0;
}

Is This Answer Correct ?    24 Yes 3 No

Post New Answer

More OOPS Interview Questions

What is a function in oop?

0 Answers  


In multilevel inheritance constructors will be executed from the .... class to ... class

2 Answers   ABCO, TCS,


What is interface in oop?

0 Answers  


What is encapsulation in oops?

0 Answers  


What is Dynamic Polymorphism?

13 Answers  






officer say me - i am offered to a smoking , then what can you say

0 Answers  


Why is polymorphism needed?

0 Answers  


The type of variable a pointer points to must be the part of pointer's definition so that:

1 Answers   Infosys,


OOP'S advantages of inheritance include:

1 Answers   Infosys,


What is a scope operator and tell me its functionality?

3 Answers   emc2,


What does and I oop mean?

0 Answers  


There are 2 empty jars of 5 and 3 liters capacity. And a river is flowing besides. I want to measure 4 liters of wanter using these 2 jars. How do you do this?

2 Answers  


Categories