Форум программистов, компьютерный форум, киберфорум
С++ для начинающих
Войти
Регистрация
Восстановить пароль
Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.63/8: Рейтинг темы: голосов - 8, средняя оценка - 4.63
0 / 0 / 0
Регистрация: 23.04.2016
Сообщений: 8

Класс "Список окон"

23.04.2016, 12:48. Показов 1638. Ответов 11
Метки нет (Все метки)

Студворк — интернет-сервис помощи студентам
Здравствуйте, есть довольно большое задание, код которого почти полностью представлен ниже:

Задание

1. Создать класс Прямоугольник, который имеет координаты верхнего левого и нижнего правого угла, цвет фона.

2. Определить конструкторы инициализации, копирования, деструкторы и методы для изменения и чтения значений полей этого класса.

3. Перегрузить операцию ++ для пропорционального увеличения окна, — для уменьшения окна, * для

перемещения окна, операцию присвоения объектов =, потоковые операции введения » и выведения « объектов.

4. Создать производный класс - Окно, которое имеет заголовок и рядок меню (массив строк с названиями команд меню).

Определить необходимые данные, методы,конструкторы и деструкторы, методы переприсваевание цвета фона, рядка меню,методы или операторные функции ввода и вывода.

5. В приделах иерархии классов построить полиморфичный кластер на основе виртуального метода для чтения цвета фона или рядка меню. Продемонстрировать механизм позднего связывания

6. Разработать класс СПИСОК ОКОн, который включает масиив объектов класса ОКНО. Расположить окна на экране каскадом или плиткой . Увеличить окно до размера экрана.

Минимизировать размеры окна.


контейнер: Queue
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
#include<iostream>
#include<cstring>
#include<string>
#include<conio.h>
#include<fstream>
#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include <algorithm>
#include<locale>
#include<ctime>
#include<Windows.h>
#include<string.h>
#include<stdlib.h>
#pragma warning (disable: 4996)
 
using namespace std;
class ramka {
protected:
    int x1, y1, x2, y2; //Кординати рамки
    int color;//цвет рамки
public:
    //Конструктор
    ramka(int x1, int y1, int x2, int y2, int color)
    {
        this->x1 = x1;
        this->y1 = y1;
        this->x2 = x2;
        this->y2 = y2;
        this->color = color;
    }
 
 
    virtual void cvetvibor(int x) {
        char s[10], st[20] = "color ";
        itoa(x, s, 10);
        strcat(st, s);
        system(st);
        //cout << "Выберите цвет" << endl;
    };
    ramka() {
        x1 = 0;
        y1 = 0;
        x2 = 0;
        y2 = 0;
        color = 0;
    };
    //конструктор копіювання
    ramka(ramka& r)
    {
        x1 = r.x1;
        y1 = r.y1;
        x2 = r.x2;
        y2 = r.y2;
        color = r.color;
    }
    //операція виведення у потік
    friend ostream& operator<<(ostream& os, ramka& r)
    {
        os << r.x1 << ' ' << r.y1 << ' ' << r.x2 << ' ' << r.y2 << ' ' << r.color << endl;
        return os;
    }
 
    //операція введення з потоку
    friend istream& operator>>(istream& is, ramka& r)
    {
        is >> r.x1 >> r.y1 >> r.x2 >> r.y2 >> r.color;
        return is;
    }
    //операція ++
    ramka& operator++() {
        x2++;
        y2++;
        return *this;
    }
    //операція --
    ramka& operator --() {
        x2--;
        y2--;
        return *this;
    }
 
 
    // Перевантаження оператора присвоєння "=". 
    ramka
        ramka :: operator=(ramka& obj) {
        ramka temoobj;
        temoobj.x1 = obj.x1;
        temoobj.y1 = obj.y1;
        temoobj.x2 = obj.x2;
        temoobj.y2 = obj.y2;
        temoobj.color = obj.color;
        return temoobj;
    }
 
    // Перевантаженн77я бінарного оператора множення "*"
    ramka& operator*(ramka obj) {
        ramka tmp;
        tmp.x1 = x1 * obj.x1;
        tmp.y1 = y1 * obj.y1;
        tmp.x2 = x2 * obj.x2;
        tmp.y2 = y2 * obj.y2;
        return tmp;
    }
};
 
 
//Клас меню
class Menu {
protected:
    int count;              //кількість команд
    int active;             //номер активної команди
    char** command;         //назви команд
public:
    //Конструктор
    Menu(int count, int active, char **command)
    {
        this->count = count;
        this->active = active;
 
        this->command = new char*[count];
        for (int i = 0; i < count; i++)
        {
            this->command[i] = new char[20];
            strcpy_s(this->command[i], 20, command[i]);
        }
    }
    Menu() {
        count = 0;
        active = 0;
        command = NULL;
    };
    //конструктор копіювання 
    Menu(Menu& m)
    {
        count = m.count;
        active = m.active;
 
        command = new char*[m.count];
        for (int i = 0; i < count; i++)
        {
            command[i] = new char[20];
            strcpy_s(command[i], 20, m.command[i]);
        }
    }
    //деструктор
    ~Menu()
    {
        for (int i = 0; i < count; i++)
            delete[]command[i];
    }
    //операція введення з потоку
    friend istream& operator>>(istream& is, Menu& m)
    {
        for (int i = 0; i < m.count; i++) is >> m.command[i];
        return is;
    }
    //операція Виведення у потік
    friend ostream& operator<<(ostream& os, Menu& m)
    {
        for (int i = 0; i < m.count; i++) os << m.command[i] << endl;
        return os;
    }
};
//клас вікна
class Window : public ramka, public Menu
{
 
protected:
    char *title; //Заголовок 
public:
    //конструктор
    Window(char *title, ramka r, Menu m) : ramka(r), Menu(m)
    {
        this->title = new char[100];
        strcpy_s(this->title, 100, title);
    }
    //конструктор копіювання 
    Window(Window &w)
    {
        //ramka
        x1 = w.x1;
        y1 = w.y1;
        x2 = w.x2;
        y2 = w.y2;
        color = w.color;
        //Menu
        count = w.count;
        active = w.active;
        command = new char*[w.count];
        for (int i = 0; i < count; i++)
        {
            command[i] = new char[20];
            strcpy_s(command[i], 20, w.command[i]);
        }
        //Window
        title = w.title;
    }
    //деструктор
    ~Window()
    {
        delete[] title;
    }
    
    
    Window() :ramka(), Menu()
    {
        title = NULL;
    }
    //операція введення з потоку
    friend istream& operator>>(istream& is, Window& w)
    {
        is >> w.x1 >> w.y1 >> w.x2 >> w.y2;
        for (int i = 0; i < w.count; i++) is >> w.command[i];
        is >> w.title;
        return is;
    }
    //операція виведення у потік
    friend ostream& operator<<(ostream& os, Window& w)
    {
        os << w.title << ' ';
        os << ramka(w.x1, w.y1, w.x2, w.y2, w.color);
        os << Menu(w.count, w.active, w.command);
        return os;
    }
    void set() { cin.ignore(); };
    char* getname() { return title; };
    Window set(ifstream &f) {
        char str[100] = "";
        char *delim = "\t";
        char *ptr;
        f.getline(title, 50);
        ptr = strtok(str, delim);   if (ptr) strcpy(title, ptr);
 
    /*  ptr = strtok(str, NULL); if (ptr) set(atoi(ptr));
        ptr = strtok(str, NULL); if (ptr) set(atoi(ptr));
        ptr = strtok(NULL, delim); if (ptr) set(atoi(ptr));*/
    }
    void Window::print(ofstream &f)
    {
        f << title << '\n';
    }
    void Window::print() {
        //printf("\t%-25s%-11s% 8s", title);
        Window();
    }
};
 
