24.03.2018, 10:52. Показов 1107. Ответов 0
Пытаюсь свою консольную программу переделать под интерфейс. В консоли все работает хорошо, но в переделанной программе подчеркивает строчку со структурой. В консольном структура находится в main и cpp-шнике. В интерфейсном не знаю куда поставить было бы правильно, поэтому оставил в функции нажатия на кнопку. Собственно вот и вопрос где описывать структуру. Я надеюсь, что объяснил правильно, ибо не до конца знаю терминологию.
код консоли:
| C++ |
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
| #include <iostream>
#include <fstream>
#include <iostream>
#include <ctime>
#include <iomanip>
#include <string>
#include <set>
#include <iterator>
#include <Windows.h>
using namespace std;
int main()
{
setlocale(LC_ALL, "rus");
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
ifstream file;
file.open("fin.txt");
int K;
char C;
char str[100];
set<char> mySet;
for (int i = 32; i < 127; i++)
{
mySet.insert(i);
}
if (file.is_open())
{
//// получаем вводные данные
cout << "Файл открыт\nВведите Символ\n";
cin >> C;
cout << "Введите номер строки\n";
cin >> K;
///// вытаскиваем нужную строку
for (int i = 0; i <= K - 1; i++)
{
file.getline(str, 100);
}
string Current_string = string(str);
cout << Current_string << endl;
////удаляем разделители
int j = 1;
while (j < Current_string.length())
{
if ((mySet.find(Current_string[j]) != mySet.end()) && (mySet.find(Current_string[j - 1]) != mySet.end()))
{
Current_string.erase(j, 1);
cout << Current_string << endl;
j--;
}
j++;
}
///////// убираем первый и последний пробел если они есть
if (Current_string[0] == ' ')
{
Current_string.erase(0, 1);
}
if (Current_string[Current_string.length()] == ' ')
{
Current_string.erase(Current_string.length(), 1);
}
//// в строке могли остаться унарные разделители а не пробелы, меняем оставшиеся разделители на пробелы
for (int i = 0; i < Current_string.length(); i++)
{
if (mySet.find(Current_string[i]) != mySet.end())
{
Current_string[i] = ' ';
}
}
cout << Current_string << endl;
////// меняем тип строки из string в чар
int size = Current_string.length();
cout << "Размер строки - " << size << endl;
char *str_end = new char[size];
for (int i = 0; i < size; i++)
{
str_end[i] = Current_string[i];
}
///// считаем количество пробелов
int Probel = 0;
for (int i = 0; i < size; i++)
{
if (Current_string[i] == ' ')
{
Probel++;
}
}
cout <<"Количество слов "<< Probel+1 << endl;
/////создаем массив обьектов из колличества равного количеству пробелов + 1
struct Word
{
string Name;
int dlina;
bool accept;
};
Word *array_of_word;
array_of_word = new Word[Probel+1];
//////Зануляем все значения в обьектах
for (int i = 0; i < Probel + 1; i++)
{
array_of_word[i].dlina = 0;
array_of_word[i].Name = "";
array_of_word[i].accept = false;
}
///////заполняем массив словами, длинами и доступом
int p = -1;
for (int i = 0; i < Probel + 1; i++)
{
p++;
while ((Current_string[p] != ' ' )&&(p < size))
{
array_of_word[i].Name = array_of_word[i].Name + Current_string[p];
p++;
array_of_word[i].dlina++;
if ((array_of_word[i].Name[0] == array_of_word[i].Name[array_of_word[i].dlina - 1]) && (array_of_word[i].Name[0] == C))
array_of_word[i].accept = true;
else
array_of_word[i].accept = false;
}
}
///////из слов с доступом опредиляем самое длинное
int end_i;
int max = 0;
for (int i = 0; i < Probel + 1; i++)
{
if ((array_of_word[i].accept == true) && (array_of_word[i].dlina > max))
{
max = array_of_word[i].dlina;
end_i = i;
}
}
if (max == 0)
{
cout << "Нет такого слова"<< endl;
}
else
{
for (int i = 0; i < Probel + 1; i++)
cout << "Слово под номером " << i + 1 << " такое: " << setw(8) << array_of_word[i].Name << " Длина строки: " << setw(2) << array_of_word[i].dlina << " Доступ: " << array_of_word[i].accept << endl;
cout << "искомое слово под номером " << end_i + 1 << " Имя: " << array_of_word[end_i].Name << endl;
}
}
else
{
cout << "Ошибка открытия";
}
file.close();
system("PAUSE");
} |
|
часть кода заголовочного файла в интерфейсном
| C++ |
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
| private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
using namespace std;
ifstream file;
file.open("fin.txt");
int K = Convert::ToDouble(textBox1->Text);
char C = Convert::ToChar(textBox2->Text);
char str[100];
set<char> mySet;
for (int i = 32; i < 127; i++)
{
mySet.insert(i);
}
if (file.is_open())
{
///// вытаскиваем нужную строку
for (int i = 0; i <= K - 1; i++)
{
file.getline(str, 100);
}
string Current_string = string(str);
cout << Current_string << endl;
////удаляем разделители
int j = 1;
while (j < Current_string.length())
{
if ((mySet.find(Current_string[j]) != mySet.end()) && (mySet.find(Current_string[j - 1]) != mySet.end()))
{
Current_string.erase(j, 1);
cout << Current_string << endl;
j--;
}
j++;
}
///////// убираем первый и последний пробел если они есть
if (Current_string[0] == ' ')
{
Current_string.erase(0, 1);
}
if (Current_string[Current_string.length()] == ' ')
{
Current_string.erase(Current_string.length(), 1);
}
//// в строке могли остаться унарные разделители а не пробелы, меняем оставшиеся разделители на пробелы
for (int i = 0; i < Current_string.length(); i++)
{
if (mySet.find(Current_string[i]) != mySet.end())
{
Current_string[i] = ' ';
}
}
cout << Current_string << endl;
////// меняем тип строки из string в чар
int size = Current_string.length();
cout << "Размер строки - " << size << endl;
char *str_end = new char[size];
for (int i = 0; i < size; i++)
{
str_end[i] = Current_string[i];
}
///// считаем количество пробелов
int Probel = 0;
for (int i = 0; i < size; i++)
{
if (Current_string[i] == ' ')
{
Probel++;
}
}
cout << "Количество слов " << Probel + 1 << endl;
/////создаем массив обьектов из колличества равного количеству пробелов + 1
struct Word
{
string Name;
int dlina;
bool accept;
};
Word *array_of_word;
array_of_word = new Word[Probel + 1];
//////Зануляем все значения в обьектах
for (int i = 0; i < Probel + 1; i++)
{
array_of_word[i].dlina = 0;
array_of_word[i].Name = "";
array_of_word[i].accept = false;
}
///////заполняем массив словами, длинами и доступом
int p = -1;
for (int i = 0; i < Probel + 1; i++)
{
p++;
while ((Current_string[p] != ' ') && (p < size))
{
array_of_word[i].Name = array_of_word[i].Name + Current_string[p];
p++;
array_of_word[i].dlina++;
if ((array_of_word[i].Name[0] == array_of_word[i].Name[array_of_word[i].dlina - 1]) && (array_of_word[i].Name[0] == C))
array_of_word[i].accept = true;
else
array_of_word[i].accept = false;
}
}
///////из слов с доступом опредиляем самое длинное
int end_i;
int max = 0;
for (int i = 0; i < Probel + 1; i++)
{
if ((array_of_word[i].accept == true) && (array_of_word[i].dlina > max))
{
max = array_of_word[i].dlina;
end_i = i;
}
}
if (max == 0)
{
cout << "Нет такого слова" << endl;
}
else
{
for (int i = 0; i < Probel + 1; i++)
cout << "Слово под номером " << i + 1 << " такое: " << setw(8) << array_of_word[i].Name << " Длина строки: " << setw(2) << array_of_word[i].dlina << " Доступ: " << array_of_word[i].accept << endl;
cout << "искомое слово под номером " << end_i + 1 << " Имя: " << array_of_word[end_i].Name << endl;
}
}
else
{
cout << "Ошибка открытия";
}
file.close();
} |
|