Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. int main()
  2. {
  3. vector<Student_info> students;
  4. Student_info record;
  5. string::size_type maxlen=0;
  6.  
  7. while (read(cin,record))
  8. {
  9. maxlen=max(maxlen,record.name.size());
  10. students.push_back(record);
  11. }
  12.  
  13. sort(students.begin(),students.end(),compare);
  14.  
  15. for (vector<Student_info>::size_type i=0; i!=students.size();i++)
  16. {
  17. cout<<students[i].name
  18. <<string(maxlen+1-students[i].name.size(),' ');
  19.  
  20. try
  21. {
  22. double final_grade=grade(students[i]);
  23. streamsize prec=cout.precision();
  24. cout<<setprecision(3)<<final_grade
  25. <<setprecision(prec);
  26. }
  27. catch (domain_error e)
  28. {
  29. cout<<e.what();
  30. }
  31. cout<<endl;
  32. }
  33. return 0;
  34. }
  35.  
  36. #include "Student_info.h"
  37.  
  38. using std::istream;
  39. using std::vector;
  40.  
  41. bool compare(const Student_info& x, const Student_info& y)
  42. {
  43. return x.name<y.name;
  44. }
  45.  
  46. istream& read(istream& is, Student_info& s)
  47. {
  48. is>>s.name>>s.midterm>>s.exam;
  49.  
  50. read_hw(is,s.homework);
  51. return is;
  52. }
  53.  
  54. istream& read_hw(istream& in, vector<double>& hw)
  55. {
  56. if (in)
  57. {
  58. hw.clear();
  59.  
  60. double x;
  61. while (in>>x)
  62. hw.push_back(x);
  63.  
  64. in.clear();
  65. }
  66. return in;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement