#In the main function, input a set of (10) C language scores into the array score [], and output as shown in the figure The main menu shown in the figure is called according to different selections The corresponding functions are realized by writing functions: (1) Output average score; (2) Rank and output the scores; (3) Output scores lower than the average, and the number; (4) Output pass rate (5) Enter a score value to find, output found or not found. (6) After sorting, enter a score value, add it to score [] and keep the order.
#include<stdio.h> #include <stdlib.h> int Menu(); void HandleMenu(); void inputScore(); void PrintAveScore(float sco[]); void SortScore(float sco[]); void PrintScore(float sco[]); void PrintBadScoreAndCount(float sco[]); void PassRate(float sco[]); void FindScore(float sco[]); void AddScore(float sco[]); float score[20]; int count=10; //////main function int main() { inputScore(); while(1){ HandleMenu(); } return 0; } /// / / / menu int Menu(){ int sel; printf("----------------------------\n"); printf("1.Output average\n" ); printf("2.Ranking results\n" ); printf("3.Output scores and numbers lower than average\n"); printf("4.Output pass rate\n" ); printf("5.Search results\n" ); printf("6.Add results\n" ); printf("0.End procedure\n" ); printf("----------------------------\n"); scanf("%d",&sel); return sel; } ///////Control menu void HandleMenu() { int select; select=Menu(); switch(select){ case 1: PrintAveScore(score); break; case 2: SortScore(score); break; case 3: PrintBadScoreAndCount(score); break; case 4: PassRate(score); break; case 5: FindScore(score); break; case 6: AddScore(score); break; default:exit(0); } } //////Enter grades void inputScore() { int i; for(i=0;i<10;i++){ printf("Please input number 1.%d achievement:",i+1); scanf("%f",&score[i]); getchar(); } } /////Output average void PrintAveScore(float sco[]) { int i; float ave=0; for(i=0;i<10;i++){ ave+=sco[i]; }ave/=10; printf("%.0f",ave); } /// / / sort void SortScore(float sco[]) { int i,j,t; for(i=0;i<9;i++){ for(j=0;j<9-i;j++){ if(sco[j]>sco[j+1]){ t=sco[j]; sco[j]=sco[j+1]; sco[j+1]=t; }}}PrintScore(sco); } //////Print grades void PrintScore(float sco[]) { int i; for(i=0;i<count;i++){ printf("%.2f\t",sco[i]); }printf("\n"); } /////Output below average scores and number void PrintBadScoreAndCount(float sco[]) { float ave=0; int i; int BadScoreCount=0; for(i=0;i<10;i++){ ave+=sco[i]; } ave/=count; printf("Below average%f The results are",ave); for(i=0;i<10;i++){ if(sco[i]<ave){ printf("%.0f\t",sco[i]); BadScoreCount++; } }printf("%d individual\n",BadScoreCount); } ///////Output pass rate void PassRate(float sco[]) { int i; float psrate=0; for(i=0;i<10;i++){ if(sco[i]>=60) psrate++; }psrate/=10; printf("Passing rate is%.2f\n",psrate); }////////Find grades////// void FindScore(float sco[]) { float findsco; int i; printf("Please enter the grade you want to find\n"); scanf("%f",&findsco); for(i=0;i<count;i++){ if(sco[i]==findsco){ printf("Eureka,It is in the first place.%d Location!\n",i); break; } } if(i>=count) printf("Can't find\n"); } ///Add grades after sorting//// void AddScore(float sco[]){ float s; int i,pos; printf("Please enter grades to add\n"); scanf("%f",&s); SortScore(score); for(i=0;i<count;i++){ if(s>sco[i]){ pos=i; break; } } for(i=count-1;i>=pos;i--){ sco[i+1]=sco[i]; } sco[pos]=s; count++; PrintScore(sco); }