2dix-The Student Choice
Log in Register now

Source code for Examination management system in c language

Source code for Examination management system in c language

#include<stdio.h>

#include<conio.h>

void main()

{

FILE *fp, *ft;

char another, choice;

 struct Exam

{       int r_no;

       char clas[20];

       char name[40];

       char add[40];

       char f_name[40];

       float math;

       float phy;

       float che;

       float comp;

       float avg;

       float avg1;

};

struct Exam f;

long int amount,flag;

long int recsize;

float avg;

int r_no;

char clas[20];

fp=fopen("EXAM.DAT","rb+");

if(fp==NULL)

{

       fp=fopen("EXAM.DAT","wb+");

       if(fp==NULL)

       {

              puts("Cannot open file");

              exit(1);

       }

}

 recsize = sizeof(f);

while(1)

{

       clrscr();

       gotoxy(30,10);

       printf("1. Student detail");

       gotoxy(30,12);

       printf("2. Display Record");

       gotoxy(30,14);

       printf("3. Topper");

       gotoxy(30,16);

       printf("4. Failer");

       gotoxy(30,18);

       printf("5. Delete Record");

       gotoxy(30,20);

       printf("0.Exit");

       gotoxy(30,22);

       printf("Your choice");

       fflush(stdin);

       choice = getche();

       switch(choice)

       {

              case '1':

              fseek(fp,0,SEEK_END);

              another = 'Y';

              while((another == 'Y') || (another == 'y'))

              {

                     printf("\nEnter Roll_no");

                     scanf("%d", &f.r_no);

                     printf("\nEnter Name");

                     scanf(" %s",f.name);

                     printf("\nEnter class");

                     scanf("%s",f.clas);

                     printf("\nEnter Address");

                     scanf("%s",f.add);

                     printf("\nEnter Father name");

                     scanf("%s",f.f_name);

                     printf("\nEnter Maths marks ");

                     scanf("%f", &f.math);

                     printf("\nEnter phy marks");

                     scanf("%f",&f.phy);

                     printf("\nEnter che marks");

                     scanf("%f",&f.che);

                     printf("enter computer marks");

                     scanf("%f",&f.comp);

                     f.avg=f.math+f.comp+f.phy+f.che;

                     f.avg1=f.avg/4;

                     fwrite(&f, recsize, 1, fp);

                     printf("\nCreate another Student Record(Y/N)");

                     fflush(stdin);

                     another = getche();

              }

              break;

              case '2':

              clrscr();

              rewind(fp);

              printf("R no   name  class  Address  Father'Nm  maths    phy    che      comp   Avg");

              while(fread(&f, recsize, 1, fp) == 1)

                  printf("\n%d\t%s\t%s\t%s\t%s\t%2.2f\t%2.2f\t%2.2f\t%2.2f\t%2.2f", f.r_no,f.name,f.clas, f.add, f.f_name, f.math,f.phy,f.che,f.comp,f.avg1);

              getch();

              break;

 

              case '3':

              another='Y';

              avg=0.0;

              while(another=='Y')

              {

              printf("\nenter the class");

              scanf("%s",clas);

                     rewind(fp);

                     while(fread(&f, recsize, 1, fp)==1)

                           if((f.avg>=avg)&&(strcmp(f.clas,clas)==0))

                           {

                                  avg = f.avg;

 

                           }

                     printf("Student topped information is below");

                     printf("Name = %s", f.name);

                     fflush(stdin);

                     another=getche();

                  }

                  break;

              case '4':

              another='Y';

              avg=33.3;

              while(another=='Y')

              {

                     printf("\nEnter class to check the score");

                     scanf("%s",clas);

                     rewind(fp);

                     //flag=0;

                     while(fread(&f, recsize, 1, fp)==1)

                     {

                           //flag=1;

                           //printf("\n%f",f.avg1);

 

                           if((strcmp(f.clas,clas)==0)&&(f.avg1<=avg))

                           {

                                  printf("\n failed",f.r_no);

                                  printf("\n Students name is%s",f.name);

                                  printf("\n Father's name is%s",f.f_name);

                            }

                                  //getch();

 

 

                     }

                     //if(flag==0)

                     //{

                       //   printf("Sorry !! Invalid roll number");

                       //   getch();

                     //}

 

                     fflush(stdin);

                     another=getche();

              }

              break;

 

              case '5':

              another='Y';

              while(another=='Y')

              {

                     printf("\nEnter roll number to delete");

                     scanf("%d",&r_no);

                     ft = fopen("TEMP.DAT","wb");

                     rewind(fp);

                     while(fread(&f, recsize, 1, fp) == 1)

                     {

                           if(f.r_no!=r_no)

                                  fwrite(&f, recsize, 1, ft);

                     }

                     fclose(fp);

                     fclose(ft);

                     remove("EXAM.DAT");

                     rename("TEMP.DAT", "EXAM.DAT");

                     fp=fopen("EXAM.DAT", "rb+");

                     printf("Delete another record(Y/N)");

                     fflush(stdin);

                     another = getche();

              }

              break;

 

              case '0':

              fclose(fp);

              exit();

       }

}

}

comments (0)

avatar