Форум программистов, компьютерный форум, киберфорум
С++ для начинающих
Войти
Регистрация
Восстановить пароль
Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.60/5: Рейтинг темы: голосов - 5, средняя оценка - 4.60
11 / 6 / 7
Регистрация: 06.10.2016
Сообщений: 65

Где здесь ошибки? Почему крашится?

14.12.2016, 20:12. Показов 961. Ответов 2

Студворк — интернет-сервис помощи студентам
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#include "stdafx.h"
#include <math.h>
#include <iostream>
#define MAX_DEGREE 340
#define MAX_LINE 4
using namespace std;
 
struct Pos
{
    float x, y;
    Pos(void){x=0;y=0;}
    Pos(float _x, float _y){x=_x; y=_y;}
    void operator= (Pos& apos){x = apos.x; y = apos.y;}
    void Print(int level, int count)
    {
        printf("Level %i count %i posX %f posY %f \n",level,count, x, y);
    }
};
 
class Node
{
public:
    class Iterator
    {
    public:
        Node* current;
        int index;
        int level;
 
        Iterator(){current = NULL; index = 0; level = 0;}
        ~Iterator(){}
 
        void operator= (Iterator &it);
        bool operator!= (Iterator &it);
        Iterator& operator++(int k);
        void NextNode();
        void NextLine();
        bool EndLine();
    };
public:
    Node(void);
    ~Node(void);
    void Set();
    void Find(int level, int& count);
    bool Check();
    Iterator begin(){return m_begin;}
    Iterator end(){return m_end;}
protected:
    void MakeThree(int degree, Node* root, Pos pos);
protected:
    Node* ch1;
    Node* ch2;
    Node* ch3;
    Node* ch4;
    Node* m_root;
    Pos m_Pos;
    int index;
    Iterator m_begin;
    Iterator m_end;
};
 
void Node::Iterator::operator=( Iterator &it )
{
    current = it.current;
    level = it.level;
    index = it.index;
}
 
bool Node::Iterator::operator!=( Iterator &it )
{
    if (current != it.current)
        return true;
    else
        return false;
}
 
Node::Iterator& Node::Iterator::operator++( int k )
{
    if (current->m_root == NULL)
    {
        current = current->ch1;
        level++;
        index++;
        return *this;
    }
    if (current == current->m_root->ch1)
    {
        current = current->m_root->ch2;
        index++;
        return* this;
    }
    if (current == current->m_root->ch2)
    {
        current = current->m_root->ch3;
        index++;
        return* this;
    }
    if (current == current->m_root->ch3)
    {
        current = current->m_root->ch4;
        index++;
        return* this;
    }
    if (current == current->m_root->ch4)
    {
        NextNode();
        return* this;
    }
}
 
void Node::Iterator::NextNode()
{
    if (current->m_root->m_root == NULL)
        NextLine();
    if (current == current->m_root->m_root->ch1->ch4)
    {
        current = current->m_root->m_root->ch2->ch1;
        index++;
    }
    if (current == current->m_root->m_root->ch2->ch4)
    {
        current = current->m_root->m_root->ch3->ch1;
        index++;
    }
    if (current == current->m_root->m_root->ch3->ch4)
    {
        current = current->m_root->m_root->ch4->ch1;
        index++;
    }
    if (current == current->m_root->m_root->ch4->ch4)
    {
        if (EndLine())
        {
            NextLine();
        }
        else
        {
            NextNode();
        }
    }
}
 
bool Node::Iterator::EndLine()
{
    Node* root /*= current->m_root*/;
    while (root->m_root->m_root != NULL)
    {
        if (root == root->m_root->ch4)
            root = root->m_root;
        else 
            return false;
    }
    return true;
}
 
void Node::Iterator::NextLine()
{
    if (level == MAX_LINE)
    {
        current = NULL;
        return;
    }
    while(current->m_root != NULL)
    {
        current = current->m_root;
    }
    for (int i = 0; i <= level+1; i++)
    {
        current = current->ch1;
    }
    level++;
    index++;
    return;
}
 
