본문 바로가기
Programming/C#

c - Students' score management program.

by NAMP 2009. 3. 21.

#include <stdio.h>

 

#define max 11    // set over 6 //

#define cls system("cls")

#define pause system("pause")

 

void inputData();

void ouputData();

void modifyData();

void deleteData();

void vaild();

void calcRank();

void insert();

 

 

int main(){

             static int scoreArr[max][max];

            

             int sel;

             int set;

            

             while(1){

                           for(set=0;set!=1;)

                           {                        

                                        cls;

                                        printf("== Score Management Program ==\n\n");

                                        printf("1. Input\n");

                                        printf("2. Output\n");

                                        printf("3. Modify\n");

                                        printf("4. Delete\n");

                                        printf("5. End\n\n");

                                        printf("> ");          scanf("%d",&sel);

                                        if (sel>0&&sel<6)

                                        {

                                                     set=1;

                                        }else{

                                                     printf("Wrong Number, input number 1 ~ 5\n");

                                                     pause;

                                        }

                           }

                           set=0;

                          

                           switch(sel){// select Menu function

                           case 1:  inputData(scoreArr);

                                        break;

                           case 2:  ouputData(scoreArr);

                                        break;

                           case 3: modifyData(scoreArr);

                                        break;

                           case 4: deleteData(scoreArr);

                                        break;

                           case 5: printf("Good bye\n");

                                        exit(0);

                                        break;

                           }

                          

             }

             return 0;

}

 

void insert(int scoreArr[max][max],int id){

             int score,set;

             printf("Input scores of Korean, English, Math orderly.\n");

             printf("Students ID number : %2d\n",id);

             scoreArr[id][0]=id;

            

             for(set=0;set!=1;){

                           printf("%12s :","Korean");fflush(stdin);scanf("%d",&score);

                           vaild(score,&set);

             }

             scoreArr[id][1]=score;

            

             for(set=0;set!=1;){

                           printf("%12s :","English");fflush(stdin);scanf("%d",&score);

                           vaild(score,&set);

             }

             scoreArr[id][2]=score;

            

             for(set=0;set!=1;){

                           printf("%12s :","Mathematics");fflush(stdin);scanf("%d",&score);

                           vaild(score,&set);

             }

             scoreArr[id][3]=score;

             scoreArr[id][max-1]=1;

             scoreArr[id][4]=scoreArr[id][1]+scoreArr[id][2]+scoreArr[id][3];

            

             calcRank(scoreArr);

}

 

void modifyData(int scoreArr[max][max]){

             int sel,set=0;

             int j;

             cls;

             printf("Which ID do you want to modify? :");

             fflush(stdin);       scanf("%d",&sel);

             for (j=1;j<max;j++)

             {

                           if (sel==scoreArr[j][0])

                           {

                                        insert(scoreArr,j);                                     

                                        set=1;

                                        break;

                           }

             }

             if (set==0)

             {

                           printf("It's invalid ID\n");

                           pause;

             }

            

             calcRank(scoreArr);

}

 

 

void deleteData(int scoreArr[max][max]){

             int sel,set=0;

            

             cls;

             printf("==Warning==\nData will be deleted\n");

             printf("Which ID do you want to delete? :");

             fflush(stdin);       scanf("%d",&sel);

                          

             scoreArr[sel][max-1]=0;

             printf("ID %d's data deleted\n",sel);

             calcRank(scoreArr);

             pause;

            

}

 

void calcRank(int scoreArr[max][max]){

             int i,j;

             int rank;

             for (i=1;i<max;i++)

             {

                           rank=1;

                           for (j=1;j<max;j++)

                           {

                                        if (scoreArr[i][4]<scoreArr[j][4]&&scoreArr[j][4]!=0&&scoreArr[j][max-1]!=0){

                                                     rank++;               

                                        }

                           }

                           scoreArr[i][5]=rank;                   

             }

}

 

void vaild(int score, int *ck){

             if (score>=0&&score<=100)

             {

                           *ck= 1;

             }else{

                           printf("Wrong number. Input again \n");

                           *ck=0;

             }

}

 

void ouputData(int scoreArr[max][max]){

             int i,j;

             char grade;

             cls;

             printf("%8s|%8s|%8s|%8s|%8s|%8s|%8s|%8s|\n","ID","Korean","English"\

                           ,"Math","Total","Average","Grade","Rank");

             for (i=1;i<max;i++)

             {

                           if (scoreArr[i][max-1]==1)

                           {

                                       

                                        for (j=0;j<5;j++)

                                        {

                                                     printf("%8d|",scoreArr[i][j]);

                                        }

                                        printf("%8.2f|",scoreArr[i][4]/(float)3);

                                       

                                        if (scoreArr[i][4]>=270)

                                        {

                                                     grade='A';

                                        }else if (scoreArr[i][4]>=240)

                                        {

                                                     grade='B';

                                        }else if (scoreArr[i][4]>=210)

                                        {

                                                     grade='C';

                                        }else if (scoreArr[i][4]>=180)

                                        {

                                                     grade='D';

                                        }else{

                                                     grade='F';

                                        }

                                        printf("%8c|",grade);

                                        printf("%8d|\n",scoreArr[i][5]);

                           }                        

             }           

             pause;

}

 

int idcheck(int scoreArr[max][max]){

             int i;

             for (i=1;i<max;i++)

             {

                           if (scoreArr[i][max-1]==0){

                                        return i;

                           }

             }

             return i;

}

 

void inputData(int scoreArr[max][max]){  

             int id;

             cls;

             id = idcheck(scoreArr);

             if (id!=max)

             {

                           insert(scoreArr,id);

                          

                          

             }else{

                           printf("Data Full. Delete data befor input data.\n");

                           pause;

             }

}

 

'Programming > C#' 카테고리의 다른 글

C - 지렁이 & 지뢰 찾기 게임 만들기  (0) 2009.03.29
C - 구구단 파일 입출력  (0) 2009.03.27
Maximum value of each Radix ... ?  (0) 2009.03.25
c - Baseball Game.  (0) 2009.03.20
C - Dice Game  (0) 2009.03.14

댓글