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
| #include <stdio.h>
#include <windows.h>
#include <conio.h>
#include <iostream.h>
#include <fstream.h>
#include <conio.c>
#include <cstring>
#include <stdlib.h>
#include <string.h>
#include <string>
#define N 20
using namespace std;
int main()
{
FILE *file_d;
struct disks
{
int number, date;
char POname[20];
char Disktype[20];
char POtype[20];
char POdeveloper[20];
} disk[N]={};
int i,j,l,a;
int choice;
int check;
int flag=0;
do
{
flag++;
if (flag<2)
{ system("color F0");
cout<<"\n Make a choice!\a\n\n";
cout<<" 1 - Show all records.\n";
cout<<" 2 - Add new record.\n";
cout<<" 3 - Delete file.\n";
cout<<" 4 - Make new file(if file missing).\n";
cout<<" 5 - Search by name of PO.\n";
cout<<" 6 - Search by type of disc.\n";
cout<<" 7 - Search by type of PO.\n";
cout<<" 8 - Search by developer of PO.\n";
cout<<" 9 - Show all records by date over than.\n\n";
cout<<" 10 - Close programm.\n";
cout<<"___________________________________________\n";
}
cin>>choice;
switch(choice)
{
case 1:
if ((file_d = fopen("labfile.txt", "rb")) == NULL)
cout<<"File couldn't be opened. Make new file!\a\n";
else
{
for(j=0; !feof(file_d); j++)
fread(&disk[j], sizeof(struct disks), 1, file_d);
fclose(file_d);
j--;
cout<<" All records\a\n\n\n";
for(i=0; i<j; i++)
printf("%2d|%15s%15s%15s%15d%15s\n", disk[i].number, disk[i].Disktype, disk[i].POname, disk[i].POtype, disk[i].date, disk[i].POdeveloper);
}
break;
case 2:
if ((file_d = fopen("labfile.txt", "rb")) == NULL)
cout<<"File couldn't be opened. Make new file!\a\n";
else
{
for(i=0; !feof(file_d); i++)
fread(&disk[i], sizeof(struct disks), 1, file_d);
fclose(file_d);
cout<<"Fill structure, please.\a\n";
l=1;
i--;
for(a=i; l!=0; i++)
{
disk[i].number = i+1;
cout<<"\nWrite information about disk "<<i+1<<":\n"<<endl;
cout<<"Type of disc(cd,dvd...): "; gets(disk[i].Disktype);
cout<<"PO name: "; gets(disk[i].POname);
cout<<"Type of PO: "; gets(disk[i].POtype);
cout<<"Date of creation: "; scanf ("%d%*c",&disk[i].date);
cout<<"PO developer: "; gets(disk[i].POdeveloper);
cout<<"0 - Go to menu.\a\n";
cout<<"Random number - continue fill structure\n";
scanf ("%d%*c",&l);
}
file_d = fopen("labfile.txt", "ab");
for(; a<i; a++)
fwrite(&disk[a], sizeof(struct disks), 1, file_d);
fclose(file_d);
}
break;
case 3:
cout<<"File delete!\n\a";
remove("labfile.txt");
break;
case 4:
if ((file_d = fopen("labfile.txt", "rb")) == NULL)
{
cout<<"Fill structure, please.\a\n";
l=1;
for(i=0; l!=0; i++)
{
disk[i].number = i+1;
cout<<"\nWrite information about disk "<<i+1<<":\n"<<endl;
cout<<"Type of disc(cd,dvd...): "; gets(disk[i].Disktype);
cout<<"PO name: "; gets(disk[i].POname);
cout<<"Type of PO: "; gets(disk[i].POtype);
cout<<"Date of creation: "; scanf ("%d%*c",&disk[i].date);
cout<<"PO developer: "; gets(disk[i].POdeveloper);
cout<<"0 - Go to menu.\a\n";
cout<<"Random number - continue fill structure\n";
scanf ("%d%*c",&l);
}
file_d = fopen("labfile.txt", "wb");
for(j=0; j<i; j++)
fwrite(&disk[j], sizeof(struct disks), 1, file_d);
fclose(file_d);
}
else
cout<<"File already exists!\a\n";
break;
case 5:
if ((file_d = fopen("labfile.txt", "rb")) == NULL)
cout<<"File couldn't be opened. Make new file!\a\n";
else
{
for(j=0; !feof(file_d); j++)
fread(&disk[j], sizeof(struct disks), 1, file_d);
fclose(file_d);
check=true;
string str;
cout<<"Enter name of PO: ";
cin>>str;
cout<<"\n\nStruct with POname: \a\n";
for(i=0; i<j; i++)
{
if (disk[i].POname==str)
{
printf("%2d|%15s%15s%15s%15d%15s\n", disk[i].number, disk[i].Disktype, disk[i].POname, disk[i].POtype, disk[i].date, disk[i].POdeveloper);
check=false;
}
}
if (check)
cout<<"Nothing found.";
}
cout<<endl;
break;
case 6:
if ((file_d = fopen("labfile.txt", "rb")) == NULL)
cout<<"File couldn't be opened. Make new file!\a\n";
else
{
for(j=0; !feof(file_d); j++)
fread(&disk[j], sizeof(struct disks), 1, file_d);
fclose(file_d);
check=true;
string str;
cout<<"Enter type of disc: ";
cin>>str;
cout<<"\n\nStruct with Disktype: \a\n";
for(i=0; i<j; i++)
{
if (disk[i].Disktype==str)
{
printf("%2d|%15s%15s%15s%15d%15s\n", disk[i].number, disk[i].Disktype, disk[i].POname, disk[i].POtype, disk[i].date, disk[i].POdeveloper);
check=false;
}
}
if (check)
cout<<"Nothing found.\a";
}
cout<<endl;
break;
case 7:
if ((file_d = fopen("labfile.txt", "rb")) == NULL)
cout<<"File couldn't be opened. Make new file!\a\n";
else
{
for(j=0; !feof(file_d); j++)
fread(&disk[j], sizeof(struct disks), 1, file_d);
fclose(file_d);
check=true;
string str;
cout<<"Enter type of PO: ";
cin>>str;
cout<<"\n\nStruct with POtype: \a\n";
for(i=0; i<j; i++)
{
if (disk[i].POtype==str)
{
printf("%2d|%15s%15s%15s%15d%15s\n", disk[i].number, disk[i].Disktype, disk[i].POname, disk[i].POtype, disk[i].date, disk[i].POdeveloper);
check=false;
}
}
if (check)
cout<<"Nothing found.\a";
}
cout<<endl;
break;
case 8:
if ((file_d = fopen("labfile.txt", "rb")) == NULL)
cout<<"File couldn't be opened. Make new file!\a\n";
else
{
for(j=0; !feof(file_d); j++)
fread(&disk[j], sizeof(struct disks), 1, file_d);
fclose(file_d);
check=true;
string str;
cout<<"Enter developer of PO: ";
cin>>str;
cout<<"\n\nStruct with POdeveloper: \a\n";
for(i=0; i<j; i++)
{
if (disk[i].POdeveloper==str)
{
printf("%2d|%15s%15s%15s%15d%15s\n", disk[i].number, disk[i].Disktype, disk[i].POname, disk[i].POtype, disk[i].date, disk[i].POdeveloper);
check=false;
}
}
if (check)
cout<<"Nothing found.\a";
}
cout<<endl;
break;
case 10:
break; // exit(0);
default: cout<<"\nIncorrect choice.\a\n";
case 9:
if ((file_d = fopen("labfile.txt", "rb")) == NULL)
cout<<"File couldn't be opened. Make new file!\a\n";
else
{
for(j=0; !feof(file_d); j++)
fread(&disk[j], sizeof(struct disks), 1, file_d);
fclose(file_d);
check=true;
int n;
cout<<"Show all records relise > ";
cin>>n;
cout<<"\n\nStruct with relise last than "<<n<<" : \a\n";
for(i=0; i<j; i++)
{
if (disk[i].date>=n)
{
printf("%2d|%15s%15s%15s%15d%15s\n", disk[i].number, disk[i].Disktype, disk[i].POname, disk[i].POtype, disk[i].date, disk[i].POdeveloper);
check=false;
}
}
if (check)
cout<<"Nothing found.\a";
}
cout<<endl;
break;
}//switch end
}// do end
while (choice!=10);
remove("labfile.txt");
} // main end |