1
+ #include < iostream>
2
+ #include < conio.h>
3
+ #include < fstream>
4
+
5
+ using namespace std ;
6
+
7
+ struct football
8
+ {
9
+ string name;
10
+ string position;
11
+ int touchdowns;
12
+ int catches;
13
+ int passingYard;
14
+ int receivingYard;
15
+ int rushingYard;
16
+ };
17
+
18
+ int count = 0 ;
19
+ const int size = 10 ;
20
+
21
+ void head ();
22
+ char menu ();
23
+ football addPlayer ();
24
+ void show (football player);
25
+ void viewPlayer (football player[size]);
26
+ void search (football player[size]);
27
+ int finding (football player[size], string search);
28
+ void loadData (football player[size]);
29
+ string parseData (string line, int field);
30
+ void storeData (football player);
31
+
32
+ main ()
33
+ {
34
+
35
+ football player[size];
36
+
37
+ loadData (player);
38
+
39
+ while (true )
40
+ {
41
+ system (" cls" );
42
+ char Option;
43
+ Option = menu ();
44
+
45
+ if (Option == ' 1' )
46
+ {
47
+ viewPlayer (player);
48
+ }
49
+ else if (Option == ' 2' )
50
+ {
51
+ player[count] = addPlayer ();
52
+ char yn ;
53
+ cout << " DO YOU WANT SAVE DATA ! (Y/N) : " ;
54
+ cin >> yn ;
55
+ if ( yn == ' y' || yn == ' Y' )
56
+ {
57
+ storeData ( player[count]);
58
+ count++;
59
+ }
60
+
61
+ }
62
+ else if (Option == ' 3' )
63
+ {
64
+ search (player);
65
+ }
66
+ else if (Option == ' 4' )
67
+ {
68
+ break ;
69
+ }
70
+ }
71
+ }
72
+
73
+ void head ()
74
+ {
75
+ cout << " ****************************************" << endl;
76
+ cout << " * Football Players Information *" << endl;
77
+ cout << " ****************************************" << endl;
78
+ cout << " \n " ;
79
+ }
80
+
81
+ char menu ()
82
+ {
83
+ char Option;
84
+ head ();
85
+ cout << " Menu >> " << endl;
86
+ cout << " ________________________________________" << endl;
87
+ cout << " \n " ;
88
+ cout << " 1. View All Players " << endl;
89
+ cout << " 2. Add Player " << endl;
90
+ cout << " 3. Search " << endl;
91
+ cout << " 4. Exit" << endl;
92
+
93
+ cout << " \n Select Your Option....." ;
94
+ Option = getche ();
95
+
96
+ return Option;
97
+ }
98
+
99
+ football addPlayer ()
100
+ {
101
+ football player;
102
+ system (" cls" );
103
+ head ();
104
+ cout << " Add Player >> " << endl;
105
+ cout << " ________________________________________" << endl;
106
+ cout << " \n " ;
107
+ cout << " PLayer Name : " ;
108
+
109
+ getline (cin, player.name );
110
+ cout << " Position : " ;
111
+ cin >> player.position ;
112
+ cout << " Number of Touchdowns : " ;
113
+ cin >> player.touchdowns ;
114
+ cout << " Number of Catches : " ;
115
+ cin >> player.catches ;
116
+ cout << " Number of Passing Yards : " ;
117
+ cin >> player.passingYard ;
118
+ cout << " Number of Receving Yards : " ;
119
+ cin >> player.receivingYard ;
120
+ cout << " Number of Rushing Yards : " ;
121
+ cin >> player.rushingYard ;
122
+ cout << " \n New Player Added Succesfully :)" << endl;
123
+ cout << " \n Press any Key to continue....." ;
124
+ getch ();
125
+ return player;
126
+ }
127
+
128
+ void viewPlayer (football player[size])
129
+ {
130
+ system (" cls" );
131
+ head ();
132
+ cout << " All Players >> " << endl;
133
+ cout << " ________________________________________" << endl;
134
+ cout << " \n " ;
135
+ cout << " Name\t\t Position\t Touchdowns\t Catches\t Passing Yard\t Receiving Yard\t Rushing Yard" << endl;
136
+ cout << " \n " ;
137
+
138
+ for (int idx = 0 ; idx < count; idx++)
139
+ {
140
+ show (player[idx]);
141
+ }
142
+ cout << " \n Press any Key to continue....." ;
143
+ getch ();
144
+ }
145
+
146
+ void show (football player)
147
+ {
148
+ cout << " " << player.name << " \t\t " << player.position << " \t\t " << player.touchdowns << " \t\t " << player.catches << " \t " << player.passingYard << " \t\t " << player.receivingYard << " \t\t " << player.rushingYard << endl;
149
+ }
150
+
151
+ void search (football player[size])
152
+ {
153
+ string search;
154
+ system (" cls" );
155
+ head ();
156
+ cout << " Search Player >> " << endl;
157
+ cout << " ________________________________________" << endl;
158
+ cout << " \n " ;
159
+
160
+ cout << " Enter Player Name : " ;
161
+ // cin.ignore();
162
+ getline (cin, search);
163
+
164
+ int idx = -1 ;
165
+ idx = finding (player, search);
166
+
167
+ getch ();
168
+
169
+ if (idx > count || idx < 0 )
170
+ {
171
+ cout << " Nothing Find :( " << endl;
172
+ }
173
+ else
174
+ {
175
+ cout << " Name\t\t Position\t Touchdowns\t Catches\t Passing Yard\t Receiving Yard\t Rushing Yard" << endl;
176
+ cout << " \n " ;
177
+ show (player[idx]);
178
+ }
179
+
180
+ cout << " \n Press any Key to continue....." ;
181
+ getch ();
182
+ }
183
+
184
+ int finding (football player[size], string search)
185
+ {
186
+ for (int idx = 0 ; idx < count; idx++)
187
+ {
188
+ if (search == player[idx].name )
189
+ {
190
+ return idx;
191
+ }
192
+ }
193
+ return -1 ;
194
+ }
195
+
196
+ void loadData (football player[size])
197
+ {
198
+ fstream file;
199
+ string line;
200
+
201
+ file.open (" PlayersData.txt" , ios::in);
202
+
203
+ while (!file.eof ())
204
+ {
205
+ getline (file, line);
206
+
207
+ player[count].name = parseData (line, 1 );
208
+ player[count].position = parseData (line, 2 );
209
+ player[count].touchdowns = stoi (parseData (line, 3 ));
210
+ player[count].catches = stoi (parseData (line, 4 ));
211
+ player[count].passingYard = stoi (parseData (line, 5 ));
212
+ player[count].receivingYard = stoi (parseData (line, 6 ));
213
+ player[count].rushingYard = stoi (parseData (line, 7 ));
214
+ count++;
215
+ }
216
+
217
+ file.close ();
218
+ }
219
+
220
+ string parseData (string line, int field)
221
+ {
222
+ string item;
223
+ int comma = 1 ;
224
+ for (int i = 0 ; i < line.length (); i++)
225
+ {
226
+ if (line[i] == ' ,' )
227
+ {
228
+ comma++;
229
+ }
230
+ else if (comma == field)
231
+ {
232
+ item = item + line[i];
233
+ }
234
+ }
235
+ return item;
236
+ }
237
+
238
+ void storeData (football player)
239
+ {
240
+ fstream file;
241
+
242
+ file.open (" PlayersData.txt" , ios::app);
243
+
244
+ file << " \n " ;
245
+ file << player.name << " ," ;
246
+ file << player.position << " ," ;
247
+ file << player.touchdowns << " ," ;
248
+ file << player.catches << " ," ;
249
+ file << player.passingYard << " ," ;
250
+ file << player.receivingYard << " ," ;
251
+ file << player.rushingYard << " ," ;
252
+
253
+ file.close ();
254
+ }
0 commit comments