You are on page 1of 7

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

h>

class string { char str[20]; public: void getdata(); void operator==(string); void operator=(string); string operator+(string); void operator>>(string); void operator-(string); void operator*(string); //equality //copy //concatenation //reverse a string //palindrome //substring

friend ostream&operator<<(ostream&zout,string&string); };

void string::getdata() { cout<<"\nenter the string: "; gets(str); }

void string::operator==(string s) {

//Equality

if(!strcmp(str,s.str)) { cout<<"\nstring are equal"; } else { cout<<"\nstring are not equal"; } }

void string::operator=(string s) { strcpy(str,s.str); }

//copy

string string::operator+(string s) { string temp; strcpy(temp.str,str); strcat(temp.str,s.str); return(temp); }

//concat

void string::operator>>(string s) { string temp; strcpy(temp.str,s.str); strrev(temp.str); cout<<temp.str; }

//reverse

void string:: operator-(string s) { string temp; strcpy(temp.str,s.str); strrev(s.str); if(!strcmp(temp.str,s.str))

// palindrome

cout<<"\nthe string is palindrome"; else cout<<"\nThe string is not palindrome"; }

void string::operator*(string s) // substring { int i; if(!strstr(str,s.str)) cout<<"\nsubstring is not present";

else { cout<<"\nsubstring is present"; // // // } } for(i=0;i<strlen(str);i++) { }

ostream&operator<<(ostream&zout,string&string) {

//Display

zout<<string.str; return(zout); }

void main() { int ch; string str1,str2,str3; clrscr(); do { cout<<"\n\n#####MENU####";

cout<<"\n1:Equality"; cout<<"\n2:copy"; cout<<"\n3:concatenation"; cout<<"\n4:reverse"; cout<<"\n5:palindrome"; cout<<"\n6:substring"; cout<<"\n7:exit";

cout<<"\nthe choice is yours:"; cin>>ch;

switch(ch) { case 1: { str1.getdata(); str2.getdata(); str1==str2; break; }

case 2: { str1.getdata(); str3.getdata();

str3=str1; cout<<"\nThe Copied String:"<<str3; break; }

case 3: { str1.getdata(); str2.getdata(); str3=str1+str2; cout<<"\nthe concated string is:"; cout<<str3; break; }

case 4: { str1.getdata(); cout<<"\nthe reverse is:"; str2>>str1; break; }

case 5: {

str1.getdata(); str1-str1; break; }

case 6: { str1.getdata(); str2.getdata(); str1*str2; break; } } }while(ch!=7); }

You might also like