-
Notifications
You must be signed in to change notification settings - Fork 0
/
mini-project.c
315 lines (270 loc) · 5.44 KB
/
mini-project.c
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#include <stdio.h>
#include<conio.h>
#include<string.h>
#include<dos.h>
#define amt 300
FILE *fp;
long int size;
struct donor
{
char name[25];
int age;
char address1[30];
char address2[30];
char city[20];
char phn[11];
char bloodgrp[4];
char email[40];
int id;
};
struct donor b; //declaration of structure
void putdonor(); //store the data in file
void getdonor(); //display data
void donorbyid();
void donorbycity();
void calamt(); //calculate sum to be paid to donor
void menu(); //display menu
void creden(); //display credentials
void main()
{
int i;
i=1;
size=sizeof(b); //finding size of structure
while(i<=7)
{
printf("\n\n\n\n\n\n\n\n\t\t\t\t Initializing");
if(i<7)
{
}
i++;
}
printf(".");
printf(".");
printf(".");
menu();
getch();
}
void putdonor()
{
char a;
fp=fopen("BDONOR.DAT","wb+"); //opening a binary file
if(fp==NULL)
{
puts("Cannot Open File");
exit(0);
}
fseek(fp,0,SEEK_END); //putting the pointer at the end of the file
do
{
fflush(stdin);
printf("\n\tEnter Name : ");
gets(b.name);
printf("\n\tEnter Your Age : ");
scanf("%d",&b.age);
fflush(stdin);
printf("\n\tEnter Your Donor ID : ");
scanf("%d",&b.id);
printf("\n\tEnter Address Line 1 : ");
fflush(stdin);
gets(b.address1);
printf("\n\tEnter Address Line 2 : ");
gets(b.address2);
printf("\n\tEnter City : ");
gets(b.city);
printf("\n\tEnter Blood Group : ");
gets(b.bloodgrp);
printf("\n\tEnter Your 10 Digit Moblie Number : ");
scanf("%s",b.phn);
fflush(stdin);
printf("\n\tEnter Your Email : ");
scanf("%s",b.email);
fwrite(&b,size,1,fp);
printf("\n\tDo You Want To Add Another Data\n Enter(Y / N)");
fflush(stdin);
scanf("%c",&a);
}while(a=='Y'||a=='y');
fclose(fp);
menu();
}
void getdonor()
{
char bld[4];
char a='y';
fp=fopen("BDONOR.DAT","rb");
if(fp==NULL)
{
puts("Cannot Open File");
exit(0);
}
fflush(stdin);
printf("\n\tEnter The Blood Group : ");
scanf("%s",bld);
rewind(fp);
while(fread(&b,size,1,fp)==1)
{
if(a=='Y'||a=='y')
{
if(strcmp(b.bloodgrp,bld)==0) //matching the blood group required with the one's present in Database
{
printf("\n\tName : %s \n\tDonor Id : %d \n\tAge : %d \n\tAddress Line : %s \n\tAddress Line 2 : %s \n\tCity : %s \n\tPhone No : %s \n\tEmail : %s \n\tBlood Grouo : %s \n\n",b.name,b.id,b.age,b.address1,b.address2,b.city,b.phn,b.email,b.bloodgrp);
printf("\n\n\tSee More(Y/N)");
fflush(stdin);
scanf("%c",&a);
}
}
}
if(a=='n'||a=='N')
{
fclose(fp);
menu();
}
else
{
printf("\n\n\n\t\t No More Records Found......!!!");
printf("\n\nBack to Main Menu in 7 Seconds");
fclose(fp);
menu();
}
}
void menu()
{
int choice;
printf("\n\n\t\t\tBLOOD DONOR DATABSE \n\n\n");
printf("\t1 Add a new entry\n\n");
printf("\t2 Search by Blood Group \n\n");
printf("\t3 Search by Donor Id\n\n");
printf("\t4 Search by City\n\n");
printf("\t5 Calculate the amount to be paid to Donor\n\n");
printf("\t6 Credentials\n\n");
printf("\t7 Exit the program\n\n");
printf("\t Your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1 : putdonor();
break;
case 2 : getdonor();
break;
case 3 : donorbyid();
break;
case 4 : donorbycity();
break;
case 5 : calamt();
break;
case 6 : creden();
break;
case 7 : exit(0);
default :
printf("\n\n\t\tYou have entered wrong choce....!!!");
menu();
}
}
void calamt()
{
float unit,sum;
printf("\n\n\tEnter the unit donated : ");
scanf("%f",&unit);
sum=unit*amt; //Calculating the amount to be paid
printf("\n\tAmount paid per unit = Rs.%d\n\n",amt);
printf("\n\tTotal Amount to be paid = Rs.%f\n",sum);
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nBack to Main Menu in 7 seconds");
menu();
}
void creden()
{
printf("\n\n\t\t\t\tBLOOD DONOR DATABASE\n\n\n");
printf("\t\t\tTeacher Incharge : ABDUL AHAD\n");
printf("\n\n\t\tTeam Lead : ZAINA AHAD\n");
printf("\n\n\t\tTeam Members : \n");
printf("\n\t\t\tAKASH\n\t\t\tGARG\n");
printf("\t\t\tAZBAQ\n\t\t\tKHAN\n");
printf("\n\n\nBack to Main Menu in 10 seconds");
menu();
}
void donorbyid()
{
int id;
char a='y';
fp=fopen("BDONOR.DAT","rb");
if(fp==NULL)
{
puts("Cannot Open File");
exit(0);
}
fflush(stdin);
printf("\n\tEnter the Donor Id : ");
scanf("%d",&id);
rewind(fp);
while(fread(&b,size,1,fp)==1)
{
if(a=='Y'||a=='y')
{
if(b.id==id)
{
printf("\n\tName : %s \n\tdonor Id : %d \n\tAge : %d \n\tAddress Line 1 : %s \n\tCity : %s \n\tPhone No : %s \n\tEmail :%s \n\tBlood Group : %s \n\n",b.name,b.id,b.age,b.address1,b.address2,b.city,b.phn,b.email,b.bloodgrp);
printf("\n\n\tSee More(Y / N)");
fflush(stdin);
scanf("%c",&a);
}
}
}
if(a=='n'||a=='N')
{
fclose(fp);
menu();
}
else
{
printf("\n\n\n\t\t NO MORE RECORDS FOUND....!!!");
printf("\n\n Back to Main Menu in 7 seconds");
fclose(fp);
menu();
}
}
void donorbycity()
{
char city[20];
char a='y';
fp=fopen("BDONOR.DAT","rb");
if(fp==NULL)
{
puts("Cannot Open File");
exit(0);
}
fflush(stdin);
printf("\n\tEnter the City : ");
scanf("%s",&city);
rewind(fp);
while(fread(&b,size,1,fp)==1)
{
if(a=='Y'||a=='y')
{
if((strcmp(b.city,city))==0) //Matching the Bloodgroup required with the one's present in Databse
{
printf("\n\tName : %s \n\tdonor Id : %d \n\tAge : %d \n\tAddress Line 1 : %s \n\tCity : %s \n\tPhone No : %s \n\tEmail :%s \n\tBlood Group : %s \n\n",b.name,b.id,b.age,b.address1,b.address2,b.city,b.phn,b.email,b.bloodgrp);
printf("\n\n\tSee More(Y /N)");
fflush(stdin);
scanf("%c",&a);
}
}
}
if(a=='n'||a=='N')
{
fclose(fp);
menu();
}
else
{
printf("\n\n\n\t\t NO MORE RECORDS FOUND....!!!");
printf("\n\n Back to Main Menu in 7 seconds");
fclose(fp);
menu();
}
}
//floating point Emulator
void linkfloat()
{
float a=0,*b;
b=&a;
a=*b;
}