-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patha.c
More file actions
297 lines (267 loc) · 8.01 KB
/
a.c
File metadata and controls
297 lines (267 loc) · 8.01 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
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
#include<stdlib.h>
#include<stdio.h>
#include<process.h>
struct student{
int rollno;
char name[50];
char branch[5];
int dbms,ds,c,total;
float per;
int std;
}st;
FILE *fptr;
void gotoxy(int x,int y){
printf("%c[%d;%df",0x1B,y,x);
}
void write_student(){
fptr=fopen("student.dat","ab");
printf("\nPlease Enter The New Details of student \n");
printf("\nEnter The roll number of student ");
scanf("%d",&st.rollno);
fflush(stdin);
printf("\n\nEnter The Name of student ");
gets(st.name);
printf("\n\nEnter The branch of student ");
gets(st.branch);
printf("\nEnter The marks in DBMS out of 100 : ");
scanf("%d",&st.dbms);
printf("\nEnter The marks in DS out of 100 : ");
scanf("%d",&st.ds);
printf("\nEnter The marks in C out of 100 : ");
scanf("%d",&st.c);
st.total=st.dbms+st.ds+st.c;
st.per=(st.dbms+st.ds+st.c)/3.0;
fwrite(&st,sizeof(st),1,fptr);
fclose(fptr);
printf("\n\nStudent Record Has Been Created ");
getch();
}
void display_all()
{
system("cls");
printf("\n\n\n\t\tDISPLAY ALL RECORD !!!\n\n");
fptr=fopen("student.dat","rb");
while((fread(&st,sizeof(st),1,fptr))>0){
printf("\nRoll Number of Student : %d",st.rollno);
printf("\nBranch of student : %s",st.branch);
printf("\nName of student : %s",st.name);
printf("\nMarks in DBMS : %d",st.dbms);
printf("\nMarks in DS : %d",st.ds);
printf("\nMarks in C : %d",st.c);
printf("\nPercentage of student is : %.2f",st.per);
printf("\nTotal Marks: %d",st.total);
printf("\n\n====================================\n");
getch();
}
fclose(fptr);
getch();
}
void display_sp(int n)
{
int flag=0;
fptr=fopen("student.dat","rb");
while((fread(&st,sizeof(st),1,fptr))>0){
if(st.rollno==n){
system("cls");
printf("\nRoll Number of Student : %d",st.rollno);
printf("\nBranch of student : %s",st.branch);
printf("\nName of student : %s",st.name);
printf("\nMarks in DBMS : %d",st.dbms);
printf("\nMarks in DS : %d",st.ds);
printf("\nMarks in C : %d",st.c);
printf("\nTotal Marks: %d",st.total);
printf("\nPercentage of student is : %.2f",st.per);
printf("\n\n====================================\n");
flag=1;
}
}
fclose(fptr);
if(flag==0)
printf("\n\nrecord not exist");
getch();
}
void modify_student()
{
int no,found=0;
system("cls");
printf("\n\n\tTo Modify ");
printf("\n\n\tPlease Enter The roll number of student");
scanf("%d",&no);
fptr=fopen("student.dat","rb+");
while((fread(&st,sizeof(st),1,fptr))>0 && found==0)
{
if(st.rollno==no)
{
printf("\nRoll Number of Student : %d",st.rollno);
printf("\nBranch of student : %s",st.branch);
printf("\nName of student : %s",st.name);
printf("\nMarks in DBMS : %d",st.dbms);
printf("\nMarks in DS : %d",st.ds);
printf("\nMarks in C : %d",st.c);
printf("\nTotal Marks: %d",st.total);
printf("\nPercentage of student is : %.2f",st.per);
printf("\nPlease Enter The New Details of student \n");
fflush(stdin);
printf("\n\nEnter The Name of student ");
gets(st.name);
printf("\n\nEnter The branch of student ");
gets(st.branch);
printf("\nEnter The marks in DBMS out of 100 : ");
scanf("%d",&st.dbms);
printf("\nEnter The marks in DS out of 100 : ");
scanf("%d",&st.ds);
printf("\nEnter The marks in C out of 100 : ");
scanf("%d",&st.c);
st.total=st.dbms+st.ds+st.c;
st.per=(st.dbms+st.ds+st.c)/3.0;
fseek(fptr,-(long)sizeof(st),1);
fwrite(&st,sizeof(st),1,fptr);
printf("\n\n\t Record Updated");
found=1;
}
}
fclose(fptr);
if(found==0)
printf("\n\n Record Not Found ");
getch();
}
void delete_student()
{
int no;
FILE *fptr2;
system("cls");
printf("\n\n\n\tDelete Record");
printf("\n\nPlease Enter The roll number of student You Want To Delete");
scanf("%d",&no);
fptr=fopen("student.dat","rb");
fptr2=fopen("Temp.dat","wb");
rewind(fptr);
while((fread(&st,sizeof(st),1,fptr))>0){
if(st.rollno!=no){
fwrite(&st,sizeof(st),1,fptr2);
}
}
fclose(fptr2);
fclose(fptr);
remove("student.dat");
rename("Temp.dat","student.dat");
printf("\n\n\tRecord Deleted ..");
getch();
}
void class_result()
{
system("cls");
fptr=fopen("student.dat","rb");
if(fptr==NULL){
printf("ERROR!!! FILE COULD NOT BE OPEN\n\n\n Go To Entry Menu to create File");
printf("\n\n\n Program is closing ....");
getch();
exit(0);
}
printf("\n\n\t\tALL STUDENTS RESULT \n\n");
printf("====================================================\n");
printf("R.No. Branch Name DBMS DS C percentage TOTAL\n");
printf("====================================================\n");
while((fread(&st,sizeof(st),1,fptr))>0)
{
printf("%-6d %-2s %-10s %-3d %-3d %-3d %-3.2f percent %-3d \n",st.rollno,st.branch,st.name,st.dbms,st.ds,st.c,st.per,st.total);
}
fclose(fptr);
getch();
}
void result(){
int ans,rno;
char ch;
system("cls");
printf("\n\n\nRESULT MENU");
printf("\n\n\n1. Class Result\n\n2. Student Report Card\n\n3.Back to Main Menu");
printf("\n\n\nEnter Choice (1/2)? ");
scanf("%d",&ans);
switch(ans)
{
case 1 : class_result();break;
case 2 : {
do{
char ans;
system("cls");
printf("\n\nEnter Roll Number Of Student : ");
scanf("%d",&rno);
display_sp(rno);
printf("\n\nDo you want to See More Result (y/n)?");
scanf("%c",&ans);
}while(ans=='y'||ans=='Y');
break;
}
case 3: break;
default: printf("\a");
}
}
void intro()
{
system("cls");
gotoxy(35,11);
printf("STUDENT Database \n");
printf("Assignment 1");
printf("\n\n\n\n\n\nMADE BY : Ekaansh Ahuja");
printf("\nRoll number : 19ucc077\n\n");
printf("press ENTER to continue...");
getch();
}
void entry_menu()
{
char ch2;
system("cls");
printf("\n\n\n\tENTRY MENU");
printf("\n\n\t1.CREATE STUDENT RECORD");
printf("\n\n\t2.DISPLAY ALL STUDENTS RECORDS");
printf("\n\n\t3.SEARCH STUDENT RECORD ");
printf("\n\n\t4.MODIFY STUDENT RECORD");
printf("\n\n\t5.DELETE STUDENT RECORD");
printf("\n\n\t6.BACK TO MAIN MENU");
printf("\n\n\tPlease Enter Your Choice (1-6) ");
ch2=getche();
switch(ch2)
{
case '1': system("cls");
write_student();
break;
case '2': display_all();break;
case '3': {
int num;
system("cls");
printf("\n\n\tPlease Enter The roll number ");
scanf("%d",&num);
display_sp(num);
}
break;
case '4': modify_student();break;
case '5': delete_student();break;
case '6': break;
default:printf("\a");entry_menu();
}
}
void main()
{
char ch;
intro();
do
{
system("cls");
printf("\n\n\n\tMAIN MENU");
printf("\n\n\t01. RESULT MENU");
printf("\n\n\t02. ENTRY/EDIT MENU");
printf("\n\n\t03. EXIT");
printf("\n\n\tPlease Select Your Option (1-3) ");
ch=getche();
switch(ch)
{
case '1': system("cls");
result();
break;
case '2': entry_menu();
break;
case '3':exit(0);
default :printf("\a");
}
}while(ch!='3');
}