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 variable example?

0 Answers  


What are the three parts of a simple empty class?

0 Answers  


What is a function in oop?

0 Answers  


What is Inheritance, Multiple Inheritance, Shared and Repeatable Inheritance?

4 Answers   Accenture, L&T,


What is the difference between class and object?

4 Answers   Apple, Heinz,






what are the realtime excercises in C++?

0 Answers   IBM, Wipro,


why in java first invoke public static void main(String args[]) method????Why not public static void method1(String args[])??

1 Answers  


what is virtual function?

26 Answers   Aspire, HP, Infosys, RoboSoft, TCS,


Difference between realloc() and free?

9 Answers   HP,


How is class defined?

0 Answers  


WILL I GET A guaranteed JOB AFTER DOING bsc()IT) and GNIIT from an NIIT CENTRE??

21 Answers   Biocon, MIT, NIIT,


What is an interface in oop?

0 Answers  


Categories