Bob103

quque2

Jul 12th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <iterator>
  4. #include <fstream>
  5. #include <string>
  6. #include <queue>
  7. #include <array>
  8.  
  9. using namespace std;
  10.  
  11. class Student
  12. {
  13. static const int SES_NUM = 5;
  14. string name, surname, secondname, gender;
  15. int age;
  16. array<int, SES_NUM> ses;
  17. public:
  18. friend ifstream& operator >> (ifstream& in, Student& st);
  19. friend ofstream& operator<< (ofstream& out, const Student& st);
  20. bool pass_exams() const
  21. {
  22. return *min_element(ses.begin(), ses.end()) > 2;
  23. }
  24. };
  25.  
  26. ifstream& operator >> (ifstream& in, Student& st)
  27. {
  28. in >> st.surname
  29. >> st.name
  30. >> st.secondname
  31. >> st.gender
  32. >> st.age;
  33. for (int i = 0; i < st.SES_NUM; ++i)
  34. in >> st.ses[i];
  35. return in;
  36. }
  37.  
  38. ofstream& operator << (ofstream& out, const Student& st)
  39. {
  40. out << st.surname << " "
  41. << st.name << " "
  42. << st.secondname << " "
  43. << st.gender << " "
  44. << st.age << " ";
  45. for (int i = 0; i < st.SES_NUM; ++i)
  46. out << st.ses[i] << " ";
  47. return out;
  48. }
  49.  
  50.  
  51. int main()
  52. {
  53. queue<Student> pass, not_pass;
  54. Student tmp;
  55.  
  56. string in_name = "input.txt", out_name = "output.txt";
  57. ifstream in(in_name);
  58. int st_num;
  59. in >> st_num;
  60.  
  61. for (int i = 0; i < st_num; ++i)
  62. {
  63. in >> tmp;
  64. if (tmp.pass_exams())
  65. pass.push(tmp);
  66. else
  67. pass.push(tmp);
  68. }
  69. in.close();
  70.  
  71. ofstream out(out_name);
  72. while (!pass.empty())
  73. {
  74. out << pass.front() << endl;
  75. pass.pop();
  76. }
  77. while (!not_pass.empty())
  78. {
  79. out << not_pass.front() << endl;
  80. not_pass.pop();
  81. }
  82. out.close();
  83.  
  84. cout << "Done" << endl;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment