//PROGRAM FOR THE IMPLEMENTATION OF UNIVERSITY DATABASE
#include<stdio.h>
#include<string.h>
#include<fcntl.h>
#include<stdlib.h>
main()
{
FILE *f1,*f2,*f3,*f4,*f5;
char c;
int a,k,k1,k2,k3,k4;
//GETTING THE VALUE OF NUMBER OF ENTRIES IN THE RESPECTIVE DATBASE
f4=fopen("counter","r");
c=getc(f4);
c=c-48;
a=c;
//printf("%d",a);
k=a;
fclose(f4);
f4=fopen("counter1","r");
c=getc(f4);
c=c-48;
a=c;
//printf("%d",a);
k1=a;
fclose(f4);
f4=fopen("counter2","r");
c=getc(f4);
c=c-48;
a=c;
//printf("%d",a);
k2=a;
fclose(f4);
f4=fopen("counter3","r");
c=getc(f4);
c=c-48;
a=c;
//printf("%d",a);
k3=a;
fclose(f4);
f4=fopen("counter4","r");
c=getc(f4);
c=c-48;
a=c;
//printf("%d",a);
k4=a;
fclose(f4);
int ch,ch1,ch2,ch3,ch4,ch5,r=0,r1=0,r3=0,r2=0,r4=0,p=0,i,j,n,q=0,m,e,d=1;
char d1[2], sname[10],snum[2],ssn[10],caddr[20],paddr[20], bday[10],sex[2],cl[10],mindept[5],majdept[5],deg[5];
for(;;)
{
printf("\n\t1.student info\t2.dept info\n\t3.Course info\t4.Section info\n\t 5.Grade report\t6.Exit\n");
printf("\tenter ur choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1: for(;;)
{
//OPERATION ON THE STUDENT DETAILS
printf("\n\t1.Add student\t 2.search student\n\t 3.delete student\t4.Exit\n");
printf("\tenter ur choice\n");
scanf("%d",&ch1);
switch(ch1)
{
case 1: k++;
// printf("k=%d\n",k);
f1=fopen("student","a+");
fprintf(f1,"\n");
printf("SNUM:\t");
scanf("%s",snum);
fprintf(f1,"%s\t",snum);
printf("SNAME:\t");
scanf("%s",sname);
fprintf(f1,"%s\t",sname);
printf("SSN:\t");
scanf("%s",ssn);
fprintf(f1,"%s\t",ssn);
printf("Caddr:\t");
scanf("%s",caddr);
fprintf(f1,"%s\t",caddr);
printf("Paddr:\t");
scanf("%s",paddr);
fprintf(f1,"%s\t",paddr);
printf("BDAY:\t");
scanf("%s",bday);
fprintf(f1,"%s\t",bday);
printf("SEX:\t");
scanf("%s",sex);
fprintf(f1,"%s\t",sex);
printf("CLASS:\t");
scanf("%s",cl);
fprintf(f1,"%s\t",cl);
printf("MIN dept:\t");
scanf("%s",mindept);
fprintf(f1,"%s\t",mindept);
printf("MAJ dept:\t");
scanf("%s",majdept);
fprintf(f1,"%s\t",majdept);
printf("DEG:\t");
scanf("%s",deg);
fprintf(f1,"%s\n",deg);
fclose(f1);
break;
case 2: printf("enter the student number to be searched\n");
scanf("%s",d1);
f2=fopen("student","r");
for(i=0;i<77;i++)
{
fscanf(f2,"%s",sname);
if(strcmp(d1,sname)==0)
{
printf("%s\t",sname);
for(j=0;j<10;j++)
{
fscanf(f2,"%s",ssn);
printf("%s\t",ssn);
}
break;
}
}
fclose(f2);
break;
case 3: printf("enter the student number to be deleted\n");
scanf("%s",d1);
f2=fopen("student","r");
f3=fopen("temp1","w");
m=k*11;
m=m-11;
// printf("m=%d\n",m);
for(i=0;i<m;i++)
{
fscanf(f2,"%s",sname);
if(strcmp(d1,sname)==0)
{
for(i=0;i<10;i++)
{
fscanf(f2,"%s",sname);
}
printf("\nthe student is deleted");
fscanf(f2,"%s",sname);
d=0;
k=k-1;
printf("k=%d",k);
}
fprintf(f3,"%s\t",sname);
}
if(d==1)
{
for(i=0;i<10;i++)
{
fscanf(f2,"%s",sname);
fprintf(f3,"%s\t",sname);
}
}
fclose(f2);
fclose(f3);
f3=fopen("temp1","r");
f2=fopen("student","w");
e=k*11;
for(i=0;i<e;i++)
{
q++;
if((q%12)==0)
fprintf(f2,"\n");
fscanf(f3,"%s",sname);
fprintf(f2,"%s\t",sname);
}
fclose(f2);
fclose(f3);
break;
case 4: r=1;
f4=fopen("counter","w");
fprintf(f4,"%d",k);
fclose(f4);
return 0;
}
if(r==1) break;
}
case 2: for(;;)
{
printf("\n\t1.Add department \t2.search department details\n\t3.delete department\t 4.Exit\n");
printf("\tenter ur choice\n");
scanf("%d",&ch1);
switch(ch1)
{
case 1: k1++;
// printf("k1=%d\n",k1);
f1=fopen("department","a+");
fprintf(f1,"\n");
printf("DCODE:\t");
scanf("%s",snum);
fprintf(f1,"%s\t",snum);
printf("OFFICE NO:\t");
scanf("%s",sname);
fprintf(f1,"%s\t",sname);
printf("OFFICE PH:\t");
scanf("%s",ssn);
fprintf(f1,"%s\t",ssn);
printf("COLLEGE:\t");
scanf("%s",ssn);
fprintf(f1,"%s\t",ssn);
fclose(f1);
break;
case 2:
//OPERATION ON DEPARTMENT ENTRIES
printf("enter the departmental code to be searched\n");
scanf("%s",d1);
f2=fopen("department","r");
for(i=0;i<77;i++)
{
fscanf(f2,"%s",sname);
if(strcmp(d1,sname)==0)
{
printf("%s\t",sname);
for(j=0;j<3;j++)
{
fscanf(f2,"%s",ssn);
printf("%s\t",ssn);
}
break;
}
}
fclose(f2);
break;
case 4:r1=1;
f4=fopen("counter","w");
fprintf(f4,"%d",k1);
fclose(f4);
break;
}
if(r1==1) break;
}
case 3: for(;;)
{
//OPERATIONS ON COURSE ENTRIES
printf("\n\t1.Add course \t2.search course details \n\t3.delete course \t4.Exit\n");
printf("\tenter ur choice\n");
scanf("%d",&ch2);
switch(ch2)
{
case 1: k2++;
// printf("k2=%d\n",k2);
f1=fopen("course","a+");
fprintf(f1,"\n");
printf("COURSE NUM:\t");
scanf("%s",snum);
fprintf(f1,"%s\t",snum);
printf("COURSE NAME:\t");
scanf("%s",sname);
fprintf(f1,"%s\t",sname);
printf("NO OF SEM HRS:\t");
scanf("%s",ssn);
fprintf(f1,"%s\t",ssn);
printf("OFFERING DEPT:\t");
scanf("%s",ssn);
fprintf(f1,"%s\t",ssn);
fclose(f1);
break;
case 2: printf("enter the course code to be searched\n");
scanf("%s",d1);
f2=fopen("course","r");
for(i=0;i<77;i++)
{
fscanf(f2,"%s",sname);
if(strcmp(d1,sname)==0)
{
printf("%s\t",sname);
for(j=0;j<3;j++)
{
fscanf(f2,"%s",ssn);
printf("%s\t",ssn);
}
break;
}
}
fclose(f2);
break;
case 4:r2=1;
f4=fopen("course","w");
fprintf(f4,"%d",k2);
fclose(f4);
return 0;
}
if(r2==1) break;
}
case 4:for(;;)
{
//OPERATIONS ON SECTION ENTRIES
printf("\n\t1.Add section \t2.search section details \n\t3.delete section \t4.Exit\n");
printf("\tenter ur choice\n");
scanf("%d",&ch3);
switch(ch3)
{
case 1: k3++;
// printf("k3=%d\n",k3);
f1=fopen("section","a+");
fprintf(f1,"\n");
printf("SECTION NUM:\t");
scanf("%s",snum);
fprintf(f1,"%s\t",snum);
printf("INSTRUCTOR NAME:\t");
scanf("%s",sname);
fprintf(f1,"%s\t",sname);
printf("SEM:\t");
scanf("%s",ssn);
fprintf(f1,"%s\t",ssn);
printf("YEAR:\t");
scanf("%s",ssn);
fprintf(f1,"%s\t",ssn);
printf("COURSE:\t");
scanf("%s",ssn);
fprintf(f1,"%s\t",ssn);
fclose(f1);
break;
case 2: printf("enter the section code to be searched\n");
scanf("%s",d1);
f2=fopen("section","r");
for(i=0;i<77;i++)
{
fscanf(f2,"%s",sname);
if(strcmp(d1,sname)==0)
{
printf("%s\t",sname);
for(j=0;j<4;j++)
{
fscanf(f2,"%s",ssn);
printf("%s\t",ssn);
}
break;
}
}
fclose(f2);
break;
case 4:r3=1;
f4=fopen("section","w");
fprintf(f4,"%d",k3);
fclose(f4);
return 0;
}
if(r3==1) break;
}
case 5:for(;;)
{
printf("\n\t1.Add grade report \t2.search grade details \n\t3.delete grade report \t4.Exit\n");
printf("\tenter ur choice\n");
scanf("%d",&ch4);
switch(ch4)
{
case 1: k4++;
// printf("k4=%d\n",k4);
f1=fopen("grade","a+");
fprintf(f1,"\n");
printf("SNUM:\t");
scanf("%s",snum);
fprintf(f1,"%s\t",snum);
printf("SECTON NUM:\t");
scanf("%s",sname);
fprintf(f1,"%s\t",sname);
printf("LETTER GRADE:\t");
scanf("%s",ssn);
fprintf(f1,"%s\t",ssn);
printf("NUMERIC GRADE:\t");
scanf("%s",ssn);
fprintf(f1,"%s\t",ssn);
fclose(f1);
break;
case 2: printf("enter the student num whose grade is to be searched\n");
scanf("%s",d1);
f2=fopen("grade","r");
for(i=0;i<77;i++)
{
fscanf(f2,"%s",sname);
if(strcmp(d1,sname)==0)
{
printf("%s\t",sname);
for(j=0;j<3;j++)
{
fscanf(f2,"%s",ssn);
printf("%s\t",ssn);
}
break;
}
}
fclose(f2);
break;
case 4:r4=1;
f4=fopen("grade","w");
fprintf(f4,"%d",k4);
fclose(f4);
return 0;
}
if(r4==1) break;
}
case 6: p=1;
break;
}
if(p==1) break;
}
}
Use full for CSE 6th sem student..
ReplyDelete