-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass23.cpp
50 lines (48 loc) · 923 Bytes
/
class23.cpp
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
47
48
49
50
#include<iostream>
#include<string.h> //program for constructors with new
using namespace std;
class strin
{
char *name;
int length;
public:
strin()
{
length = 0;
name = new char[length+1];
}
strin(char *s)
{
length =strlen(s);
name =new char[length+1];
strcpy(name,s);
}
void display()
{
cout<<name<<"\n";
}
void join(strin &a,strin &b);
};
void strin :: join(strin &a,strin &b)
{
length = a.length + b.length;
delete name;
name = new char[length];
strcpy(name,a.name);
strcat(name,b.name);
}
int main()
{
char *first="Joseph";
strin name1(first),name2("Louis"),name3("Langrage"),s1,s2;
s1.join(name1,name2);
s2.join(s1,name3);
name1.display();
name2.display();
name3.display();
cout<<"\n";
s1.display();
cout<<endl;
s2.display();
return 0;
}