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 |
namespace is working on which compiler?
What is the real life example of polymorphism?
how much classes are used in c++
What is the use of unnamed namespaces in OOPS? The only advantage I know is that they dont need the scope resolution operator while accessing them. I want to know some other advantages of unnamed namespaces...
Who invented oop?
What is oops in simple words?
what is abstract class ? when is used in real time ? give a exp
which feature are not hold visual basic of oop?
Have you ever interfaced with a database?
What type of Job you are providing?
what is difference between thread and programme.
Round up a Decimal number in c++.. example Note = 3.5 is as 4 3.3 is as 3
3 Answers Accenture, Cognizant, IBM,