STUDY/Assignment
객체지향 프로그래밍 중간고사 실습대비 연습문제
da1seun9
2020. 4. 24. 19:04
#include<iostream>
#include<iomanip>
using namespace std;
#define STUDENT 5
const char *head[] = { "학생 신체 현황 자료(입력순)","학생 신체 현황 자료(성명순)" }, *underline = "===========================";
const char *name[] = { "김철수","이영희","홍길동","한수만","박문수" };
int birth[] = {1990,1989,1991,1988,1990};
double height[] = { 172.5,187.2,174.6,182.5,170.3 };
double weight[] = { 67.2,78.5,75.1,80.6,68.6 };
int main() {
int i,j;
int flag, id, index[] = { 0,1,2,3,4 };
char n[10];
cout << "문제1. 자료 종합 출력(입력순)\n";
cout << setw(74) << head[0]<<endl;
cout << setw(74) << underline <<endl << endl << setw(25);
cout << "성 명";
cout << setw(25) << "출생연도(년)";
cout << setw(25) << "신장(cm)";
cout << setw(25) << "체중(kg)";
cout << setw(121) << "------------------------------------------------------------------------------------"<<endl;
for (i = 0; i <= 4; i++) {
cout << setw(25);
cout << name[i] << setw(20);
cout << birth[i] << setw(28);
cout << height[i] << setw(25);
cout << weight[i] << endl;
}
cout << "\n\n문제 2. 자료 종합 출력(성명순)\n";
cout << setw(74) << head[0] << endl;
cout << setw(74) << underline << endl << endl << setw(25);
cout << "성 명";
cout << setw(25) << "출생연도(년)";
cout << setw(25) << "신장(cm)";
cout << setw(25) << "체중(kg)";
cout << setw(121) << "------------------------------------------------------------------------------------" << endl;
for (i = 0; i < 4; i++)
{
for (j = i + 1; j < 5; j++)
{
if (strcmp(name[i], name[j]) > 0)
{
swap(name[i], name[j]);
swap(birth[i], birth[j]);
swap(height[i], height[j]);
swap(weight[i], weight[j]);
}
}
}
for (i = 0; i <= 4; i++) {
cout << setw(25);
cout << name[i] << setw(20);
cout << birth[i]<< setw(28);
cout << height[i] << setw(25);
cout << weight[i] << endl;
}
cout << endl << endl;
return 0;
}
더 간단하게 할 수 있을 듯 한데.... 더 공부해봐야겠다