define a string class. overload the operator == to compare
two strings
Answers were Sorted based on User's Feedback
Answer / mostafizur rahman
define a string class. overload the operator == to compare
two strings
| Is This Answer Correct ? | 59 Yes | 30 No |
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 |
Which is not an object oriented programming language?
How to overload new operator in c++
Pls...could any one tell me that whether we can access the public data memeber of a class from another class with in the same program. Awaiting for your response Thanku
what is the advantage in software? what is the difference between the software developer and Engineer
What is sub classing in c++?
what is an instance of a class
how to create thread in java?
17 Answers IBM, Infosys, Wipro,
Can we define a class within the interface?
What are generic functions and generic classes?
What is overriding in oops?
What is virtual destructor? Why?
3 Answers Agile Software, College School Exams Tests, CSC,
How to call a non virtual function in the derived class by using base class pointer