-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinbuiltStringfunctionsDemo
More file actions
46 lines (46 loc) · 913 Bytes
/
inbuiltStringfunctionsDemo
File metadata and controls
46 lines (46 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <string.h>
#include <iomanip>
#define MAX 80
using namespace std;
class STRING
{
char str[MAX];
public:
STRING()
{
str[0]='\0';
}
STRING(const char pstr[])
{
strcpy(str,pstr);
}
STRING strconcat(STRING X)
{
STRING temp;
if(strlen(str)+strlen(X.str)<MAX)
{
strcpy(temp.str,str);
strcat(temp.str,X.str);
}
return temp;
}
void display()
{
cout<<setw(30)<<"The string is:\t"<<str<<endl;
}
};
int main()
{
STRING S1,S2("rachel"),S3("green");
cout<<"The uninitialized string for object S1 using constructor with no arg is:"<<endl;
S1.display();
cout<<"The initialized string for object S2 using parametrized constructor is:"<<endl;
S2.display();
cout<<"The initialized string for object S3 using parametrized constructor is:"<<endl;
S3.display();
cout<<endl<<"Concatenating object S2 with object S3"<<endl;
S1 = S2.strconcat(S3);
S1.display();
return 0;
}