Node::Node( void )
{
    ch1 = NULL;
    ch2 = NULL;
    ch3 = NULL;
    ch4 = NULL;
    m_root = NULL;
    m_Pos;
    index = 0;
    m_end.current = NULL;
}
 
Node::~Node( void )
{
}
 
void Node::Set()
{
    int degree = 16;
    m_begin.current = this;
    MakeThree(degree, NULL, m_Pos);
}
 
void Node::MakeThree( int degree, Node* root, Pos pos )
{
    if(degree%2 != 0)
        return;
    m_root = root;
    ch1 = new Node;
    ch1->m_Pos = Pos(m_Pos.x+(float)degree/4, m_Pos.y +(float)degree/4);
    ch2 = new Node;
    ch2->m_Pos = Pos(m_Pos.x + (float)degree/4, m_Pos.y - (float)degree/4);
    ch3 = new Node;
    ch3->m_Pos = Pos(m_Pos.x - (float)degree/4, m_Pos.y - (float)degree/4);
    ch4 = new Node;
    ch4->m_Pos = Pos(m_Pos.x - (float)degree/4, m_Pos.y + (float)degree/4);
    ch1->MakeThree(degree/2, this, ch1->m_Pos);
    ch2->MakeThree(degree/2, this, ch2->m_Pos);
    ch3->MakeThree(degree/2, this, ch3->m_Pos);
    ch4->MakeThree(degree/2, this, ch4->m_Pos);
}
 
void Node::Find( int level, int& count )
{
    if(!Check())
        return;
    ch1->m_Pos.Print(level, count++);
    ch2->m_Pos.Print(level, count++);
    ch3->m_Pos.Print(level, count++);
    ch4->m_Pos.Print(level, count++);
    ch1->Find(level+1, count);
    ch2->Find(level+1, count);
    ch3->Find(level+1, count);
    ch4->Find(level+1, count);
}
 
bool Node::Check()
{
    if((ch1!=NULL)&&(ch2!=NULL)&&(ch3 != NULL)&&(ch4!=NULL))
        return true;
    else
        return false;
}
 
 
 
int main()
{
    setlocale(LC_ALL, "RUSSIAN");
    system("color E");
 
    Node Three;
    Three.Set();
    Node::Iterator It;
    It = Three.begin();
    for (;It != Three.end();It++)
    {
        cout<<It.index<<" "<<It.level<<" ";
        cout<<endl;
    }
    
    return 0;
}
0
Лучшие ответы (1)
cpp_developer
Эксперт
20123 / 5690 / 1417
Регистрация: 09.04.2010
Сообщений: 22,546
Блог
14.12.2016, 20:12
Ответы с готовыми решениями:

Структура ( где здесь ошибки?)
struct { int a, int b, }z; помогите разобраться, где здесь ошибки?

Где здесь ошибки? Файлы
Подскажите, пожалуйста, где здесь ошибки. Условие: считать текст из файла и вывести на экран количество вхождений заданного слова в текст и...

Код крашится при вводе ЛЮБОГО значения, не могу понять почему
#include &lt;iostream&gt; #include &lt;string&gt; #include &lt;windows.h&gt; using namespace std; main() { int pos;

2
 Аватар для Людвиг Бодмер
378 / 375 / 213
Регистрация: 29.03.2013
Сообщений: 867
14.12.2016, 21:21
Лучший ответ Сообщение было отмечено Whitemorn как решение

Решение

Whitemorn, так а почему в 145 строке инициализация закомментирована?
1
11 / 6 / 7
Регистрация: 06.10.2016
Сообщений: 65
15.12.2016, 15:14  [ТС]
Что с инициализацией, что без нее она крашится