class Queue {
protected:
    queue<Window> q;
public:
    void Print();
    void Load();
    void Save();
    void Add();
    void Edit();
    void Del();
    void Find();
};
void Queue::Print()//
{
    //queue <osoba>::iterator it;
    int i = 0;
    cout << "# Окно\n";
    cout << "-------------------------------------------------------------------\n";
    //it=os.begin();
    int n = q.size();
    queue <Window> t = q;
 
    while (!t.empty())
    {
        cout << ++i;
        t.front().print();
        t.pop();
    }
}
 
void Queue::Load()//
{
    char sn[5] = "";
    int n = 0;
    Window dd;
 
    ifstream fi("text.txt", ios::in);
    fi.getline(sn, 5);
    n = atoi(sn);
    for (int i = 0; i < n; i++)
    {
        dd.set(fi);
        q.push(dd);
    }
}
 
void Queue::Save()//
{
    ofstream f("text.txt", ios::out); //ff.close();
    f << q.size() << '\n';
 
    queue<Window> t = q;
    while (!t.empty())
    {
        t.front().print(f);
 
        t.pop();
    }
    f.close();
}
 
void Queue::Add()//vector <osoba> &os)
{
    Window dd;
    dd.set();
    q.push(dd);
}
 
void Queue::Edit()//
{
    int i = 0, n;
    Print();
    cout << "Введите номер редактируемого элемента > ";
    cin >> n;
    if (n < 1 || n > q.size())
    {
        fprintf(stderr, "Элемент с номером %d не существует\n", n); return;
    }
    n--;
    queue<Window> f, f2;
    Window dd;
    while (i < n)
    {
        f.push(q.front());
        q.pop();
        i++;
        //f.back().print();
    }
 
    dd = q.front();
    q.pop();
    dd.set();
 
    while (!q.empty())
    {
        f2.push(q.front());
        q.pop();
    }
 
    while (!f.empty())
    {
        q.push(f.front());
        f.pop();
    }
    q.push(dd);
 
    while (!f2.empty())
    {
        q.push(f2.front());
        f2.pop();
    }
}
 
void Queue::Del()//vector <osoba> &os)
{
    int i = 0, n;
    Print();
    cout << "Введите номер удаляемого элемента > ";
    cin >> n;
    if (n < 1 || n > q.size())
    {
        fprintf(stderr, "Элемент с номером %d не существует\n", n); return;
    }
    n--;
    queue<Window> f, f2;
    while (i < n)
    {
        f.push(q.front());
        q.pop();
        i++;
        //f.back().print();
    }
 
    q.pop();
 
    while (!q.empty())
    {
        f2.push(q.front());
        q.pop();
    }
 
    while (!f.empty())
    {
        q.push(f.front());
        f.pop();
    }
 
    while (!f2.empty())
    {
        q.push(f2.front());
        f2.pop();
    }
}
void Queue::Find()
{
    int i = 0;
    char str[50];
    Print();
    cout << "Введите Фамилию> ";
    cin >> str;
    queue<Window> f = q;
 
    while (!f.empty())
    {
        if (strstr(f.front().getname(), str))
        {
            f.front().print(); i++;
        }
        f.pop();
 
        if (i == 0) cout << "Нет записей удолетворяющих условие!" << endl;
    }
}
int men(void) {
    int c = 0;
    struct tm*t;
    time_t ltime;
    time(&ltime);
    t = localtime(&ltime);
    cout << '\n' << t->tm_mday << '/' << t->tm_mon + 1 << '/' << 1990 + t->tm_year << endl;
 
    while ((c < '0' || c >9) && c != 21)
    {
        printf("\n>>>>>Menu<<<<<\n");
        printf("----------------\n");
        printf("[0] - Exit\n[1] - Add\n[2] - Save\n[3] - Load\n[4] - Print\n[5] - Find\n[6] - Del\n[7] - Edit\n");
        printf("----------------\n");
        printf("---->");
        c = getch();
        printf("%c\n", c);
    }
    return c;
}
 
 
 
 
 
void main()
{
    Queue os;
    int k;
    setlocale(LC_ALL, "Russian");
    char * command[] = { "Add", "Save", "Load", "Print", "Find", "Del","Edit" };
    while ((k = men()) != 0 && k != 20)
        switch (k)
        {
        case'1': os.Add(); break;
        case'2': os.Save(); break;
        case'3': os.Load(); break;
        case'4': os.Print(); break;
        case'5': os.Find(); break;
        case'6': os.Del(); break;
        case'7': os.Edit(); break;
        }
 
    /*ramka f(1, 1, 80, 25, 2);
    cout << "Склад об'єкта ramka\n" << f;
 
    Menu m(7, 0, command);
    cout << "Склад об'єкта Menu\n" << m;
 
    Window w("MyWindow", f, m);
 
    cout << w << endl;*/
 
    system("pause");
}
не могу устранить проблему
Ошибка C2558 class "Window": нет доступных конструкторов копии или конструктор копии объявлен как "explicit"
0
cpp_developer
Эксперт
20123 / 5690 / 1417
Регистрация: 09.04.2010
Сообщений: 22,546
Блог
23.04.2016, 12:48
Ответы с готовыми решениями:

