|
| 1 | +// |
| 2 | +// Created by Daisy on 2020/12/14. |
| 3 | +// |
| 4 | + |
| 5 | +#include <string> |
| 6 | +#include <vector> |
| 7 | +#include <iostream> |
| 8 | +#include <algorithm> |
| 9 | +#include <iomanip> |
| 10 | +#include "../5_organize program_data/original/grade.h" |
| 11 | + |
| 12 | +using std::istream; |
| 13 | +using namespace std; |
| 14 | + |
| 15 | +class Student_info_dnc{ |
| 16 | +private: |
| 17 | + std::string n; |
| 18 | + double midterm, final; |
| 19 | + std::vector<double> homework; |
| 20 | + std::istream& readhw(std::istream&); |
| 21 | + |
| 22 | +public: |
| 23 | + std::istream& read(std::istream&); |
| 24 | + double grade() const; |
| 25 | + std::string name() const {return n;} |
| 26 | + bool valid() const {return !homework.empty();} |
| 27 | + Student_info_dnc(): midterm(0),final(0) {}; |
| 28 | + Student_info_dnc(std::istream& in) {read(in);}; |
| 29 | +}; |
| 30 | + |
| 31 | +double Student_info_dnc::grade() const |
| 32 | +{ |
| 33 | + return ::calgrade(midterm,final,homework); |
| 34 | +} |
| 35 | + |
| 36 | +bool compare_dnc(const Student_info_dnc& x, const Student_info_dnc& y) |
| 37 | +{ |
| 38 | + return x.name() < y.name(); |
| 39 | +} |
| 40 | + |
| 41 | +bool compare_dnc_pass(const Student_info_dnc& x, const Student_info_dnc& y) |
| 42 | +{ |
| 43 | + return x.grade() > y.grade(); |
| 44 | +} |
| 45 | + |
| 46 | +std::istream& Student_info_dnc::readhw(std::istream& in){ |
| 47 | + if(in){ |
| 48 | + homework.clear(); |
| 49 | + double x; |
| 50 | + while(in>>x) |
| 51 | + homework.push_back(x); |
| 52 | + |
| 53 | + in.clear(); |
| 54 | + } |
| 55 | + return in; |
| 56 | +} |
| 57 | + |
| 58 | +std::istream& Student_info_dnc::read(std::istream& in ) { |
| 59 | + in >> n >> midterm >> final; |
| 60 | + readhw(in); |
| 61 | + return in; |
| 62 | +}; |
| 63 | + |
| 64 | +string PF_grade(double grade) |
| 65 | +{ |
| 66 | + if(grade>60) |
| 67 | + return "P"; |
| 68 | + else |
| 69 | + return "F"; |
| 70 | +} |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | +int main() |
| 75 | +{ |
| 76 | + vector<Student_info_dnc> students; |
| 77 | + Student_info_dnc record; |
| 78 | + string::size_type maxlen = 0; |
| 79 | + |
| 80 | + while (record.read(cin)) |
| 81 | + { |
| 82 | + maxlen = max(maxlen, record.name().size()); |
| 83 | + students.push_back(record); |
| 84 | + } |
| 85 | + |
| 86 | + sort(students.begin(),students.end(), compare_dnc); |
| 87 | + |
| 88 | + for (vector<Student_info_dnc>::size_type i = 0; i!=students.size(); ++i) |
| 89 | + { |
| 90 | + cout <<setw(maxlen+1) << students[i].name(); |
| 91 | + if (students[i].valid()){ |
| 92 | + double final_grade = students[i].grade(); |
| 93 | + streamsize prec = cout.precision(); |
| 94 | + cout << setprecision(3) |
| 95 | + <<setw(maxlen+1) << final_grade |
| 96 | + <<setw(maxlen+1) << PF_grade(final_grade) |
| 97 | + << setprecision(prec) << endl; |
| 98 | + } |
| 99 | + else |
| 100 | + cout << " This student didn't submit homework" << endl; |
| 101 | + } |
| 102 | + |
| 103 | +// sort(students.begin(), students.end(), compare_dnc_pass); |
| 104 | + |
| 105 | + return 0; |
| 106 | +} |
| 107 | + |
| 108 | + |
| 109 | +//d 80 90 80 80 80 80 |
| 110 | +//c 80 90 80 80 80 80 |
| 111 | +//a 80 90 44 34 23 12 |
| 112 | +//e 80 90 80 80 80 80 |
| 113 | +//b 80 90 |
| 114 | +// end of file |
| 115 | + |
| 116 | + |
| 117 | +//d 80 90 80 80 80 80 |
| 118 | +//c 20 40 30 30 10 80 |
| 119 | +//a 80 90 44 34 23 12 |
| 120 | +//e 20 10 30 10 20 20 |
| 121 | +//b 80 90 10 |
| 122 | +// end of file |
0 commit comments