티스토리 뷰
애플리케이션 구현
#프로그램 설계
1. 프로그램 기능 정의
프로그램명 : 성적처리 프로그램
주요기능 : 학생들의 성적을 입력받고 평균을 구하여 성적순으로 출력하는 프로그램
자료구조 : 이름, 국어, 영어, 수학, 평균
요구사항
- 학생이름은 10글자이내
- 최대 20명의 학생 성적 처리되지
- 평균값 자동 계산
- 메뉴 방식 UI
2. 자료 구조 정의주요기능 : 학생들의 성적을 입력받고 평균을 구하여 성적순으로 출력하는 프로그램
자료구조 : 이름, 국어, 영어, 수학, 평균
요구사항
- 학생이름은 10글자이내
- 최대 20명의 학생 성적 처리되지
- 평균값 자동 계산
- 메뉴 방식 UI
자료구조 : 이름, 국어, 영어, 수학, 평균
struct sungjuk {
char name[10];
int kor, eng, mat;
double avg;
}
3. 메뉴 구조struct sungjuk {
char name[10];
int kor, eng, mat;
double avg;
}
#코드분석
1. 헤드 파일
2. 메인함수
3. 입출력함수
#include
#difine ST_NUM 20
#define NAME_LENGTH 10
struct sungjuk {
char name[NAME_LEGTH];
int kor, eng, mat;
double avg;
}SUNGJUK
int main() {
int sel, totalSCnt=0;
SUNGJUK student[ST_NUM];
while(1) {
put("\n원하는 메뉴를 선택하세요");
puts("1, 성적입력");
puts("2, 성적순출력");
puts("0, 종료");
scanf("%d, &sel");
fflush(stdin);
switch(sel){
case 1: totalScnt = inScore(student, totalSCnt); break;
case 2: outScore(student, totalSCnt); break;
case 0: return 0;
default : puts("0-3 사이의 메뉴 번호를 선택하세요");
}
}
}
#include
int inScore(SUNGJUK *st, int cnt){
char op;
do {
fflush(stdin);
printf("이름 :");
gets(st[cnt], name);
printf("국어 :");
scanf("%d, &st[cnt].kor");
printf("영어 :");
scanf("%d, &st[cnt].eng");
printf("수학 :");
scanf("%d, &st[cnt].mat");
puts("계속 입력하시겟습니까?");
fflush(stdin);
op = getc(stdin);
st[cnt].avg = (double)(st[cnt].kor + st[cnt].eng +st[cnt].mat )/3.0
cnt++;
}while(op! = 'n');
return cnt;
}
void sortScore(SUNGUK*st, int cnt) {
SUNGJUK temp;
int i, j;
for(i = 0; i < cnt-1; i++) {
for(j=0; j < (cnt-i)-1; j++) {
if(st[j].avg < st[j+1].avg) {
temp=st[j];
st[j]=st[j+1];
st[j+1]=temp;
}
}
}
}
void outScore(SUNGUK*st, int cnt) {
int i; sortScore(st, cnt);
for(i=0; i < cnt; i++) {
printf("%2d %10s %5d %5d %5d %3.1f\n", i+1, st[i].name,st[i].kor,st[i].eng,st[i].mat,st[i].avg)
}
}
'JAVA기반스마트웹개발2021 > 프로그래밍언어 활용' 카테고리의 다른 글
디버깅 (0) | 2021.08.07 |
---|---|
프로그래밍 언어별 특성 (0) | 2021.08.07 |
전처리기 (0) | 2021.08.05 |
배열 포인터 처리 (0) | 2021.08.05 |
스토리지 클래스 (0) | 2021.08.05 |