Создать класс Список окон
Здравствуйте, есть довольно большое задание: Задание 1. Создать класс Прямоугольник, который имеет координаты верхнего левого и...

Создать базовый класс «Список» и класс-потомок «Упорядоченный список»
Создать базовый класс «список», определив в нем функции добавления в начало списка, удаления N-го элемента списка, вывода элементов списка...

Список видимых окон
Добрый день. В с++ практически ничего не понимаю. Нужно получить список всех видимых окон. Я нашла такой код на форуме: BOOL...

11
7804 / 6568 / 2988
Регистрация: 14.04.2014
Сообщений: 28,705
23.04.2016, 12:55
Обычно так:
C++
1
Window(const Window &w)
В какой строке ошибка?
0
0 / 0 / 0
Регистрация: 23.04.2016
Сообщений: 8
23.04.2016, 15:05  [ТС]
nmcf, не пишет в какой строке

Добавлено через 57 минут
nmcf, не пишет в какой строке
0
7804 / 6568 / 2988
Регистрация: 14.04.2014
Сообщений: 28,705
23.04.2016, 16:21
Ты остальные ошибки справь сначала, у тебя умножение в ramka возвращает ссылку на локальный объект; 197-я строка не верна и пр.
0
0 / 0 / 0
Регистрация: 23.04.2016
Сообщений: 8
23.04.2016, 16:49  [ТС]
nmcf, я вставил конст как вы сказали и дописал return хотя не совсем понимаю зачем он в set. Программа запускается. Ошибку в 197 строке сейчас уберу, можете еще пожалуйста проверить на ошибки
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
#include<iostream>
#include<cstring>
#include<string>
#include<conio.h>
#include<fstream>
#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include <algorithm>
#include<locale>
#include<ctime>
#include<Windows.h>
#include<string.h>
#include<stdlib.h>
#pragma warning (disable: 4996)
 
using namespace std;
class ramka {
protected:
    int x1, y1, x2, y2; //Кординати рамки
    int color;//цвет рамки
public:
    //Конструктор
    ramka(int x1, int y1, int x2, int y2, int color)
    {
        this->x1 = x1;
        this->y1 = y1;
        this->x2 = x2;
        this->y2 = y2;
        this->color = color;
    }
 
 
    virtual void cvetvibor(int x) {
        char s[10], st[20] = "color ";
        itoa(x, s, 10);
        strcat(st, s);
        system(st);
        //cout << "Выберите цвет" << endl;
    };
    ramka() {
        x1 = 0;
        y1 = 0;
        x2 = 0;
        y2 = 0;
        color = 0;
    };
    //конструктор копіювання
    ramka(ramka& r)
    {
        x1 = r.x1;
        y1 = r.y1;
        x2 = r.x2;
        y2 = r.y2;
        color = r.color;
    }
    //операція виведення у потік
    friend ostream& operator<<(ostream& os, ramka& r)
    {
        os << r.x1 << ' ' << r.y1 << ' ' << r.x2 << ' ' << r.y2 << ' ' << r.color << endl;
        return os;
    }
 
    //операція введення з потоку
    friend istream& operator>>(istream& is, ramka& r)
    {
        is >> r.x1 >> r.y1 >> r.x2 >> r.y2 >> r.color;
        return is;
    }
    //операція ++
    ramka& operator++() {
        x2++;
        y2++;
        return *this;
    }
    //операція --
    ramka& operator --() {
        x2--;
        y2--;
        return *this;
    }
 
 
    // Перевантаження оператора присвоєння "=". 
    ramka
        ramka :: operator=(ramka& obj) {
        ramka temoobj;
        temoobj.x1 = obj.x1;
        temoobj.y1 = obj.y1;
        temoobj.x2 = obj.x2;
        temoobj.y2 = obj.y2;
        temoobj.color = obj.color;
        return temoobj;
    }
 
    // Перевантаженн77я бінарного оператора множення "*"
    ramka& operator*(ramka obj) {
        ramka tmp;
        tmp.x1 = x1 * obj.x1;
        tmp.y1 = y1 * obj.y1;
        tmp.x2 = x2 * obj.x2;
        tmp.y2 = y2 * obj.y2;
        return tmp;
    }
};
 
 
//Клас меню
class Menu {
protected:
    int count;              //кількість команд
    int active;             //номер активної команди
    char** command;         //назви команд
public:
    //Конструктор
    Menu(int count, int active, char **command)
    {
        this->count = count;
        this->active = active;
 
        this->command = new char*[count];
        for (int i = 0; i < count; i++)
        {
            this->command[i] = new char[20];
            strcpy_s(this->command[i], 20, command[i]);
        }
    }
    Menu() {
        count = 0;
        active = 0;
        command = NULL;
    };
    //конструктор копіювання 
    Menu(Menu& m)
    {
        count = m.count;
        active = m.active;
 
        command = new char*[m.count];
        for (int i = 0; i < count; i++)
        {
            command[i] = new char[20];
            strcpy_s(command[i], 20, m.command[i]);
        }
    }
    //деструктор
    ~Menu()
    {
        for (int i = 0; i < count; i++)
            delete[]command[i];
    }
    //операція введення з потоку
    friend istream& operator>>(istream& is, Menu& m)
    {
        for (int i = 0; i < m.count; i++) is >> m.command[i];
        return is;
    }
    //операція Виведення у потік
    friend ostream& operator<<(ostream& os, Menu& m)
    {
        for (int i = 0; i < m.count; i++) os << m.command[i] << endl;
        return os;
    }
};
//клас вікна
class Window : public ramka, public Menu
{
 
protected:
    char *title; //Заголовок 
public:
    //конструктор
    Window(char *title, ramka r, Menu m) : ramka(r), Menu(m)
    {
        this->title = new char[100];
        strcpy_s(this->title, 100, title);
    }
    //конструктор копіювання 
    Window( const Window &w)
    {
        //ramka
        x1 = w.x1;
        y1 = w.y1;
        x2 = w.x2;
        y2 = w.y2;
        color = w.color;
        //Menu
        count = w.count;
        active = w.active;
        command = new char*[w.count];
        for (int i = 0; i < count; i++)
        {
            command[i] = new char[20];
            strcpy_s(command[i], 20, w.command[i]);
        }
        //Window
        title = w.title;
    }
    //деструктор
    ~Window()
    {
        delete[] title;
    }
    
    
    Window() :ramka(), Menu()
    {
        title = NULL;
    }
    //операція введення з потоку
    friend istream& operator>>(istream& is, Window& w)
    {
        is >> w.x1 >> w.y1 >> w.x2 >> w.y2;
        for (int i = 0; i < w.count; i++) is >> w.command[i];
        is >> w.title;
        return is;
    }
    //операція виведення у потік
    friend ostream& operator<<(ostream& os, Window& w)
    {
        os << w.title << ' ';
        os << ramka(w.x1, w.y1, w.x2, w.y2, w.color);
        os << Menu(w.count, w.active, w.command);
        return os;
    }
    void set() { cin.ignore(); };
    char* getname() { return title; };
    Window set(ifstream &f) {
        char str[100] = "";
        char *delim = "\t";
        char *ptr;
        f.getline(title, 50);
        ptr = strtok(str, delim);   if (ptr) strcpy(title, ptr);
 
    ptr = strtok(str, NULL); if (ptr) cvetvibor(atoi(ptr));
        
    return Window();
    }
    void Window::print(ofstream &f)
    {
        f << title << '\n';
    }
    void Window::print() {
        //printf("\t%-25s%-11s% 8s", title);
        Window();
    }
};
 
