#include<stdio.h>
#include<string.h>
int input_int();
int total(int a, int b, int c);
float avg(int total);
void insert();
void select();
void select_all();
void modify();
void delete();
int arr[3][3][3];
int main()
{
int yn;
do {
int choice;
printf("1.등록 2.조회 3.전체 조회 4.수정 5.삭제");
choice = input_int();
switch (choice)
{
case 1:
insert();
break;
case 2:
select();
break;
case 3:
select_all();
break;
case 4:
modify();
break;
case 5:
delete();
break;
default:
break;
}
printf("계속하시겠습니까?\n");
printf("99.끝내기 나머지.계속\n");
yn = input_int();
} while (yn != 99);
}
void insert()
{
printf("반 : ");
int classNum = input_int();
printf("학생 : ");
int student = input_int();
for (int i = 0; i < 3; i++) {
if (arr[classNum][student][i] != 0) {
printf("해당 학생이 이미 존재합니다.\n");
return;
}
printf("점수를 입력해주세요 :");
arr[classNum][student][i] = input_int();
}
}
void select()
{
printf("반 : ");
int classNum = input_int();
printf("학생 : ");
int student = input_int();
int kor = arr[classNum][student][0];
int eng = arr[classNum][student][1];
int math = arr[classNum][student][2];
int score_total = total(kor, eng, math);
float average = avg(score_total);
printf("%d반 %d번 학생 -> ", classNum, student);
printf("국어:%d 영어:%d 수학:%d 총점:%d 평균:%f\n", kor, eng, math, score_total, average);
}
void select_all()
{
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
int kor = arr[i][j][0];
int eng = arr[i][j][1];
int math = arr[i][j][2];
int score_total = total(kor, eng, math);
float average = avg(score_total);
printf("%d반 %d번 학생 -> ",i, j);
printf("국어:%d 영어:%d 수학:%d 총점:%d 평균:%f\n", kor, eng, math, score_total, average);
}
}
}
void modify()
{
printf("반 : ");
int classNum = input_int();
printf("학생 : ");
int student = input_int();
printf("국어 점수를 입력해주세요 \n");
arr[classNum][student][0] = input_int();
printf("영어 점수를 입력해주세요 \n");
arr[classNum][student][1] = input_int();
printf("수학 점수를 입력해주세요 \n");
arr[classNum][student][2] = input_int();
}
void delete()
{
printf("반 : ");
int classNum = input_int();
printf("학생 : ");
int student = input_int();
arr[classNum][student][0] = 0;
arr[classNum][student][1] = 0;
arr[classNum][student][2] = 0;
}
int input_int()
{
int i;
scanf_s("%d", &i);
return i;
}
int total(int a, int b, int c)
{
return (a + b + c);
}
float avg(int total)
{
return (total / 3.f);
}
반응형
'C언어 > C언어 연습' 카테고리의 다른 글
(C언어) 간단한 계산기 (0) | 2020.11.23 |
---|