3 / 3 / 2
Регистрация: 24.03.2020
Сообщений: 153
1

Нотариальная контора

26.06.2020, 13:44. Показов 1294. Ответов 2

Author24 — интернет-сервис помощи студентам
Ребят, привет! Помогите разобраться, есть сама программа (код ниже), и есть фрагмент кода этой программы (также ниже). Так вот, что делает этот фрагмент кода в программе и каким образом? Спасибо заранее.

Сам код программы Нотариальной конторы
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
#include "stdio.h"
#include <iostream>
#include <fstream>
#include "windows.h"
#include <string>
#include "string.h"
#include "conio.h"
#include <vector>
using namespace std;
string a, b;
 
int Auth()
{
    setlocale(LC_ALL, "Rus");
    string login = "User6";
    string password = "1111";
    string log1;
    string pass;
    for (; ; )
    {
        system("cls");
        cout << "Введите логин: ";
        cin >> log1;
        if (log1 == login)
        {
            cout << "Введите пароль: ";
            cin >> pass;
            if (pass == password)
            {
                return 0;
            }
            continue;
        }
    }
}
 
struct myList
{
    char nomer[20];
    char client[15];
    char dceni[22];
    char pdogovora[100];
    myList* next;
};
myList* first = NULL;
myList* getLast()
{
    myList* temp = first;
    if (!temp) return NULL;
    while (temp->next != NULL)
    {
        temp = temp->next;
    }
    return temp;
}
myList* addFirst(const char* nomer, const char* m, const char* m1, const char* c)
{
    myList* temp = new myList;
    strcpy_s(temp->nomer, nomer);
    strcpy_s(temp->client, m);
    strcpy_s(temp->dceni, c);
    strcpy_s(temp->pdogovora, m1);
    temp->next = first;
    first = temp;
    return temp;
}
myList* addLast(const char* nomer, const char* m, const char* m1, const char* c)
{
    myList* temp = new myList;
    strcpy_s(temp->nomer, nomer);
    strcpy_s(temp->client, m);
    strcpy_s(temp->dceni, c);
    strcpy_s(temp->pdogovora, m1);
    temp->next = NULL;
    if (first == NULL)
        first = temp;
    else
        getLast()->next = temp;
    return temp;
}
myList* addAfter(const char* nomer, const char* m, const char* c, const char* m1, myList* item)
{
    myList* temp = new myList;
    strcpy_s(temp->nomer, nomer);
    strcpy_s(temp->client, m);
    strcpy_s(temp->dceni, c);
    strcpy_s(temp->pdogovora, m1);
    temp->next = item->next;
    item->next = temp;
    return temp;
}
void printList()
{
    setlocale(LC_ALL, "Rus");
    myList* temp = first;
    while (temp != NULL)
    {
        cout << "Номер договора: " << temp->nomer << endl;
        cout << "Фамилия клиента: " << temp->client << endl;
        cout << "Предмет договора: " << temp->pdogovora << endl;
        cout << "Цена: " << temp->dceni << endl;
        cout << endl;
        temp = temp->next;
    }
}
void print(myList* temp)
{
    if (temp != NULL)
    {
        cout << "Номер договора: " << temp->nomer << endl;
        cout << "Фамилия клиента: " << temp->client << endl;
        cout << "Предмет договора: " << temp->pdogovora << endl;
        cout << "Цена: " << temp->dceni << endl;
        cout << endl;
    }
}
myList* indexOf(int item)
{
    if (item < 0)return NULL;
    myList* temp = first;
    if (temp == NULL)return NULL;
    while (temp->next != NULL)
    {
        item--;
        if (item < 0)return temp;
        temp = temp->next;
    }
    if (item == 0)return temp;
    else return NULL;
}
void deleteAfter(myList* item)
{
    if (item != NULL)
    {
        myList* temp = item->next;
        if (temp == NULL) return;
        item->next = temp->next;
        delete temp;
    }
}
 
void deleteAt(int item)
{
    myList* temp;
    if (first == NULL) return;
    if (item == 0)
    {
        temp = first;
        first = temp->next;
        delete temp;
    }
    else
        deleteAfter(indexOf(item - 1));
}
void deleteList()
{
    myList* next;
    myList* temp = first;
    while (temp != NULL)
    {
        next = temp->next;
        delete temp;
        temp = next;
    }
    first = NULL;
}
 
 
 
