~cpp // Data.h #ifndef _DATA_H_ #define _DATA_H_ class Data{ private: char name[20]; int number; int kor; int eng; int math; int total; double ave; char grade[2]; public: Data(); Data(char na[], int nu, int k, int e, int m); int showNumber(int select); char * showName(); int showNum(); int showTotal(); double showAve(); }; #endif
~cpp //Judgement.h #ifndef _JUDGEMENT_H_ #define _JUDGEMENT_H_ #include "Data.h" #include "Order.h" class Judgement{ private: int tempData; int tempNumber; int stData[20]; int arrayNumber[20]; public: Judgement(); void sort(bool IsItSort , int select , Data d[]); void outputAll(bool IsItAll, Data d[]); void outputPart(bool IsItPart, Data d[] , int select); }; #endif
~cpp //Order.h #ifndef _ORDER_H_ #define _ORDER_H_ class Order{ private: int mainmenu; int submenu; public: Order(); void menu(); bool IsItAll(); bool IsItSort(); int subNumber(); }; #endif
~cpp // Data.cpp #include <iostream> using namespace std; #include "Data.h" Data::Data() { } Data::Data(char na[], int nu, int k, int e , int m) { strcpy(name, na); number = nu; kor = k; eng = e; math = m; total = k + e + m; ave = (double)total/3; for (int i = 0 ; i <= 19 ; i++ ) { if ( ave >= 95 && ave <=100) strcpy(grade,"a+"); else if ( ave >= 90 && ave < 95) strcpy(grade,"a"); else if ( ave >= 85 && ave < 90) strcpy(grade,"b+"); else if ( ave >= 80 && ave < 85) strcpy(grade,"b"); else if ( ave >= 75 && ave < 80) strcpy(grade,"c+"); else if ( ave >= 70 && ave < 75) strcpy(grade,"c"); else if ( ave >= 65 && ave < 70) strcpy(grade,"d+"); else if ( ave >= 60 && ave < 65) strcpy(grade,"d"); else if ( ave <= 59) strcpy(grade,"f"); } } int Data::showNumber(int select) { if (select == 1 ) return kor; else if (select == 2 ) return eng; else if (select == 3 ) return math; else return 0; } char * Data::showName() { return name; } int Data::showNum() { return number; } int Data::showTotal() { return total; } double Data::showAve() { return ave; }
~cpp //Judgement.cpp #include <iostream> using namespace std; #include "Judgement.h" #include "Data.h" #include "Order.h" Judgement::Judgement() { for (int i = 0 ; i <= 19 ; i++) arrayNumber[i] = i; } void Judgement::sort(bool IsItSort , int select , Data d[]) // 소트 부분 { if (IsItSort) { if ( select == 0 ) for (int k = 0 ; k <= 19 ; k++) // stData[k] = d[k].showTotal(); // else // 알맞는 데이터 값 카피 for (int k = 0 ; k <= 19 ; k++) // stData[k] = d[k].showNumber(select); // for (int i = 0 ; i <= 19 ; i++) { for (int j = i+1 ; j <= 19 ; j++) { if ( stData[i] < stData[j] ) { tempData = stData[i]; tempNumber = arrayNumber[i]; stData[i] = stData[j]; arrayNumber[i] = arrayNumber[j]; stData[j] = tempData; arrayNumber[j] = tempNumber; } } } // 소트 } } void Judgement::outputAll(bool IsItAll, Data d[]) { if (IsItAll) { cout << "이름\t번호\t\t국어\t영어\t수학\t총점\t평균" << endl; for (int i = 0 ; i <= 19 ; i++){ cout << d[arrayNumber[i]].showName() << "\t" << d[arrayNumber[i]].showNum() << "\t" << d[arrayNumber[i]].showNumber(1) << "\t" << d[arrayNumber[i]].showNumber(2) << "\t" << d[arrayNumber[i]].showNumber(3) << "\t" << d[arrayNumber[i]].showTotal() << "\t" << d[arrayNumber[i]].showAve() << endl; } cin.get(); cin.get(); } } void Judgement::outputPart(bool IsItPart, Data d[] , int select) { if (IsItPart) { cout << "이름\t번호\t"; if ( select == 1 ) cout << "\t국어" << endl; else if ( select == 2 ) cout << "\t영어" << endl; else if ( select == 3 ) cout << "\t수학" << endl; for (int i = 0 ; i <= 19 ; i++){ cout << d[arrayNumber[i]].showName() << "\t" << d[arrayNumber[i]].showNum() << "\t" << d[arrayNumber[i]].showNumber(select) << endl; } cin.get(); cin.get(); } }
~cpp //Order.cpp #include <iostream> using namespace std; #include "Order.h" Order::Order() { submenu = 0; } bool Order::IsItAll() { if (mainmenu == 3 || mainmenu == 4) return true; else return false; } bool Order::IsItSort() { if (mainmenu == 2 || mainmenu == 4) return true; else return false; } void Order::menu() { system("cls"); cout << "\t◆ 메뉴 ◆" << endl << "1) 과목별 입력 결과 리스트 " << endl << "2) 과목별 성적순 리스트 " << endl << "3) 학생 전과목 입력 결과 리스트 " << endl << "4) 학생 전과목 성적순 리스트 " << endl << "5) 종료 " << endl << endl << "메뉴를 선택하세요 -> "; cin >> mainmenu; if (mainmenu == 5) exit(1); if (mainmenu == 1 || mainmenu == 2) { system("cls"); cout << "\t◇과목 선택 메뉴◇" << endl << "1) 국어" << endl << "2) 영어" << endl << "3) 수학" << endl << "과목을 선택하세요 -> "; cin >> submenu; } } int Order::subNumber() { return submenu; }
~cpp #include <iostream> using namespace std; #include "Data.h" #include "Judgement.h" #include "Order.h" Data data[] = { Data( "고재선" ,20025301, 85, 90, 80 ), Data( "권현진" ,20025302, 80, 88, 85 ), Data( "김동욱" ,20025303, 88, 93, 75 ), Data( "김무영" ,20025309, 75, 85, 70 ), Data( "김민재" ,20025307, 73, 83, 77 ), Data( "김성원" ,20025304, 95, 88, 80 ), Data( "김영준" ,20025308, 95, 88, 80 ), Data( "김윤섭" ,20025305, 94, 70, 65 ), Data( "김철호" ,20025306, 80, 75, 88 ), Data( "김태완" ,20025310, 65, 73, 94 ), Data( "김태완" ,20025313, 77, 78, 99 ), Data( "김희균" ,20025312, 80, 77, 85 ), Data( "류재현" ,20025311, 95, 80, 95 ), Data( "문구봉" ,20025315, 78, 90, 75 ), Data( "박대원" ,20025314, 90, 95, 65 ), Data( "박세연" ,20025316, 88, 88, 80 ), Data( "박준성" ,20025317, 83, 76, 75 ), Data( "서수원" ,20025318, 75, 68, 70 ), Data( "양민우" ,20025319, 65, 70, 80 ), Data( "양정은" ,20025320, 88, 85, 90 ) }; int main() { while (1) { Judgement judgement; Order order; order.menu(); judgement.sort(order.IsItSort(), order.subNumber(), data); judgement.outputAll(order.IsItAll(), data); judgement.outputPart(!(order.IsItAll()), data, order.subNumber()); } return 0; }