Created
September 30, 2013 21:34
-
-
Save somratcste/6770638 to your computer and use it in GitHub Desktop.
This problem is basis on one string is user input, another is defined by two object and this two other concatenation by another object is done by this program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstring> | |
using namespace std; | |
static const int string1=1; | |
static const int string2=2; | |
static const int string3=3; | |
class str | |
{ | |
public : | |
int l; | |
char mystr[40]; | |
char mystr1[40]; | |
str() | |
{ | |
l=0; | |
cout<<"Pls enter your first string : "<<endl; | |
cin.getline(mystr,40); | |
} | |
str(char *s) | |
{ | |
l=strlen(s); | |
strcpy(mystr1,s); | |
} | |
void concat(str r, str t); | |
}; | |
void str::concat(str r, str t) | |
{ | |
strcat(r.mystr," "); | |
strcat(r.mystr,t.mystr1); | |
cout<<endl<<endl<<r.mystr<<endl<<endl; | |
} | |
int show(str p,str q) | |
{ | |
int index; | |
while(true) | |
{ | |
cout<<endl<<endl<<"1 for string 1"<<endl<<"2 for string 2"<<endl; | |
cout<<"3 for string concatenation"<<endl; | |
cout<<"4 for exit the programe."<<endl; | |
cout<<"What do you want : "; | |
cin>>index; | |
switch(index) | |
{ | |
case string1: | |
cout<<endl<<endl<<p.mystr<<endl<<endl; | |
break; | |
case string2: | |
cout<<endl<<endl<<q.mystr1<<endl<<endl; | |
break; | |
case string3: | |
p.concat(p,q); | |
break; | |
default : | |
cout<<endl<<endl<<"Thanks for your operation"<<endl; | |
return 0; | |
} | |
} | |
} | |
int main() | |
{ | |
str o,o1("Hello world"); | |
show(o,o1); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment