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 runtime polymorphism? For the 5 marks.
when to use 'mutable' keyword and when to use 'const cast' in c++
Why is polymorphism important in oop?
What is protected in oop?
What is overriding in oops?
Write a program to demonstrate the use of 'Composition' in C++
what is the 3 types of system development life cycle
What is coupling in oops?
Write a C++ program without using any loop (if, for, while etc) to print prime numbers from 1 to 100 and 100 to 1 (Do not use 200 print statements!!!)
What are the 4 pillars of oop?
What is abstraction?
What is constructor overloading in oop?