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 persistence in oop?

0 Answers  


What is the difference between and interface and an abstract class ?

4 Answers   IBM, Infosys, Ness Technologies,


What is class and object with example?

0 Answers  


write a program in c++ to overload the function add (s1,s2) where s1 and s2 are integers and floating point values.

4 Answers  


ambiguity regulation of multiple inheritance with example.

1 Answers  


Finding of the 4 larger (bigger) numbers from the list like{1245,4587,2145,1163,29987,65783.....}

1 Answers   Wipro,


what is oops

4 Answers   NIIT,


What is encapsulation oop?

0 Answers  


What is interface? When and where is it used?

0 Answers  


How can i write a code in c# to take a number from the user and then find all the prime numbers till the number entered by the user.

4 Answers   NIIT, TCS,


write a code for this. serial_number contained in the header of the file will be read , if this serial number is less than a previous serial number within a successfully processed file, or is the same as another serial number within a successfully processed file, or if the field contains anything other than 7 digits, then the file must error with the reason ‘Invalid SERIAL_NUMBER’.

0 Answers   Microsoft, TCS,


What is a class?

32 Answers   Infosys, TCS, Thylak,


Categories