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 the use of classes in c++;
What is memory leak and memory corruption?
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
how to swap to variables without using thrid variable in java?
What makes a language oop?
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.
What exactly is polymorphism?
What is debug class?what is trace class? What differences are between them? With examples.
What are main features of oop?
write a program that takes input in digits and display the result in words from 1 to 1000
can we create and enter the data & hide files using programmes ?