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 the use of classes in c++;

2 Answers   HCL,


What is memory leak and memory corruption?

1 Answers   TCS,


Write a C++ program to conduct an election of a mayor.Declare a class ELECTION With the following specification: Data member: Name 25 character Age Integer symbol 1 character Member functions: To accept data for 20 contestant To accept symbol as voting from 100 voters. To declare the winner and the loser.

1 Answers   Global Academy, Infotech,


what is the definition of incapsulation

2 Answers  


how to swap to variables without using thrid variable in java?

5 Answers  






What makes a language oop?

0 Answers  


C#.net Interview Question A=10 B=5 C=A+B Print C The above will be given in a multiline textbox. You need to parse the above input, store values for A,B&c. And you have to display the value of C.

1 Answers   Syncfusion,


What exactly is polymorphism?

0 Answers  


What is debug class?what is trace class? What differences are between them? With examples.

0 Answers  


What are main features of oop?

0 Answers  


write a program that takes input in digits and display the result in words from 1 to 1000

0 Answers   Wipro,


can we create and enter the data & hide files using programmes ?

2 Answers   Wipro,


Categories