STUDY/Assignment

객체 지향 과제 rep6

da1seun9 2020. 5. 18. 00:00
#include <iostream>
#include <iomanip>
using namespace std;
#define ROW		3  
#define COL		6

void main()
{
	char* col[] = { "번호", "국어", "영어", "수학", "사회", "평 균" };
	int		a[ROW][COL] = {0, };
	int		r, c,i;
	float	b[ROW] = { 0 };
	float avg[5] = { 0 };

	for (r = 0; r<ROW; r++) {
		a[r][0] = r + 1;
		cout << "\n>> " << a[r][0] << " 번째 학생의 점수를 입력하세요\n";
		for (c = 1; c <= 4; c++) {
			cout << c << "번째 과목 => ";
			cin >> a[r][c];
		}
	}

	for (r = 0; r<ROW; r++) {
		for (c = 1; c <= 4; c++) {
			a[r][5] += a[r][c];
		}
		b[r] = (float)a[r][5] / 4;
	}

	for (c = 1; c <= 5; c++) {

		for (r = 0; r < ROW; r++) {
			if (c == 5) avg[4] += b[r]; //평균의 평균
			else avg[c - 1] += a[r][c]; // 과목 평균
		}

		avg[c-1] = (float)avg[c-1] / 3;


	}


	cout << setw(48) << "학 생 별   성 적 표" << endl;
	cout << setw(48) << "==================="<<endl<<endl;

	for (i = 0; i < sizeof(col) / sizeof(char*); i++) {
		if (i == 0) {
			cout << setw(15) << col[i];
		}
		else cout << setw(10) << col[i];
	}
	cout << endl;

	cout << setw(65) << "------------------------------------------------------" << endl;

	for (r = 0; r<ROW; r++) {
		for (c = 0; c <= 4; c++) {

			if (c == 0) cout << setw(14) << a[r][c];

			else cout << setw(10) << a[r][c];
		}
		cout << setw(10) << b[r] << endl;
	}
	cout << setw(65) << "------------------------------------------------------" << endl;

	cout << setw(16) << "평균";
	
	for (c = 0; c <= 4; c++) {
		if (c == 0) cout << setw(8) << avg[c];
		else cout << setw(10) << avg[c];
	}
	cout << endl << endl;
}

교수님이 짜신 걸 베이스로 하라 그래서 밤새면서 했다.. 하하

'STUDY > Assignment' 카테고리의 다른 글

객체 지향 과제 rep 8-1  (0) 2020.06.05
객체 지향 과제 rep7  (0) 2020.05.30
보안 자료 구조 과제  (0) 2020.05.04
객체 지향 과제 rep4  (1) 2020.04.25
객체지향 프로그래밍 중간고사 실습대비 연습문제  (0) 2020.04.24