-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask4.cpp
More file actions
127 lines (115 loc) · 2.38 KB
/
task4.cpp
File metadata and controls
127 lines (115 loc) · 2.38 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//
// main.cpp
// task4.4
//
// Created by Nikita Kolmakov on 16.05.2018.
// Copyright © 2018 Interesting Com. All rights reserved.
//
#include <iostream>
#include <stdlib.h>
#include <fstream>
#define MAXSIZE 255
//если кол-во символов в строке = 10, то удалить символы A -> Z;
using namespace std;
class Line{
public:
int k = 0;
char *str;
char *retstr;
Line();
~Line();
Line(char*);
void set(char*);
void run();
void print();
string print1();
};
Line::Line(){
str=new char[MAXSIZE];
str[0]='\0';
retstr=new char[MAXSIZE];
retstr[0]='\0';
};
Line::Line(char *s){
str=new char[MAXSIZE];
strcpy(str,s);
retstr=new char[MAXSIZE];
retstr[0]='\0';
};
void Line::run() {
if((strlen(str) == 10))
{
int j = 0;
for(unsigned int i = 0; i < strlen(str); i++) {
if ((*(str + i) < 65) || (*(str + i) > 90)) {
*(retstr + j++ ) = *(str + i);
*(retstr + j) = '\0';
}
}
}
else
{
k = 1;
cout << "Количество элементов не равняется 10" << endl;
}
}
void Line::set(char* s) {
strcpy(str, s);
}
void Line::print()
{
if (strlen(str) != 10) {
cout << str << endl;
} else {
cout << retstr << endl;
}
}
string Line::print1() {
return retstr;
}
Line::~Line() {
delete [] str;
// cout << "... free space was delete" << endl;
}
class Pereg {
char *str;
int k;
public:
Pereg(const char* s = "")
{
k = (int)strlen(s);
str = new char [k + 1];
strcpy(str,s);
}
Pereg& operator=(const Pereg& s)
{
if(k != s.k)
{
k = s.k;
delete[] str;
str = new char [k];
}
strcpy(str,s.str);
return (*this);
}
};
int main() {
setlocale(0,"");
ofstream file1("first.txt");
ofstream file2("second.txt");
char s[265];
cout << "Enter string"<<endl;
cin.getline(s,256);
Line str(s);
str.run();
cout << "Вывод при косвенном вызове:" <<endl;
str.print();
Line *obj = new Line();
obj -> set(s);
obj -> run();
cout << "Вывод при прямом вызове" << endl;
obj -> print();
file1 << s;
file2 << obj -> print1();
return 0;
}