-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cp
More file actions
171 lines (142 loc) · 4.24 KB
/
main.cp
File metadata and controls
171 lines (142 loc) · 4.24 KB
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
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
using namespace std;
struct Student {
string imie;
string nazwisko;
string nr_albumu;
Student* next;
};
Student* head = nullptr;
Student* create_object() {
Student* nowy = new Student;
if (!nowy) {
cerr << "Błąd dodawania\n";
exit(1);
}
cout << "Podaj imie: ";
cin >> nowy->imie;
cout << "Podaj nazwisko: ";
cin >> nowy->nazwisko;
cout << "Podaj numer albumu: ";
cin >> nowy->nr_albumu;
nowy->next = nullptr;
return nowy;
}
void wstaw() {
ofstream plik;
plik.open("rejestr.txt", ios::app);
if (!plik) {
cerr << "Error opening file\n";
return;
}
Student* nowy = create_object();
if (!head) {
head = nowy;
} else {
nowy->next = head;
head = nowy;
}
plik << nowy->imie << " " << nowy->nazwisko << " " << nowy->nr_albumu << "\n";
plik.close();
}
void wypisz() {
ifstream plik("rejestr.txt");
if (!plik) {
cerr << "Error opening file\n";
return;
}
Student* aktualny = new Student;
while (plik >> aktualny->imie >> aktualny->nazwisko >> aktualny->nr_albumu) {
cout << "Imie: " << aktualny->imie << "\n";
cout << "Nazwisko: " << aktualny->nazwisko << "\n";
cout << "Numer albumu: " << aktualny->nr_albumu << "\n\n";
}
delete aktualny;
plik.close();
}
void szukaj() {
ifstream plik("rejestr.txt");
if (!plik) {
cerr << "Error opening file\n";
return;
}
cout << "Podaj imie: ";
string imie;
cin >> imie;
cout << "Podaj nazwisko: ";
string nazwisko;
cin >> nazwisko;
Student* aktualny = new Student;
while (plik >> aktualny->imie >> aktualny->nazwisko >> aktualny->nr_albumu) {
if (aktualny->imie == imie && aktualny->nazwisko == nazwisko) {
cout << "Imie: " << aktualny->imie << "\n";
cout << "Nazwisko: " << aktualny->nazwisko << "\n";
cout << "Numer albumu: " << aktualny->nr_albumu << "\n";
}
}
delete aktualny;
plik.close();
}
void PrintList(Student* head) {
Student* bierzacy = head;
if (!head) {
cout << "Brak ostatnio dodanych danych\n";
} else {
while (bierzacy != nullptr) {
cout << bierzacy->imie << " " << bierzacy->nazwisko << " " << bierzacy->nr_albumu;
bierzacy = bierzacy->next;
}
}
cout << "\n";
}
int main() {
cout << "-----------------------------\n";
cout << "- REJESTR STUDENTÓW -\n";
cout << "-----------------------------\n\n";
cout << "Wybierz opcje:\n\n";
cout << "1. Dodaj studenta\n";
cout << "2. Wyświetl ostatnio dodanych studentów\n";
cout << "3. Wyświetl całą listę studentów\n";
cout << "4. Wyszukaj studenta\n";
cout << "5. Wyjście\n\n";
int opcja;
cout << "Opcja: ";
cin >> opcja;
switch (opcja) {
case 1:
wstaw();
cout << "\nNACIŚNIJ ENTER ABY WRÓCIĆ DO MENU\n";
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cin.get();
main();
case 2:
cout << "---OSTATNIO DODANE---\n";
PrintList(head);
cout << "\nNACIŚNIJ ENTER ABY WRÓCIĆ DO MENU\n";
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cin.get();
main();
case 3:
cout << "---LISTA STUDENTÓW---\n\n";
wypisz();
cout << "\nNACIŚNIJ ENTER ABY WRÓCIĆ DO MENU\n";
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cin.get();
main();
case 4:
cout << "---WYSZUKIWANIE---\n\n";
szukaj();
cout << "\nNACIŚNIJ DOWOLNY ENTER ABY WRÓCIĆ DO MENU\n";
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cin.get();
main();
case 5:
break;
default:
cout << "Wybierz opcje 1-5\n";
}
return 0;
}