stroka ifndef STROKA_H define STROKA_H class stroka protected char ch

 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//stroka h
#ifndef STROKA_H
#define STROKA_H
class stroka
{
protected:
char *ch;
int len;
public:
stroka();
stroka(char*);
stroka(char);
stroka(stroka& str);
~stroka();
void Clear();
int GetLen();
char* GetLine();
};
#endif
//stroka cpp
#include "stroka.h"
#include <string.h>
#include <stdio.h>
stroka::stroka()
{
len = 0;
ch = new char[1];
ch[0] = 0;
report("Worked stroka::stroka()");
}
stroka::stroka(char *s)
{
len = strlen(s);
ch = new char[len+1];
strcpy(ch,s);
ch[len] = 0;
report("Worked stroka::stroka(char *s)");
}
stroka::stroka(char c)
{
len = 1;
ch = new char[2];
ch[0] = c;
ch[1] = 0;
report("Worked stroka::stroka(char c)");
}
stroka::~stroka()
{
delete ch;
report("Worked stroka::~stroka()");
}
stroka::stroka(stroka &cp)
{
len=cp.GetLen();
ch=new char[len+1];
strcpy(ch,cp.GetLine());
report("Worked stroka::stroka(stroka &from)");
}
int stroka::GetLen(void)
{
return len;
}
char* stroka::GetLine(void)
{
return ch;
}
void stroka::Clear(void)
{
delete ch;
len = 0;
ch = new char[1];
ch[0] = 0;
report("Worked stroka::clear()");
}