Last active
June 5, 2019 01:57
-
-
Save zzzz465/636950fbde92fb7d797013fa6efc620e to your computer and use it in GitHub Desktop.
C조별과제입니다
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
//함수원형들 | |
void printData(); | |
void mainLoop(); | |
void FindStudent(int); | |
void showAllData(); | |
void printMetaData(); | |
void readData(int); | |
void MaxEval(int, int*); | |
void MinEval(int, int*); | |
int GradeEval(int); | |
typedef struct _Student | |
{ | |
unsigned int Code; | |
int KoScore; | |
int EnScore; | |
int MathScore; | |
int Sum; | |
float Average; | |
char Grade; | |
} Student; | |
Student Students[100]; | |
int KoScoreMin = 100, EnScoreMin = 100, MathScoreMin = 100, KoScoreMax = 0, EnScoreMax = 0, MathScoreMax = 0, KoScoreSum = 0, EnScoreSum = 0, MathScoreSum = 0; | |
int length; | |
int main() | |
{ | |
printf("학생의 수를 입력해주세요 : "); | |
scanf("%d", &length); | |
printf("\n"); | |
readData(length); // 데이터를 받아오는 함수 | |
mainLoop(); // 입력을 받고 처리하는 함수 | |
return 0; | |
} | |
void mainLoop() | |
{ | |
while (1) | |
{ | |
printf("메뉴 번호를 입력해주세요 : "); | |
int menu, input; | |
scanf("%d", &menu); | |
printf("\n"); | |
switch (menu) // 입력된 menu의 숫자에 따라 case | |
{ | |
case 0: | |
return; | |
case 1: | |
showAllData(); | |
break; | |
case 2: | |
printf("학번을 입력해주세요 : "); | |
scanf(" %d", &input); | |
FindStudent(input); | |
printf("\n"); | |
break; | |
default: | |
printf("error"); | |
} | |
} | |
return; | |
} | |
void FindStudent(int code) // 배열과, 학번을 받아 해당하는 학생을 출력 없으면 에러 출력 | |
{ | |
for (int count = 0; count < length; count++) | |
{ | |
if (Students[count].Code == code) | |
{ | |
printData(Students[count]); | |
return; | |
} | |
} | |
printf("Not Valid\n"); | |
return; | |
} | |
void printData(Student StructData) // 1차원 배열을 받아 학생의 정보를 출력해줌 | |
{ | |
printf("%d %d %d %d %d %.1f %c\n", StructData.Code, StructData.KoScore, StructData.EnScore, StructData.MathScore, StructData.Sum, StructData.Average, (char)StructData.Grade); | |
return; | |
} | |
void printMetaData() // 전체 데이터에 대한 정보를 출력해줌 | |
{ | |
printf("국/영/수 최소값\n%d %d %d\n", KoScoreMin, EnScoreMin, MathScoreMin); | |
printf("국/영/수 최대값\n%d %d %d\n", KoScoreMax, EnScoreMax, MathScoreMax); | |
printf("국/영/수 평균값\n%d %d %d\n", KoScoreSum / length, EnScoreSum / length, MathScoreSum / length); | |
return; | |
} | |
void showAllData() // 모든 학생들의 정보를 출력함 | |
{ | |
for (int count = 0; count < length; count++) | |
{ | |
printData(Students[count]); | |
} | |
printMetaData(); | |
return; | |
} | |
void readData(int n) // 데이터를 읽어오는 함수 | |
{ | |
for (int count = 0; count < n; count++) | |
{ | |
int Code, KoScore, EnScore, MathScore; | |
scanf("%d %d %d %d", &Code, &KoScore, &EnScore, &MathScore); // 데이터를 받아옴 | |
Students[count].Code = Code; | |
Students[count].KoScore = KoScore; | |
Students[count].EnScore = EnScore; | |
Students[count].MathScore = MathScore; | |
Students[count].Sum = (KoScore + EnScore + MathScore); | |
Students[count].Average = ((float)Students[count].Sum / 3); | |
Students[count].Grade = (char)GradeEval(Students[count].Average); //데이터 입력 | |
//국어, 영어, 수학에 대한 최대값 판별 후 값 대입 | |
MaxEval(KoScore, &KoScoreMax); | |
MaxEval(EnScore, &EnScoreMax); | |
MaxEval(MathScore, &MathScoreMax); | |
//국어, 영어, 수학에 대한 최솟값 판별 후 값 대입 | |
MinEval(KoScore, &KoScoreMin); | |
MinEval(EnScore, &EnScoreMin); | |
MinEval(MathScore, &MathScoreMin); | |
//평균을 구하기 위하여 합계 저장 | |
KoScoreSum += KoScore; | |
MathScoreSum += MathScore; | |
EnScoreSum += EnScore; | |
} | |
} | |
void MaxEval(int value, int* p) // value와 *p를 비교하여, 조건에 따라 *p값을 변화 | |
{ | |
if(*p < value) | |
*p = value; | |
return; | |
} | |
void MinEval(int value, int *p) // value와 *p를 비교하여, 조건에 따라 *p값을 변화 | |
{ | |
if(*p > value) | |
*p = value; | |
return; | |
} | |
int GradeEval(int Score) // Score를 받아, 등급에 해당하는 ASCII 값을 int형으로 반환 | |
{ | |
if (Score >= 90) | |
return 'A'; | |
else if (Score >= 80) | |
return 'B'; | |
else if (Score >= 70) | |
return 'C'; | |
else if (Score >= 60) | |
return 'D'; | |
else | |
return 'F'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment