Expand|Select|Wrap|Line Numbers
- #include <stdio.h>
- #include <string.h>
- #include <conio.h>
- #include <ctype.h>
- #define MAX 30
- void getData (FILE*,int[],char[][20],int[],int[],float[],float[],int[],int*);
- void computeTotal(int[],int[],float[],float[],int [],int,float[],float[]);
- int maxScore(float[],int);
- int minScore(float[],int);
- float meanScore(float[],int);
- void showResult(FILE *,int [],char[][20],int[],int[],float[],int[],int,int,float,int,float[]);
- void printLine(FILE *);
- void menu();
- int seqSearch (int [],int,int);
- void bubbleSort(int[],char[][20],float[],int);
- void showSortedlist (FILE *,int[],char[][20],float[],int);
- void main ()
- {
- int cnt,id[MAX],mid[MAX],final[MAX],lab[MAX],imax,imin,a,pos,key;
- char name[MAX][20];
- float test1[MAX],test2[MAX],test_avg[MAX],total[MAX],avg;
- FILE *inf,*outf,*outf2;
- inf = fopen ("SCORE.TXT","r");/*open file*/
- outf = fopen("REPORT.out","w");
- outf2 = fopen("OUTPUT.OUT","w");
- clrscr();
- if (inf == NULL)
- {
- printf("File not found");/*check file for exit*/
- exit(1);
- }
- do{
- menu();
- printf(" Enter No. Menu.........::");
- scanf("%d",&a);
- if (a == 1)
- {
- getData(inf,id,name,mid,final,test1,test2,lab,&cnt);
- }
- else if (a == 2)
- {
- computeTotal(mid,final,test1,test2,lab,cnt,total,test_avg);
- avg = meanScore(total,cnt);
- }
- else if (a == 3)
- {
- imax = maxScore(total,cnt);
- imin = minScore(total,cnt);
- }
- else if (a == 4)
- {
- showResult(outf,id,name,mid,final,test_avg,lab,imax,imin,avg,cnt,total);
- }
- else if (a == 5)
- {
- printf("\n Searching Student Data\n");
- printf("-----------------------------\n");
- printf("Please Enter Student ID >> ");
- scanf("%d",&key);
- pos = seqSearch (id,key,cnt);
- if (pos ==-1)
- printf(" Not found %d \n",key);
- else
- printf("%d &s &2.f\n",id[pos],name[pos],total[pos]);
- }
- else if (a == 6)
- {
- bubbleSort(id,name,total,cnt);
- showSortedlist(outf2,id,name,total,cnt);
- }
- } while (a != 0);
- fclose(inf);
- fclose(outf);
- getch();
- }
- void getData (FILE*inf,int id[],char name[][20],int mid[],int final[],float test1[],float test2[],int lab[],int*cnt)
- {
- *cnt = 0;
- while(!feof(inf))
- { /* read data from file*/
- fscanf(inf,"%d%s%d%d%f%f%d",&id[*cnt],&name[*cnt],&mid[*cnt],&final[*cnt],&test1[*cnt],&test2[*cnt],&lab[*cnt]);
- (*cnt)++;
- }
- }
- void computeTotal(int mid[],int final[],float test1[],float test2[],int lab[],int cnt,float total[],float test_avg[])
- {
- int i;
- for (i=0;i<cnt;i++)
- {
- test_avg[i] = (test1[i]+test2[i])/2;
- total[i] = mid[i]+final[i]+test_avg[i]+lab[i];
- }
- }
- int maxScore (float total[],int cnt)
- {
- int i,max=0,imax=0;
- for(i=0;i<cnt;i++)
- {
- if(total[i]>max)
- {
- max=total[i];
- imax = i;
- }
- }
- return imax;
- }
- int minScore (float total[],int cnt)
- {
- int i,min =100,imin=0;
- for(i=0;i<cnt;i++)
- {
- if(total[i]<min)
- {
- min=total[i];
- imin = i;
- }
- }
- return imin;
- }
- float meanScore(float total[],int cnt)
- {
- int i;
- float mean,avg;
- for (i=0;i<cnt;i++ )
- {
- mean+= total[i];
- }
- avg = mean/cnt;
- return avg;
- }
- void showResult(FILE *outf,int id[],char name[][20],int mid[],int final[],float test_avg[],int lab[],int imax,int imin,float avg,int cnt,float total[])
- {
- int i;
- fprintf(outf,"\t\tIT200 Score Report\n");
- printLine(outf);
- for(i=0;i<cnt;i++)
- fprintf(outf,"%d %s \t\t%d \t%d \t%.2f \t%d \t%.2f\n",id[i],name[i],mid[i],final[i],test_avg[i],lab[i],total[i]);
- printLine(outf);
- fprintf(outf,"Average Score = %.2f\n",avg);
- fprintf(outf,"Max Score :: %d %s \tScore = %.2f\n" ,id[imax],name[imax],total[imax]);
- fprintf(outf,"Min Score :: %d %s \tScore = %.2f\n",id[imin],name[imin],total[imin]);
- printLine(outf);
- }
- void printLine(FILE *outf)
- {
- fprintf(outf,"---------------------------------------------------------------\n");
- }
- void menu ()
- {
- printf("\n Grading program\n");
- printf("1> Get Data \n");
- printf("2> Calculate Total Score");
- printf("3> Calculate Max Min Score");
- printf("4> Display Score Repot");
- printf("5> Search Student Data");
- printf("6> Display Student Data Sort by Total Score");
- printf("0> Exit");
- }
- int seqSearch (int id[],int key,int cnt)
- {
- int i;
- printf("...........Searching..............\n");
- for (i=0;i<cnt;i++)
- {
- if (id[i] == key)
- return i;
- }
- return -1;
- void bubbleSort(int id[],char name [][20],float total [],int cnt)/* Error Declaration is not allowed here*/
- {/*Declaration syntax erroe*/
- int i,j,tempid;
- char tempname[MAX];
- float temptotal;
- for (i=0;i<cnt;i++)
- {
- for (j=cnt-1;j>=i j--)
- {
- if (total[j] < total[j-1])
- {
- temptotal = total[j-1];
- total[j-1] = total[j];
- total[j] = temptotal;
- strcpy(tempname,name[j-1]);
- strcpy(name[j-1],name[j]);
- strcpy(name[j],tempname);
- tempid = id[j-1];
- id[j-1] = id[j];
- id[j] = tempid;
- }
- }
- }
- }
- void showSortedlist (FILE *outf2,int id[],char name[][20],float total[],int cnt)
- {
- int i;
- fprintf(outf2," IT200 Score Peport Sort\n");
- printLine(outf2);
- fprintf(outf2," Student ID Name Total\n");
- for (i=0;i<cnt;i++)
- {
- fprintf(outf2," %d &s %.2f\n",id[i],name[i],total[i]);
- }
- printLine(outf2);
- } /*Errer Declaration missing ; , Compound statement missing } */
Thank you for answers.