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 |
What is persistence in oop?
What is the difference between and interface and an abstract class ?
4 Answers IBM, Infosys, Ness Technologies,
What is class and object with example?
write a program in c++ to overload the function add (s1,s2) where s1 and s2 are integers and floating point values.
ambiguity regulation of multiple inheritance with example.
Finding of the 4 larger (bigger) numbers from the list like{1245,4587,2145,1163,29987,65783.....}
what is oops
What is encapsulation oop?
What is interface? When and where is it used?
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.
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’.
What is a class?
32 Answers Infosys, TCS, Thylak,