소감 ¶
이제 된다 T^T
구조는 거의다 보창이형껄 배꼈지만
나름대로 열시미한 =ㅅ=
구조는 거의다 보창이형껄 배꼈지만
나름대로 열시미한 =ㅅ=
코드 ¶
Grade.h ¶
~cpp #ifndef GRADE_H_ #define GRADE_H_ #include "student.h" class Grade { private: Student * students; public: Grade(); void show_good_student(); void show_bad_student(); void show_all_student(); ~Grade(); }; #endif
Grade.cpp ¶
~cpp #include <iostream> using namespace std; #include "grade.h" #define MAX_STUDENT 121 Grade::Grade() { students = new Student[MAX_STUDENT]; for (int i=1;i<MAX_STUDENT;i++) { students[i].input(); } } void Grade::show_good_student() { double compare=4.5; int num=MAX_STUDENT/10; int good_student_number=0; cout << "장학생 명단\n"; while (1) { int i,j; double temp=4.5; for (i=1;i < MAX_STUDENT;i++) { if (compare-students[i].average < temp && compare-students[i].average > 0 ) { temp=compare-students[i].average; j=i; } } for (i=1;i < MAX_STUDENT;i++) { if (compare-students[i].average == temp) { students[i].show(); good_student_number++; } } compare=students[j].average; if (good_student_number>num) { break; } } cout << "\n\n"; } void Grade::show_bad_student() { cout << "학고 명단\n"; for (int i=1;i<MAX_STUDENT;i++) { if (students[i].average<1.5) students[i].show(); } cout << "\n\n"; } void Grade::show_all_student() { for (int i=1;i<MAX_STUDENT;i++) { students[i].show(); } cout << "\n\n"; } Grade::~Grade() { delete [] students; }
Student.h ¶
~cpp #ifndef STUDENT_H_ #define STUDENT_H_ class Student { private: int school_number; double grade[4]; public: Student(); double average; void input(); void show(); void get_average(); }; #endif
Student.cpp ¶
~cpp #include <iostream> #include <fstream> using namespace std; #include "student.h" Student::Student() { average = 0.0; school_number = 0; } void Student::input() { static fstream fin("input.txt"); char str[3]; double sum = 0.0; int i; fin.ignore(100, ' '); fin >> school_number; fin.ignore(100, ':'); for (i=0;i<4;i++) { fin >> str; if (str[0]=='F') { grade[i] = 0; } else { grade[i] = ((int)'F'-1)-(int)str[0]; } if (str[1]=='+'){ grade[i]+=0.5; } } fin.ignore(100, '\n'); for (i=0;i<4;i++){ sum += grade[i]; } average = sum/4; } void Student::show() { cout << "학번 : " << school_number << " 평점 : " << average << endl; }
main.cpp ¶
~cpp #include "grade.h" #include <iostream> using namespace std; void main() { Grade str; str.show_good_student(); str.show_bad_student(); str.show_all_student(); /* char str1[3]="A+" ; double sum1 = 0.0, average1 ; int i1 ; average1=((int)'F'-1)-(int)str1[0]; if (str1[1]=='+'){ average1+=0.5; } cout<<average1<<endl; cout<<(int)str1[0]<<endl<<(int)str1[1]<<endl<<(int)str1[2]; */} }