-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex02.cpp
More file actions
51 lines (43 loc) · 865 Bytes
/
Copy pathex02.cpp
File metadata and controls
51 lines (43 loc) · 865 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
47
48
49
50
51
#include <iostream>
#include <cstring>
using namespace std;
class String {
private:
static const int SZ = 80;
char str[SZ];
public:
String() { strcpy(str, ""); }
String(char s[]) { strcpy(str, s); }
void display() const { cout << str; }
String operator+=(String s) {
if (strlen(str) + strlen(s.str) < SZ) {
strcat(str, s.str);
} else {
cout << "\nПереполнение!";
exit(1);
}
return String(str);
}
};
int main() {
String s1 = "С Рождеством! ";
String s2 = "С Новым годом! ";
String s3;
s1.display();
cout << endl;
s2.display();
cout << endl << endl;
s1 += s2;
s1.display();
cout << endl;
s2.display();
cout << endl << endl;
s3 = s1 += s2;
s1.display();
cout << endl;
s2.display();
cout << endl;
s3.display();
cout << endl;
return 0;
}