Добавлено через 24 секунды
Цитата Сообщение от Людвиг Бодмер Посмотреть сообщение
так а почему в 145 строке инициализация закомментирована?
Добавлено через 12 минут
Раскомментировал инициализацию, все норм, но программа завершается на третьей ветке чилдов, а должна вывести 4 ветки
0
Надоела реклама? Зарегистрируйтесь и она исчезнет полностью.
raxper
Эксперт
30234 / 6612 / 1498
Регистрация: 28.12.2010
Сообщений: 21,154
Блог
15.12.2016, 15:14
Помогаю со студенческими работами здесь

Какие здесь ошибки
1) int main() { Node *p1, *p2; p1 = new Node; p2 = new Node; p1-&gt;Data = 11; p2-&gt;Data = 22; p1-&gt;Next = p2; p2-&gt;Next = NULL; cout &lt;&lt;...

Где здесь ошибка?
Делаю все по видео уроку. У него работает все нормально у меня жалуется #include &lt;allegro.h&gt; #define MAXFILAS 20 // X ...

Где здесь ошибка
под &quot;а&quot; #include &lt;iostream&gt; #include &lt;math.h&gt; #include &lt;time.h&gt; using namespace std; int main() { setlocale(0, &quot;rus&quot;); ...

где здесь ошибка?
решил сделать программку каторая считает каличество счасливых белетеков в сериии то есть от 000000 до 999999 при этом считается что белет...

Функция. Где здесь ошибка?
using namespace std; int main () { float x,y,z; cout &lt;&lt;&quot;x=&quot;; cin &gt;&gt;x; cout &lt;&lt;&quot;y=&quot;; cin &gt;&gt;y; ...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
3
Ответ Создать тему
Новые блоги и статьи
Конвертировать закладки radiotray-ng в m3u-плейлист
damix 19.02.2026
Это можно сделать скриптом для PowerShell. Использование . \СonvertRadiotrayToM3U. ps1 <path_to_bookmarks. json> Рядом с файлом bookmarks. json появится файл bookmarks. m3u с результатом. # Check if. . .
Семь CDC на одном интерфейсе: 5 U[S]ARTов, 1 CAN и 1 SSI
Eddy_Em 18.02.2026
Постепенно допиливаю свою "многоинтерфейсную плату". Выглядит вот так: https:/ / www. cyberforum. ru/ blog_attachment. php?attachmentid=11617&stc=1&d=1771445347 Основана на STM32F303RBT6. На борту пять. . .
Символьное дифференцирование
igorrr37 13.02.2026
/ * Программа принимает математическое выражение в виде строки и выдаёт его производную в виде строки и вычисляет значение производной при заданном х Логарифм записывается как: (x-2)log(x^2+2) -. . .
Камера Toupcam IUA500KMA
Eddy_Em 12.02.2026
Т. к. у всяких "хикроботов" слишком уж мелкий пиксель, для подсмотра в ESPriF они вообще плохо годятся: уже 14 величину можно рассмотреть еле-еле лишь на экспозициях под 3 секунды (а то и больше),. . .
И ясному Солнцу
zbw 12.02.2026
И ясному Солнцу, и светлой Луне. В мире покоя нет и люди не могут жить в тишине. А жить им немного лет.
«Знание-Сила»
zbw 12.02.2026
«Знание-Сила» «Время-Деньги» «Деньги -Пуля»
SDL3 для Web (WebAssembly): Подключение Box2D v3, физика и отрисовка коллайдеров
8Observer8 12.02.2026
Содержание блога Box2D - это библиотека для 2D физики для анимаций и игр. С её помощью можно определять были ли коллизии между конкретными объектами и вызывать обработчики событий столкновения. . . .
SDL3 для Web (WebAssembly): Загрузка PNG с прозрачным фоном с помощью SDL_LoadPNG (без SDL3_image)
8Observer8 11.02.2026
Содержание блога Библиотека SDL3 содержит встроенные инструменты для базовой работы с изображениями - без использования библиотеки SDL3_image. Пошагово создадим проект для загрузки изображения. . .
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2026, CyberForum.ru