-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
256 lines (238 loc) · 8.75 KB
/
main.cpp
File metadata and controls
256 lines (238 loc) · 8.75 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
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
#include <iostream>
#include<string>
#include<fstream>
using namespace std;
void menu () {
////////////////
cout << "***************************************************************************" << endl ;
cout << "1 - Add A New Student. " << endl ;
cout << "2 - Update A Student Data." << endl ;
cout << "3 - Remove A Student Data." << endl ;
cout << "4 - search About A Student Data." << endl ;
cout << "5 - search About A Level Data." << endl ;
cout << "6 - Print All Student Data." << endl ;
cout << "7 - Exit." << endl ;
cout << "***************************************************************************" << endl ;
////////////////
}
bool check_id( int real_id){
ifstream f;
f.open("data.txt", ios::in);
int id , level , Database, Algorithms, Math, English, Drawing ;
string Name;
while (!f.eof())
{
f >> id >> Name >> level >> Database >> Algorithms >> Math >> English >> Drawing;
if (id == real_id) {
f.close();
return false;
}
}
f.close();
return true;
}
void add_student()
{
std::ofstream outfile;
int num = 0;
cout << " How Many Student You want to Add : " ; cin >> num ;
cout << " Enter Student Data :\n \"id, Name, level, Database, Algorithms, Math, English and Drawing\"\n ";
///////////////
while(num--){
int id , level , Database, Algorithms, Math, English, Drawing ;
string Name ;
////////
outfile.open("data.txt", std::ios_base::app);
cin >> id >> Name >> level >> Database >> Algorithms >> Math >> English >> Drawing ;
////////
if(check_id(id))
outfile << id << " " << Name << " " << level << " " << Database << " " << Algorithms << " " << Math << " " << English << " " << Drawing << " \n" ;
else
cout << "That Id is Found in The Data !" << endl;
outfile.close();
}
}
void file_updated(){
ifstream f;
std::ofstream outfile;
int status = remove("data.txt");
outfile.open("data.txt", std::ios_base::app);
outfile.clear();
///////////////
cout << endl ;
/////////////////////////
bool ok = false ;
f.open("data_2.txt", ios::in);
int pre_id=0 ,id , level , Database, Algorithms, Math, English, Drawing ;
string Name;
while (!f.eof())
{
f >> id >> Name >> level >> Database >> Algorithms >> Math >> English >> Drawing;
if(pre_id != id)
outfile << id << " " << Name << " " << level << " " << Database << " " << Algorithms << " " << Math << " " << English << " " << Drawing << " \n" ;
pre_id = id ;
}
f.close();
outfile.close();
////////////////////////////////////////
}
void update_student(){
ifstream f;
std::ofstream outfile;
outfile.open("data_2.txt", std::ios_base::app);
///////////////
int find_id , pre_id =0;
cout << "Enter the id that you Want to update it : " ; cin >> find_id ;
cout << endl ;
/////////////////////////
bool ok = false ;
f.open("data.txt", ios::in);
int id , level , Database, Algorithms, Math, English, Drawing ;
string Name;
while (!f.eof())
{
f >> id >> Name >> level >> Database >> Algorithms >> Math >> English >> Drawing;
if(id == find_id && id != pre_id){
cout << "Enter The New Data : " << endl ;
cin >> id >> Name >> level >> Database >> Algorithms >> Math >> English >> Drawing ;
outfile << id << " " << Name << " " << level << " " << Database << " " << Algorithms << " " << Math << " " << English << " " << Drawing << " \n" ;
ok = 1;
}
else
{
outfile << id << " " << Name << " " << level << " " << Database << " " << Algorithms << " " << Math << " " << English << " " << Drawing << " \n" ;
}
pre_id = id ;
}
f.close();
outfile.close();
file_updated();
if(!ok)
cout << "That ID is not found in the data ! " << endl ;
int status = remove("data_2.txt");
}
void remove_student(){
ifstream f;
std::ofstream outfile;
outfile.open("data_2.txt", std::ios_base::app);
///////////////
int find_id;
cout << "Enter the id that you Want to remove it : " ; cin >> find_id ;
cout << endl ;
/////////////////////////
bool ok = false ;
f.open("data.txt", ios::in);
int id , level , Database, Algorithms, Math, English, Drawing ;
string Name;
while (!f.eof())
{
f >> id >> Name >> level >> Database >> Algorithms >> Math >> English >> Drawing;
if(id == find_id ){
outfile <<"" ;
ok = 1;
}
else
{
outfile << id << " " << Name << " " << level << " " << Database << " " << Algorithms << " " << Math << " " << English << " " << Drawing << " \n" ;
}
}
f.close();
outfile.close();
file_updated();
if(!ok)
cout << "That ID is not found in the data ! " << endl ;
int status = remove("data_2.txt");
}
void search_student(){
ifstream f;
int find_id ;
cout << "Enter the id that you Want to search about it : " ; cin >> find_id ;
cout << endl ;
/////////////////////////
bool ok = false ;
f.open("data.txt", ios::in);
int pre_id =0, id , level , Database, Algorithms, Math, English, Drawing ;
string Name;
while (!f.eof())
{
f >> id >> Name >> level >> Database >> Algorithms >> Math >> English >> Drawing;
if(id == find_id && pre_id != id){
cout << "******************** ALL THE STUDENT DATA *****************"<< endl ;
cout << id << " " << Name << " " << level << " " << Database << " " << Algorithms << " " << Math << " " << English << " " << Drawing << " \n" ;
ok = 1;
}
pre_id = id ;
}
f.close();
if(!ok)
cout << "That ID is not found in the data ! " << endl ;
}
void search_level(){
ifstream f;
int find_id ;
cout << "Enter the Level that you Want to search about it : " ; cin >> find_id ;
cout << endl ;
/////////////////////////
bool ok = false ;
f.open("data.txt", ios::in);
int pre_id =0, id , level , Database, Algorithms, Math, English, Drawing ;
string Name;
cout << "******************** ALL THE STUDENT DATA *****************"<< endl ;
while (!f.eof())
{
f >> id >> Name >> level >> Database >> Algorithms >> Math >> English >> Drawing;
if(level == find_id && pre_id != id ){
cout << id << " " << Name << " " << level << " " << Database << " " << Algorithms << " " << Math << " " << English << " " << Drawing << " \n" ;
ok = 1;
}
pre_id = id;
}
f.close();
if(!ok)
cout << "That LEVEL Has no students !!" << endl ;
}
void print_all_data(){
ifstream f;
f.open("data.txt", ios::in);
int pre_id =0,id , level , Database, Algorithms, Math, English, Drawing ;
string Name;
cout << "******************** ALL THE STUDENTS DATA *****************"<< endl ;
while (!f.eof())
{
f >> id >> Name >> level >> Database >> Algorithms >> Math >> English >> Drawing;
if ( pre_id != id)
cout << id << " " << Name << " " << level << " " << Database << " " << Algorithms << " " << Math << " " << English << " " << Drawing << " \n" ;
pre_id = id;
}
f.close();
}
int main()
{
////////////////
int option = 1 ;
////////////////
while(option)
{
menu();
////////
cout << "Enter Your Option Please : " ; cin >> option ;
//////////
if(option == 1 )
add_student();
else if(option == 2 )
update_student();
else if(option == 3)
remove_student();
else if(option == 4)
search_student();
else if(option == 5)
search_level();
else if(option == 6)
print_all_data();
else if ( option == 7 || option == -1)
return cout << "***********************Thanks For Using The Application ^_^ ***********************\n***********************Good Bye*********************************" << endl ,0;
else
cout << "Please Make A Right choice from the Menu ! " << endl ;
}
return 0;
}