unsigned int itemsCount()
{
    myList* temp = first;
    unsigned int c = 0;
    while (temp != NULL)
    {
        c++;
        temp = temp->next;
    }
    return c;
}
myList* loadListFromFile(const char* fn)
{
    ifstream f;
    f.open(fn);
    if (f.is_open())
    {
        char n[20], m[15], m1[100], c[22], t[30];
        while (1)
        {
            f.getline(n, 20);
            f.getline(m, 15);
            f.getline(m1, 100);
            f.getline(c, 22);
            if (f.eof())break;
            addLast(n, m, m1, c);
        }
        f.close();
        return first;
    }
    else return NULL;
}
void saveListToFile(const char* fn)
{
    myList* temp = first;
    ofstream f(fn);
    if (f)
    {
        while (temp != NULL)
        {
            f << temp->nomer << endl;
            f << temp->client << endl;
            f << temp->pdogovora << endl;
            f << temp->dceni << endl;
            temp = temp->next;
        }
        f.close();
    }
}
 
myList* findByNomer(const char* n)
{
    myList* temp = first;
    while (temp != NULL)
    {
        if (strcmp(temp->nomer, n) == 0)return temp;
        temp = temp->next;
    }
    return temp;
}
 
myList* findByNomer(myList* firstItem, const char* n)
{
    myList* temp = firstItem;
    while (temp != NULL)
    {
        if (strcmp(temp->nomer, n) == 0)return temp;
        temp = temp->next;
    }
    return temp;
}
 
void PoiskPoNomeru()
{
    char x[38];
    system("cls");
    cout << "Введите номер договора: ";
    cin >> x;
    myList* y = findByNomer(x);
    if (y != NULL)
    {
        print(y);
    }
    else
    {
        cout << "Указаный договор не найден\n";
    }
    cout << "Для продолжения нажмите Enter";
}
myList* findByclient(const char* m)
{
    myList* temp = first;
    while (temp != NULL)
    {
        if (strcmp(temp->client, m) == 0)return temp;
        temp = temp->next;
    }
    return temp;
}
myList* findByclient(myList* firstItem, const char* m)
{
    myList* temp = firstItem;
    while (temp != NULL)
    {
        if (strcmp(temp->client, m) == 0)return temp;
        temp = temp->next;
    }
    return temp;
}
void PoiskPoKlientu()
{
    char r[27];
    system("cls");
    cout << "Введите фамилию клиента: ";
    cin >> r;
    myList* s = findByclient(r);
    if (!s) cout << "Указаный договор не найден" << endl;
    while (s != NULL)
    {
        print(s);
        s = findByclient(s->next, r);
    }
    cout << "Для продолжения нажмите Enter";
}
myList* findBydceni(const char* c)
{
    myList* temp = first;
    while (temp != NULL)
    {
        if (strcmp(temp->dceni, c) == 0)return temp;
        temp = temp->next;
    }
    return temp;
}
myList* findBydceni(myList* firstItem, const char* c)
{
    myList* temp = firstItem;
    while (temp != NULL)
    {
        if (strcmp(temp->dceni, c) == 0)return temp;
        temp = temp->next;
    }
    return temp;
}
 
void PoiskPoDiapozonuCen()
{
    char p[17];
    system("cls");
    cout << "Введите диапозон цены: ";
    cin >> p;
    myList* a = findBydceni(p);
    if (!a) cout << "Указаный договор не найден" << endl;
    while (a != NULL)
    {
        print(a);
        a = findBydceni(a->next, p);
    }
    cout << "Для продолжения нажмите Enter";
}
vector<myList *> findByPriceRange(myList* firstItem, const char *p1, const char *p2)
{
    vector<myList *> res;
    for (myList* temp = firstItem; temp != NULL; temp = temp->next)
        if (strcmp(temp->dceni, p1) >= 0 && strcmp(temp->dceni, p2) <= 0)
            res.push_back(temp);
    return res;
}
 
void addDogovor()
{
    char n[32], m[15], m1[100], c[36];
    system("cls");
    cout << "Введите номер договора: ";
    cin.ignore();
    cin.getline(n, 255);
    cout << "Введите фамилию клиента: ";
    cin.getline(m, 255);
    cout << "Введите предмет договора: ";
    cin.getline(m1, 255);
    cout << "Введите цену договора: ";
    cin.getline(c, 255);
    addLast(n, m, m1, c);
}
 
int Menu()
{
    system("cls");
    setlocale(LC_ALL, "Rus");
    int variant;
    cout << "\t\t\tУЧЁТ ДОГОВОРОВ НОТАРИАЛЬНОЙ КОНТОРЫ\n\n" << endl;
    cout << "\t\t\t\t\tМЕНЮ\n\n"
        << "\t\t\t\tВыберите вариант\n"
        << "\t\t\t\t1. Добавить договор\n"
        << "\t\t\t\t2. Вывод списка договоров\n"
        << "\t\t\t\t3. Поиск договора по номеру\n"
        << "\t\t\t\t4. Поиск договора по фамилии клиента\n"
        << "\t\t\t\t5. Поиск договора по диапозону цен\n"
        << "\t\t\t\t6. Удалить договор по номеру\n\n"
        << "\t\t\t\t7. Выйти из программы\n\n\n\n"
        << "\tДля выбора пункта меню нажмите клавишу с номером нужного действия" << endl;
    cout << ">>> ";
    cin >> variant;
    return variant;
}
 
void DeleteDogovorNomer()
{
    system("cls");
    cout << "Введите номер договора: ";
    char nomer[32];
    cin >> nomer;
    myList* a = findByNomer(nomer);
    int num = 0;
    myList* temp = first;
    if (a != NULL)
    {
        while (temp != NULL)
        {
            if (temp == a) break;
            num++;
            temp = temp->next;
        }
        deleteAt(num);
        cout << "Договор успешно удален, нажмите любую клавишу";
        _getch();
    }
    else
    {
        cout << "Указаный договор не найден, нажмите любую клавишу";
    }
}
 
 
int main()
{
    SetConsoleCP(1251);
    SetConsoleOutputCP(1251);
    system("mode con cols=90 lines=25");
    Auth();
    loadListFromFile("5.txt");
    int variant;
    do
    {
        variant = Menu();
        switch (variant)
        {
        case 1:
            addDogovor();
            cout << "Новый договор добавлен" << endl;
            _getch();
            break;
        case 2:
            system("cls");
            printList();
            cout << "Для продолжения нажмите Enter";
            _getch();
            break;
        case 3:
            PoiskPoNomeru();
            _getch();
            break;
        case 4: PoiskPoKlientu();
            _getch();
            break;
        case 5:
            PoiskPoDiapozonuCen();
            _getch();
            break;
        case 6:
            DeleteDogovorNomer();
            break;
        case 7: cout << "Выход из программы..." << endl;
            saveListToFile("5.txt");
            exit(EXIT_SUCCESS);
            break;
        default:
            cerr << "Вы выбрали неверный вариант" << endl;
            continue;
        }
    } while (true);
    cin.get();
    return 0;
}
Фрагмент (функция) этой программы
C++
1
2
3
4
5
6
7
8
vector<myList*> findByPriceRange(myList* firstItem, const char* p1, const char* p2)
{
vector<myList*> res;
for (myList* temp = firstItem; temp != NULL; temp = temp->next)
if (strcmp(temp->dceni, p1) >= 0 && strcmp(temp->dceni, p2) <= 0)
res.push_back(temp);
return res;
}
0
Лучшие ответы (1)
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
26.06.2020, 13:44
Ответы с готовыми решениями:

Класс "Риэлторская контора"
Здраствуйте,помогите пожалуста с курсовой Задание такое: Риэлторская контора (база предложений...

Что за контора DataArt
Коллеги ! Кто что слышал о компании DataArt (www.dataart.ru). Прочел на главной странице как там...

Крутая контора или перспективный проект?
Мне 22 года. Волгоград. Хотелось бы узнать, при переезде в Москву, насколько важен сам факт...


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

Или воспользуйтесь поиском по форуму:
2
nd2
3437 / 2816 / 1249
Регистрация: 29.01.2016
Сообщений: 9,426
27.06.2020, 04:11 2
Лучший ответ Сообщение было отмечено FreeEagle как решение

Решение

Цитата Сообщение от FreeEagle Посмотреть сообщение
что делает этот фрагмент кода в программе
Отбирает из списка элементы с ценой, которая попадает в заданный диапазон.
Цитата Сообщение от FreeEagle Посмотреть сообщение
и каким образом?
Сравнивает (как Си-строки) цену, прописанную в элементе списка, с диапазоном цен, если цена попадает в диапазон, то адрес этого элемента помещается в результирующий вектор.
1
3 / 3 / 2
Регистрация: 24.03.2020
Сообщений: 153
29.06.2020, 01:01  [ТС] 3
Спасибо большое.
0
29.06.2020, 01:01
Ответ Создать тему
Опции темы

КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru