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
| #include <iostream>
#include <string>
#include "Windows.h"
using namespace std;
struct Students {
int number;
string student;
double math;
double physic;
double IT;
double score;
};
struct secondlist {
Students p;
secondlist* next;
secondlist* prev;
};
secondlist* head;
void AddList(int position, int number, string student, int math, int physic,int IT, double score)
{
secondlist* node = new secondlist;
node->p.number = number;
node->p.student = student;
node->p.math = math;
node->p.physic = physic;
node->p.IT = IT;
node->p.score = score;
if (head == NULL)
{
node->next = node;
node->prev = node;
head = node;
}
else
{
secondlist* p = head;
for (int i = position; i > 1; i--) p = p->next;
p->prev->next = node;
node->prev = p->prev;
node->next = p;
p->prev = node;
}
cout << "\nЭлемент добавлен!\n";
}
void calcEL()
{
int calc_e = 0;
if (head == NULL) cout << "\nСписок пустой!\n";
else
{
secondlist* a = head;
do
{
a = a->next;
calc_e++;
} while (a != head); cout << endl;
cout << "Элементов в списке: " << calc_e << endl;
}
}
void print2(int n)
{
secondlist* print = head->next;
cout << "==================================" << endl;
cout << "| №№ | СТУДЕНТ |МT|ФЗ|IT|РЕЙТИНГ|" << endl;
cout << "|====|==========|==|==|==|=======|" << endl;
for (int i = 0; i < n; i++) {
cout << "|" << print->p.number << "|" << "\t";
cout << print->p.student << "\t";
cout << "|" << print->p.math << "|";
cout << print->p.physic;
cout << "|" << print->p.IT;
cout << "|" << print->p.score << "|" << endl;
print = print->next;
}
cout << "==================================" << endl;
cout << "|\t№№ - номер зачетной |\n|\tMT - математика |\n|\tФЗ - физика |\n|\tІТ - информатика |" << endl;
cout << "==================================" << endl;
}
void DeleteList(int position)
{
if (head == NULL) { cout << "\nСписок пустой!\n"; }
if (head == head->next)
{
delete head;
head = NULL;
}
else
{
secondlist* a = head;
for (int i = position; i > 1; i--) a = a->next;
if (a == head) head = a->next;
a->prev->next = a->next;
a->next->prev = a->prev;
delete a;
}
cout << "\nЭлемент удален!\n";
}
int main()
{
int value, n,position = 1, calc = 0, x;
int number, math, physic, IT;
double score;
string student;
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
cout << "Начальное кол-во элементов: ";
cin >> n;
for (int i = 0; i < n && i < position; i++) {
position++;
cout << "№ зачетной: "; cin >> number; cout << "Фамилия "; cin >> student; cout << "Математика: "; cin >> math; cout << "Физика: "; cin >> physic; cout << "IT: "; cin >> IT;
score = (math + physic + IT) / 3.0;
AddList(position, number, student, math, physic, IT, score);
}
print2(n);
do
{
cout << "1. Добавить элемент" << endl;
cout << "2. Удаление элемента" << endl;
cout << "3. Просмотр списка" << endl;
cout << "4. Подсчитать кол-во элементов в списке" << endl;
cout << "0. Выйти" << endl;
cout << "\nНомер операции: "; cin >> x;
switch (x)
{
case 1:
cout << "№ зачетной: "; cin >> number; cout << "Фамилия "; cin >> student; cout << "Математика: "; cin >> math; cout << "Физика: "; cin >> physic; cout << "IT: "; cin >> IT;
score = (math + physic + IT) / 3.0;
n++;
AddList(position, number, student, math, physic, IT, score);
print2(n);
break;
case 2:
cout << "Удаление с позиции №: "; cin >> position;
DeleteList(position); n--; print2(n); break;
case 3: print2(n);; break;
case 4: calcEL(); break;
}
} while (x != 0);
} |