class Queue {
protected:
    queue<Window> q;
public:
    void Print();
    void Load();
    void Save();
    void Add();
    void Edit();
    void Del();
    void Find();
};
 
void Queue::Print()//
{
    //queue <osoba>::iterator it;
    int i = 0;
    cout << "# Окно\n";
    cout << "-------------------------------------------------------------------\n";
    //it=os.begin();
    int n = q.size();
    queue <Window> t = q;
 
    while (!t.empty())
    {
        cout << ++i;
        t.front().print();
        t.pop();
    }
}
 
void Queue::Load()//
{
    char sn[5] = "";
    int n = 0;
    Window dd;
 
    ifstream fi("text.txt", ios::in);
    fi.getline(sn, 5);
    n = atoi(sn);
    for (int i = 0; i < n; i++)
    {
        dd.set(fi);
        q.push(dd);
    }
}
 
void Queue::Save()//
{
    ofstream f("text.txt", ios::out); //ff.close();
    f << q.size() << '\n';
 
    queue<Window> t = q;
    while (!t.empty())
    {
        t.front().print(f);
 
        t.pop();
    }
    f.close();
}
 
void Queue::Add()//vector <osoba> &os)
{
    Window dd;
    dd.set();
    q.push(dd);
}
 
void Queue::Edit()//
{
    int i = 0, n;
    Print();
    cout << "Введите номер редактируемого элемента > ";
    cin >> n;
    if (n < 1 || n > q.size())
    {
        fprintf(stderr, "Элемент с номером %d не существует\n", n); return;
    }
    n--;
    queue<Window> f, f2;
    Window dd;
    while (i < n)
    {
        f.push(q.front());
        q.pop();
        i++;
        //f.back().print();
    }
 
    dd = q.front();
    q.pop();
    dd.set();
 
    while (!q.empty())
    {
        f2.push(q.front());
        q.pop();
    }
 
    while (!f.empty())
    {
        q.push(f.front());
        f.pop();
    }
    q.push(dd);
 
    while (!f2.empty())
    {
        q.push(f2.front());
        f2.pop();
    }
}
 
void Queue::Del()//vector <osoba> &os)
{
    int i = 0, n;
    Print();
    cout << "Введите номер удаляемого элемента > ";
    cin >> n;
    if (n < 1 || n > q.size())
    {
        fprintf(stderr, "Элемент с номером %d не существует\n", n); return;
    }
    n--;
    queue<Window> f, f2;
    while (i < n)
    {
        f.push(q.front());
        q.pop();
        i++;
        //f.back().print();
    }
 
    q.pop();
 
    while (!q.empty())
    {
        f2.push(q.front());
        q.pop();
    }
 
    while (!f.empty())
    {
        q.push(f.front());
        f.pop();
    }
 
    while (!f2.empty())
    {
        q.push(f2.front());
        f2.pop();
    }
}
void Queue::Find()
{
    int i = 0;
    char str[50];
    Print();
    cout << "Введите Фамилию> ";
    cin >> str;
    queue<Window> f = q;
 
    while (!f.empty())
    {
        if (strstr(f.front().getname(), str))
        {
            f.front().print(); i++;
        }
        f.pop();
 
        if (i == 0) cout << "Нет записей удолетворяющих условие!" << endl;
    }
}
int men(void) {
    int c = 0;
    struct tm*t;
    time_t ltime;
    time(&ltime);
    t = localtime(&ltime);
    cout << '\n' << t->tm_mday << '/' << t->tm_mon + 1 << '/' << 1990 + t->tm_year << endl;
 
    while ((c < '0' || c >9) && c != 21)
    {
        printf("\n>>>>>Menu<<<<<\n");
        printf("----------------\n");
        printf("[0] - Exit\n[1] - Add\n[2] - Save\n[3] - Load\n[4] - Print\n[5] - Find\n[6] - Del\n[7] - Edit\n");
        printf("----------------\n");
        printf("---->");
        c = getch();
        printf("%c\n", c);
    }
    return c;
}
 
 
 
 
 
void main()
{
    Queue os;
    int k;
    setlocale(LC_ALL, "Russian");
    char * command[] = { "Add", "Save", "Load", "Print", "Find", "Del","Edit" };
    while ((k = men()) != 0 && k != 20)
        switch (k)
        {
        case'1': os.Add(); break;
        case'2': os.Save(); break;
        case'3': os.Load(); break;
        case'4': os.Print(); break;
        case'5': os.Find(); break;
        case'6': os.Del(); break;
        case'7': os.Edit(); break;
        }
 
    /*ramka f(1, 1, 80, 25, 2);
    cout << "Склад об'єкта ramka\n" << f;
 
    Menu m(7, 0, command);
    cout << "Склад об'єкта Menu\n" << m;
 
    Window w("MyWindow", f, m);
 
    cout << w << endl;*/
 
    system("pause");
}
это переделаный код, который у меня работает
0
7804 / 6568 / 2988
Регистрация: 14.04.2014
Сообщений: 28,705
23.04.2016, 16:55
Присваивание должно возвращать ссылку на себя, а сложение, вычитание и пр. возвращают объект. Примерно так:
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
    ramka & operator = (ramka& obj)
    {
        x1 = obj.x1;
        y1 = obj.y1;
        x2 = obj.x2;
        y2 = obj.y2;
        color = obj.color;
 
        return *this;
    }
 
    ramka operator * (ramka obj)
    {
        ramka tmp;
        tmp.x1 = x1 * obj.x1;
        tmp.y1 = y1 * obj.y1;
        tmp.x2 = x2 * obj.x2;
        tmp.y2 = y2 * obj.y2;
        return tmp;
    }
0
0 / 0 / 0
Регистрация: 23.04.2016
Сообщений: 8
23.04.2016, 17:03  [ТС]
nmcf, у меня вроде такое же умножение как вы написали
0
7804 / 6568 / 2988
Регистрация: 14.04.2014
Сообщений: 28,705
23.04.2016, 18:43
У тебя возврат ссылки (&).
0
0 / 0 / 0
Регистрация: 23.04.2016
Сообщений: 8
23.04.2016, 18:59  [ТС]
nmcf, а не могли бы вы мне еще подсказать как убрать зацикливание или что это происходит?
Миниатюры
Класс "Список окон"  
0
0 / 0 / 0
Регистрация: 23.04.2016
Сообщений: 8
23.04.2016, 21:18  [ТС]
nmcf, проблема решена, спасибо за помощь))
0
0 / 0 / 0
Регистрация: 08.05.2020
Сообщений: 1
10.05.2020, 01:18
Народ помогите доделать программу плиз! Сейчас она в таком виде. Циклит меню

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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
#include<iostream>
#include<cstring>
#include<string>
#include<conio.h>
#include<fstream>
#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include <algorithm>
#include<locale>
#include<ctime>
#include<Windows.h>
#include<string.h>
#include<stdlib.h>
#pragma warning (disable: 4996)
 
using namespace std;
class ramka {
protected:
    int x1, y1, x2, y2; //координаты рамки
    int color;//цвет рамки
public:
    //конструктор
    ramka(int x1, int y1, int x2, int y2, int color)
    {
        this->x1 = x1;
        this->y1 = y1;
        this->x2 = x2;
        this->y2 = y2;
        this->color = color;
    }
 
 
    virtual void cvetvibor(int x) {
        char s[10], st[20] = "color ";
        itoa(x, s, 10);
        strcat(st, s);
        system(st);
        //cout << "Выберети цвет" << endl;
    };
    ramka() {
        x1 = 0;
        y1 = 0;
        x2 = 0;
        y2 = 0;
        color = 0;
    };
    //конструктор копирования
    ramka(ramka& r)
    {
        x1 = r.x1;
        y1 = r.y1;
        x2 = r.x2;
        y2 = r.y2;
        color = r.color;
    }
    //операция введения в поток
    ostream& operator<<(ostream& os)
    {
        os << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << ' ' << color << endl;
        return os;
    }
 
    //операция вывода из потока
    istream& operator>>(istream& is)
    {
        is >> x1 >> y1 >> x2 >> y2 >> color;
        return is;
    }
    //операция ++
    ramka& operator++() {
        x2++;
        y2++;
        return *this;
    }
    //операция --
    ramka& operator --() {
        x2--;
        y2--;
        return *this;
    }
 
 
    // Перезарузка оператора присвоения "=". 
    ramka& operator = (ramka& obj)
    {
        x1 = obj.x1;
        y1 = obj.y1;
        x2 = obj.x2;
        y2 = obj.y2;
        color = obj.color;
        return *this;
    }
    // Перезагрузка бинарного оператора умножения "*"
    ramka operator * (ramka obj)
    {
        ramka tmp;
        tmp.x1 = x1 * obj.x1;
        tmp.y1 = y1 * obj.y1;
        tmp.x2 = x2 * obj.x2;
        tmp.y2 = y2 * obj.y2;
        return tmp;
    }
};
 
 
    //Класс меню
    class Menu {
    protected:
        int count;              //количество команд
        int active;             //номер активной команды
        char** command;         //название команды
    public:
        //конструктор
        Menu(int count, int active, char** command)
        {
            this->count = count;
            this->active = active;
 
            this->command = new char* [count];
            for (int i = 0; i < count; i++)
            {
                this->command[i] = new char[20];
                strcpy_s(this->command[i], 20, command[i]);
            }
        }
        Menu() {
            count = 0;
            active = 0;
            command = NULL;
        };
        //конструктор копирования 
        Menu(Menu& m)
        {
            count = m.count;
            active = m.active;
 
            command = new char* [m.count];
            for (int i = 0; i < count; i++)
            {
                command[i] = new char[20];
                strcpy_s(command[i], 20, m.command[i]);
            }
        }
        //деструктор
        ~Menu()
        {
            for (int i = 0; i < count; i++)
                delete[]command[i];
        }
        //операция введения с потока
        friend istream& operator>>(istream& is, Menu& m)
        {
            for (int i = 0; i < m.count; i++) is >> m.command[i];
            return is;
        }
        //операция вывода из потока
        friend ostream& operator<<(ostream& os, Menu& m)
        {
            for (int i = 0; i < m.count; i++) os << m.command[i] << endl;
            return os;
        }
    };
    //Класс окна
    class Window : public ramka, public Menu
    {
 
    protected:
        char* title; //Заголовок
    public:
        //конструктор
        Window(char* title, ramka r, Menu m) : ramka(r), Menu(m)
        {
            this->title = new char[100];
            strcpy_s(this->title, 100, title);
        }
        //конструктор копирования
        Window(const Window& w)
        {
            //ramka
            x1 = w.x1;
            y1 = w.y1;
            x2 = w.x2;
            y2 = w.y2;
            color = w.color;
            //Menu
            count = w.count;
            active = w.active;
            command = new char* [w.count];
            for (int i = 0; i < count; i++)
            {
                command[i] = new char[20];
                strcpy_s(command[i], 20, w.command[i]);
            }
            //Window
            title = w.title;
        }
        //деструктор
        ~Window()
        {
            delete[] title;
        }
 
 
        Window() :ramka(), Menu()
        {
            title = NULL;
        }
        //операция введения из потока
        friend istream& operator>>(istream& is, Window& w)
        {
            is >> w.x1 >> w.y1 >> w.x2 >> w.y2;
            for (int i = 0; i < w.count; i++) is >> w.command[i];
            is >> w.title;
            return is;
        }
        //операция вывода из потка
        friend ostream& operator<<(ostream& os, Window& w)
        {
            os << w.title << ' ';
            os << w;
            os << w;
            return os;
        }
        void set() { cin.ignore(); };
        char* getname() { return title; };
        Window set(ifstream& f) {
            char str[100] = "";
            char* ptr;
            f.getline(title, 50);
            ptr = strtok(str, "\t");   if (ptr) strcpy(title, ptr);
 
            ptr = strtok(str, NULL); if (ptr) cvetvibor(atoi(ptr));
 
            return Window();
        }
        void print(ofstream& f)
        {
            f << title << '\n';
        }
        void print() {
            //printf("\t%-25s%-11s% 8s", title);
            Window();
        }
    };
 
    class Queue {
    protected:
        queue<Window> q;
    public:
        void Print();
        void Load();
        void Save();
        void Add();
        void Edit();
        void Del();
        void Find();
    };
 
    void Queue::Print()
    {
        //queue <osoba>::iterator it;
        int i = 0;
        cout << "# Окно\n";
        cout << "-------------------------------------------------------------------\n";
        //it=os.begin();
        int n = q.size();
        queue <Window> t = q;
 
        while (!t.empty())
        {
            cout << ++i;
            t.front().print();
            t.pop();
        }
    }
 
    void Queue::Load()
    {
        char sn[5] = "";
        int n = 0;
        Window dd;
 
        ifstream fi("text.txt", ios::in);
        fi.getline(sn, 5);
        n = atoi(sn);
        for (int i = 0; i < n; i++)
        {
            dd.set(fi);
            q.push(dd);
        }
    }
 
    void Queue::Save()
    {
        ofstream f("text.txt", ios::out); //ff.close();
        f << q.size() << '\n';
 
        queue<Window> t = q;
        while (!t.empty())
        {
            t.front().print(f);
 
            t.pop();
        }
        f.close();
    }
 
    void Queue::Add()//vector <osoba> &os)
    {
        Window dd;
        dd.set();
        q.push(dd);
    }
 
    void Queue::Edit()//
    {
        int i = 0, n;
        Print();
        cout << "Введите номер редактируемоо элемента > ";
        cin >> n;
        if (n < 1 || n > q.size())
        {
            fprintf(stderr, "Элемент с номером %d не существует\n", n); return;
        }
        n--;
        queue<Window> f, f2;
        Window dd;
        while (i < n)
        {
            f.push(q.front());
            q.pop();
            i++;
            //f.back().print();
        }
 
        dd = q.front();
        q.pop();
        dd.set();
 
        while (!q.empty())
        {
            f2.push(q.front());
            q.pop();
        }
 
        while (!f.empty())
        {
            q.push(f.front());
            f.pop();
        }
        q.push(dd);
 
        while (!f2.empty())
        {
            q.push(f2.front());
            f2.pop();
        }
    }
 
    void Queue::Del()//vector <osoba> &os)
    {
        int i = 0, n;
        Print();
        cout << "Введите номер удаляемоо элемента > ";
        cin >> n;
        if (n < 1 || n > q.size())
        {
            fprintf(stderr, "Элемент с номером %d не существует\n", n); return;
        }
        n--;
        queue<Window> f, f2;
        while (i < n)
        {
            f.push(q.front());
            q.pop();
            i++;
            //f.back().print();
        }
 
        q.pop();
 
        while (!q.empty())
        {
            f2.push(q.front());
            q.pop();
        }
 
        while (!f.empty())
        {
            q.push(f.front());
            f.pop();
        }
 
        while (!f2.empty())
        {
            q.push(f2.front());
            f2.pop();
        }
    }
    void Queue::Find()
    {
        int i = 0;
        char str[50];
        Print();
        cout << "Введите Фамилию> ";
        cin >> str;
        queue<Window> f = q;
 
        while (!f.empty())
        {
            if (strstr(f.front().getname(), str))
            {
                f.front().print(); i++;
            }
            f.pop();
 
            if (i == 0) cout << "Нет записей удовлетворяющих условие!" << endl;
        }
    }
    int men(void) {
        int c = 0;
        struct tm* t;
        time_t ltime;
        time(&ltime);
        t = localtime(&ltime);
        cout << '\n' << t->tm_mday << '/' << t->tm_mon + 1 << '/' << 1990 + t->tm_year << endl;
 
        while ((c < '0' || c >9) && c != 21)
        {
            printf("\n>>>>>Menu<<<<<\n");
            printf("----------------\n");
            printf("[0] - Exit\n[1] - Add\n[2] - Save\n[3] - Load\n[4] - Print\n[5] - Find\n[6] - Del\n[7] - Edit\n");
            printf("----------------\n");
            printf("---->");
            c = getch();
            printf("%c\n", c);
        }
        return c;
    }
 
 
 
 
 
    void main()
    {
        Queue os;
        int k;
        setlocale(LC_ALL, "Russian");
        char command[][6] = { "Add", "Save", "Load", "Print", "Find", "Del","Edit" };
        while ((k = men()) != 0 && k != 20)
            switch (k)
            {
            case'1': os.Add(); break;
            case'2': os.Save(); break;
            case'3': os.Load(); break;
            case'4': os.Print(); break;
            case'5': os.Find(); break;
            case'6': os.Del(); break;
            case'7': os.Edit(); break;
            }
 
        /*ramka f(1, 1, 80, 25, 2);
        cout << "Склад объекта ramka\n" << f;
 
        Menu m(7, 0, command);
        cout << "Склад объекта Menu\n" << m;
 
        Window w("MyWindow", f, m);
 
        cout << w << endl;*/
 
        system("pause");
    }
0
0 / 0 / 0
Регистрация: 06.06.2022
Сообщений: 2
06.06.2022, 16:34
maxim5163, Приветствую. Хотелось бы попросить,если у вас остался исправленный код, выставить его, очень надо.

Добавлено через 25 минут
nmcf, Простите что беспокою, просьба помочь с зацикливанием в этом же коде
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
#include<iostream>
#include<cstring>
#include<string>
#include<conio.h>
#include<fstream>
#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include <algorithm>
#include<locale>
#include<ctime>
#include<Windows.h>
#include<string.h>
#include<stdlib.h>
#pragma warning (disable: 4996)
 
using namespace std;
class ramka {
protected:
    int x1, y1, x2, y2; //координаты рамки
    int color;//цвет рамки
public:
    //конструктор
    ramka(int x1, int y1, int x2, int y2, int color)
    {
        this->x1 = x1;
        this->y1 = y1;
        this->x2 = x2;
        this->y2 = y2;
        this->color = color;
    }
 
 
    virtual void cvetvibor(int x) {
        char s[10], st[20] = "color ";
        itoa(x, s, 10);
        strcat(st, s);
        system(st);
        //cout << "Выберети цвет" << endl;
    };
    ramka() {
        x1 = 0;
        y1 = 0;
        x2 = 0;
        y2 = 0;
        color = 0;
    };
    //конструктор копирования
    ramka(ramka& r)
    {
        x1 = r.x1;
        y1 = r.y1;
        x2 = r.x2;
        y2 = r.y2;
        color = r.color;
    }
    //операция введения в поток
    ostream& operator<<(ostream& os)
    {
        os << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << ' ' << color << endl;
        return os;
    }
 
    //операция вывода из потока
    istream& operator>>(istream& is)
    {
        is >> x1 >> y1 >> x2 >> y2 >> color;
        return is;
    }
    //операция ++
    ramka& operator++() {
        x2++;
        y2++;
        return *this;
    }
    //операция --
    ramka& operator --() {
        x2--;
        y2--;
        return *this;
    }
 
 
    // Перезарузка оператора присвоения "=". 
    ramka& operator = (ramka& obj)
    {
        x1 = obj.x1;
        y1 = obj.y1;
        x2 = obj.x2;
        y2 = obj.y2;
        color = obj.color;
        return *this;
    }
    // Перезагрузка бинарного оператора умножения "*"
    ramka operator * (ramka obj)
    {
        ramka tmp;
        tmp.x1 = x1 * obj.x1;
        tmp.y1 = y1 * obj.y1;
        tmp.x2 = x2 * obj.x2;
        tmp.y2 = y2 * obj.y2;
        return tmp;
    }
};
 
 
//Класс меню
class Menu {
protected:
    int count;              //количество команд
    int active;             //номер активной команды
    char** command;         //название команды
public:
    //конструктор
    Menu(int count, int active, char** command)
    {
        this->count = count;
        this->active = active;
 
        this->command = new char* [count];
        for (int i = 0; i < count; i++)
        {
            this->command[i] = new char[20];
            strcpy_s(this->command[i], 20, command[i]);
        }
    }
    Menu() {
        count = 0;
        active = 0;
        command = NULL;
    };
    //конструктор копирования 
    Menu(Menu& m)
    {
        count = m.count;
        active = m.active;
 
        command = new char* [m.count];
        for (int i = 0; i < count; i++)
        {
            command[i] = new char[20];
            strcpy_s(command[i], 20, m.command[i]);
        }
    }
    //деструктор
    ~Menu()
    {
        for (int i = 0; i < count; i++)
            delete[]command[i];
    }
    //операция введения с потока
    friend istream& operator>>(istream& is, Menu& m)
    {
        for (int i = 0; i < m.count; i++) is >> m.command[i];
        return is;
    }
    //операция вывода из потока
    friend ostream& operator<<(ostream& os, Menu& m)
    {
        for (int i = 0; i < m.count; i++) os << m.command[i] << endl;
        return os;
    }
};
//Класс окна
class Window : public ramka, public Menu
{
 
protected:
    char* title; //Заголовок
public:
    //конструктор
    Window(char* title, ramka r, Menu m) : ramka(r), Menu(m)
    {
        this->title = new char[100];
        strcpy_s(this->title, 100, title);
    }
    //конструктор копирования
    Window(const Window& w)
    {
        //ramka
        x1 = w.x1;
        y1 = w.y1;
        x2 = w.x2;
        y2 = w.y2;
        color = w.color;
        //Menu
        count = w.count;
        active = w.active;
        command = new char* [w.count];
        for (int i = 0; i < count; i++)
        {
            command[i] = new char[20];
            strcpy_s(command[i], 20, w.command[i]);
        }
        //Window
        title = w.title;
    }
    //деструктор
    ~Window()
    {
        delete[] title;
    }
 
 
    Window() :ramka(), Menu()
    {
        title = NULL;
    }
    //операция введения из потока
    friend istream& operator>>(istream& is, Window& w)
    {
        is >> w.x1 >> w.y1 >> w.x2 >> w.y2;
        for (int i = 0; i < w.count; i++) is >> w.command[i];
        is >> w.title;
        return is;
    }
    //операция вывода из потка
    friend ostream& operator<<(ostream& os, Window& w)
    {
        os << w.title << ' ';
        os << w;
        os << w;
        return os;
    }
    void set() { cin.ignore(); };
    char* getname() { return title; };
    Window set(ifstream& f) {
        char str[100] = "";
        char* ptr;
        f.getline(title, 50);
        ptr = strtok(str, "\t");   if (ptr) strcpy(title, ptr);
 
        ptr = strtok(str, NULL); if (ptr) cvetvibor(atoi(ptr));
 
        return Window();
    }
    void print(ofstream& f)
    {
        f << title << '\n';
    }
    void print() {
        //printf("\t%-25s%-11s% 8s", title);
        Window();
    }
};
 
class Queue {
protected:
    queue<Window> q;
public:
    void Print();
    void Load();
    void Save();
    void Add();
    void Edit();
    void Del();
    void Find();
};
 
void Queue::Print()
{
    //queue <osoba>::iterator it;
    int i = 0;
    cout << "# Окно\n";
    cout << "-------------------------------------------------------------------\n";
    //it=os.begin();
    int n = q.size();
    queue <Window> t = q;
 
    while (!t.empty())
    {
        cout << ++i;
        t.front().print();
        t.pop();
    }
}
 
void Queue::Load()
{
    char sn[5] = "";
    int n = 0;
    Window dd;
 
    ifstream fi("text.txt", ios::in);
    fi.getline(sn, 5);
    n = atoi(sn);
    for (int i = 0; i < n; i++)
    {
        dd.set(fi);
        q.push(dd);
    }
}
 
void Queue::Save()
{
    ofstream f("text.txt", ios::out); //ff.close();
    f << q.size() << '\n';
 
    queue<Window> t = q;
    while (!t.empty())
    {
        t.front().print(f);
 
        t.pop();
    }
    f.close();
}
 
void Queue::Add()//vector <osoba> &os)
{
    Window dd;
    dd.set();
    q.push(dd);
}
 
void Queue::Edit()//
{
    int i = 0, n;
    Print();
    cout << "Введите номер редактируемоо элемента > ";
    cin >> n;
    if (n < 1 || n > q.size())
    {
        fprintf(stderr, "Элемент с номером %d не существует\n", n); return;
    }
    n--;
    queue<Window> f, f2;
    Window dd;
    while (i < n)
    {
        f.push(q.front());
        q.pop();
        i++;
        //f.back().print();
    }
 
    dd = q.front();
    q.pop();
    dd.set();
 
    while (!q.empty())
    {
        f2.push(q.front());
        q.pop();
    }
 
    while (!f.empty())
    {
        q.push(f.front());
        f.pop();
    }
    q.push(dd);
 
    while (!f2.empty())
    {
        q.push(f2.front());
        f2.pop();
    }
}
 
void Queue::Del()//vector <osoba> &os)
{
    int i = 0, n;
    Print();
    cout << "Введите номер удаляемоо элемента > ";
    cin >> n;
    if (n < 1 || n > q.size())
    {
        fprintf(stderr, "Элемент с номером %d не существует\n", n); return;
    }
    n--;
    queue<Window> f, f2;
    while (i < n)
    {
        f.push(q.front());
        q.pop();
        i++;
        //f.back().print();
    }
 
    q.pop();
 
    while (!q.empty())
    {
        f2.push(q.front());
        q.pop();
    }
 
    while (!f.empty())
    {
        q.push(f.front());
        f.pop();
    }
 
    while (!f2.empty())
    {
        q.push(f2.front());
        f2.pop();
    }
}
void Queue::Find()
{
    int i = 0;
    char str[50];
    Print();
    cout << "Введите Фамилию> ";
    cin >> str;
    queue<Window> f = q;
 
    while (!f.empty())
    {
        if (strstr(f.front().getname(), str))
        {
            f.front().print(); i++;
        }
        f.pop();
 
        if (i == 0) cout << "Нет записей удовлетворяющих условие!" << endl;
    }
}
int men(void) {
    int c = 0;
    struct tm* t;
    time_t ltime;
    time(&ltime);
    t = localtime(&ltime);
    cout << '\n' << t->tm_mday << '/' << t->tm_mon + 1 << '/' << 1990 + t->tm_year << endl;
 
    while ((c < '0' || c >9) && c != 21)
    {
        printf("\n>>>>>Menu<<<<<\n");
        printf("----------------\n");
        printf("[0] - Exit\n[1] - Add\n[2] - Save\n[3] - Load\n[4] - Print\n[5] - Find\n[6] - Del\n[7] - Edit\n");
        printf("----------------\n");
        printf("---->");
        c = getch();
        printf("%c\n", c);
    }
    return c;
}
 
 
 
 
 
void main()
{
    Queue os;
    int k;
    setlocale(LC_ALL, "Russian");
    char command[][6] = { "Add", "Save", "Load", "Print", "Find", "Del","Edit" };
    while ((k = men()) != 0 && k != 20) {
        switch (k)
        {
        case'1': os.Add(); break;
        case'2': os.Save(); break;
        case'3': os.Load(); break;
        case'4': os.Print(); break;
        case'5': os.Find(); break;
        case'6': os.Del(); break;
        case'7': os.Edit(); break;
        }
    }
    /*ramka f(1, 1, 80, 25, 2);
    cout << "Склад объекта ramka\n" << f;
 
    Menu m(7, 0, command);
    cout << "Склад объекта Menu\n" << m;
 
    Window w("MyWindow", f, m);
 
    cout << w << endl;*/
 
    system("pause");
}
0
Надоела реклама? Зарегистрируйтесь и она исчезнет полностью.
raxper
Эксперт
30234 / 6612 / 1498
Регистрация: 28.12.2010
Сообщений: 21,154
Блог
06.06.2022, 16:34
Помогаю со студенческими работами здесь

Класс "Список окон"
Здраствуйте, есть довольно большое задание, код которого почти полностью представлен ниже: Завдання 1. Створити клас...

Список открытых окон
Добрый вечер! Собираюсь писать менеджер окон, Qt предоставляет возможность увидеть все открытые окна? или через винапи дескрипторы как то...

Разработать базовый класс "прямоугольник", производный класс "Окно" и класс-контейнер "Список окон"
Реализовать все задачи в С # WPF 1. Разработать класс прямоугольник, имеющий координаты верхнего левого и нижнего правого угла, цвет...

Список ОКОН
Завдання 4. СПИСОК ВІКОН 1. Створити клас ПРЯМОКУТНИК, що має координати верхнього лівого і нижнього правого кута, колір фону. 2....

Список окон
Всем привет. Как получить список всех открытых окон ? Запишу допустим я список этих окон в листбокс, как потом узнать у выбранного окна из...


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

Или воспользуйтесь поиском по форуму:
12
Ответ Создать тему
Новые блоги и статьи
Символические и жёсткие ссылки в Linux.
algri14 15.03.2026
Существует два типа ссылок — символические и жёсткие. Ссылка в Linux — это дополнительная запись в каталоге, которая может указывать либо на inode «файла-ИСТОЧНИКА», тогда это будет «жёсткая. . .
[Owen Logic] Поддержание уровня воды в резервуаре количеством включённых насосов: моделирование и выбор регулятора
ФедосеевПавел 14.03.2026
Поддержание уровня воды в резервуаре количеством включённых насосов: моделирование и выбор регулятора ВВЕДЕНИЕ Выполняя задание на управление насосной группой заполнения резервуара,. . .
делаю науч статью по влиянию грибов на сукцессию
anaschu 13.03.2026
прикрепляю статью
SDL3 для Desktop (MinGW): Создаём пустое окно с нуля для 2D-графики на SDL3, Си и C++
8Observer8 10.03.2026
Содержание блога Финальные проекты на Си и на C++: hello-sdl3-c. zip hello-sdl3-cpp. zip Результат:
Установка CMake и MinGW 13.1 для сборки С и C++ приложений из консоли и из Qt Creator в EXE
8Observer8 10.03.2026
Содержание блога MinGW - это коллекция инструментов для сборки приложений в EXE. CMake - это система сборки приложений. Здесь описаны базовые шаги для старта программирования с помощью CMake и. . .
Как дизайн сайта влияет на конверсию: 7 решений, которые реально повышают заявки
Neotwalker 08.03.2026
Многие до сих пор воспринимают дизайн сайта как “красивую оболочку”. На практике всё иначе: дизайн напрямую влияет на то, оставит человек заявку или уйдёт через несколько секунд. Даже если у вас. . .
Модульная разработка через nuget packages
DevAlt 07.03.2026
Сложившийся в . Net-среде способ разработки чаще всего предполагает монорепозиторий в котором находятся все исходники. При создании нового решения, мы просто добавляем нужные проекты и имеем. . .
Модульный подход на примере F#
DevAlt 06.03.2026
В блоге дяди Боба наткнулся на такое определение: В этой книге («Подход, основанный на вариантах использования») Ивар утверждает, что архитектура программного обеспечения — это структуры,. . .
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2026, CyberForum.ru