Advertisement
x2311

Untitled

Jun 7th, 2022
856
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4. #include <queue>
  5.  
  6. using namespace std;
  7.  
  8. /*
  9. Список студентів
  10.     sdudent 12
  11.     Adam 9
  12.     Nikol 2
  13.     Dio 13
  14.     Kostya 20
  15.     Bohdan 20
  16.     Roma 10
  17.     Kia 2
  18. */
  19. //структура
  20. struct student{
  21.     string name = "";
  22.     int score = 0;
  23. };
  24.  
  25. void read_file(queue<student> &q, string path){
  26.     queue<student> more_ten; //для больше 10
  27.     queue<student> nine_or_ten; // для 10 или 9
  28.     queue<student> two; // для 2
  29.  
  30.     ifstream info_students(path);
  31.     string line;
  32.     student student;
  33.     stringstream ss;
  34.  
  35.     while(getline(info_students, line)){
  36.         ss << line;
  37.         ss >> student.name;
  38.         ss >> student.score;
  39.         if(student.score > 10){
  40.             more_ten.push(student);
  41.         }
  42.         else if(student.score > 8 && student.score < 11){
  43.             nine_or_ten.push(student);
  44.         }
  45.         else{
  46.             two.push(student);
  47.         }
  48.         ss.clear();
  49.     }
  50.     //вывод! для больше 10
  51.     while(!more_ten.empty()){
  52.         q.push(more_ten.front());
  53.         more_ten.pop();
  54.     }
  55.     //вывод! для 10 или 9
  56.     while(!nine_or_ten.empty()){
  57.         q.push(nine_or_ten.front());
  58.         nine_or_ten.pop();
  59.     }
  60.     //вывод! для 2
  61.     while(!two.empty()){
  62.         q.push(two.front());
  63.         two.pop();
  64.     }
  65. }
  66. /**
  67.  * Вывод!
  68.  * @param q что вывести
  69.  */
  70. void print_queue(queue<student> q){
  71.     while(!q.empty()){
  72.         cout << "Name : " << q.front().name << endl
  73.              << "Score : " << q.front().score << endl << endl;
  74.         q.pop();
  75.     }
  76. }
  77.  
  78. int main()
  79. {
  80.     queue<student> students_info;
  81.     read_file(students_info, "D:\\C++\\Task_17\\students_info.txt");
  82.     print_queue(students_info);
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement