¶
본 모 램 보 바랍.
CalculateGrade.h ¶
~cpp #ifndef CALCULATEGRADE_H_ #define CALCULATEGRADE_H_ #include "Student.h" class CalculateGrade { private: static const int NUM_STUDENT; // ( 멤) Student * student; // 들 배 public: CalculateGrade(); // void sort_student(); // void show_good_student(); // 명 void show_bad_student(); // 명 ~CalculateGrade(); // }; #endif
CalculateGrade.cpp ¶
~cpp #include <iostream> using namespace std; #include "CalculateGrade.h" // 멤 // - 배 덱를 1부 보 더 는. const int CalculateGrade::NUM_STUDENT = 121; // CalculateGrade::CalculateGrade() { // 배 동 student = new Student[NUM_STUDENT]; // 를 받 배 멤를 for (int i = 1; i < NUM_STUDENT; i++) student[i].input_grade(); } // . void CalculateGrade::sort_student() { int p; Student temp; for (int i = 1; i < NUM_STUDENT; i++) { p = i; for (int j = i + 1; j < NUM_STUDENT; j++) { if (student[p].average < student[j].average) p = j; } temp = student[i]; student[i] = student[p]; student[p] = temp; } } // ( 10%) 명 보. void CalculateGrade::show_good_student() { int num = NUM_STUDENT / 10; sort_student(); cout << " 명\n"; for (int i = 1; i <= num; i++) student[i].show(); cout << "\n\n"; } // ( 1.5미만) 명 보. void CalculateGrade::show_bad_student() { cout << " 명\n"; for (int i = 1; i < NUM_STUDENT; i++) { if (student[i].average < 1.5) student[i].show(); } cout << "\n\n"; } // CalculateGrade::~CalculateGrade() { delete [] student; }
Student.h ¶
~cpp #ifndef STUDENT_H_ #define STUDENT_H_ class Student { private: static const int NUM_GRADE; // 목 ( 멤) int number; // 번 double grade[4]; // 4목 public: double average; // Student(); // void find_average(); // 는 void input_grade(); // 받는 void show(); // }; #endif
Student.cpp ¶
~cpp #include <iostream> #include <fstream> #include <cstring> using namespace std; #include "Student.h" // 멤 const int Student::NUM_GRADE = 4; // Student::Student() { average = 0.0; number = 0; } // 부 4목 를 는. void Student::input_grade() { static char alpa_grade[9][3] = {"A+", "A", "B+", "B", "C+", "C", "D+", "D", "F"}; static double ital_grade[9] = {4.5, 4.0, 3.5, 3.0, 2.5, 2.0, 1.5, 1.0, 0.0}; static fstream fin("input.txt"); char str[3]; fin.ignore(100, ' '); // 문 리는 fin >> number; fin.ignore(100, ':'); // double 1대 1 변 for (int i = 0; i < NUM_GRADE; i++) { fin >> str; // >> white space(백) 무. for (int j = 0; j < 9; j++) { if (strcmp(str, alpa_grade[j]) == 0) { grade[i] = ital_grade[j]; break; } } } fin.ignore(100, '\n'); find_average(); } // 4 목 . void Student::find_average() { double sum = 0.0; for (int i = 0; i < NUM_GRADE; i++) sum += grade[i]; average = sum / NUM_GRADE; } // 보를 . void Student::show() { cout << "번 : " << number << " : " << average << endl; }
testCalculateGrade.cpp ¶
~cpp #include "CalculateGrade.h" int main() { CalculateGrade test; test.show_good_student(); test.show_bad_student(); return 0; }