Wednesday, 18 May 2016

Write a program to implement following main() function: int main() { string str1(“CSE”),str2(“MCKVIE”); string str3; str3=str1+str2; return 0; }

#include<iostream.h>
#include<conio.h>
#include<string.h>

 class string{
public:
char str[100];
string(char *);
string(){
strcpy(str,"");
}
void operator=(const string);

string operator+(const string& s){
      string s1("");
      strcpy(s1.str,this->str);
      strcat(s1.str,s.str);
      return s1;

}
friend ostream &operator<<(ostream &output,const string s){
output<<s.str<<endl;
return output;
}


};

string::string(char *s){
strcpy(str,s);
}
void  string::operator=(const string s){

strcpy(this->str,s.str);

}
void main()
{

    string str1("CSE"),str2("MCKVIE");
    string str3;
    clrscr();
    str3=str1+str2;
    cout<<str3;
    getch();
}

No comments:

Post a Comment