Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <sstream>
- #include <queue>
- using namespace std;
- /*
- Список студентів
- sdudent 12
- Adam 9
- Nikol 2
- Dio 13
- Kostya 20
- Bohdan 20
- Roma 10
- Kia 2
- */
- //структура
- struct student{
- string name = "";
- int score = 0;
- };
- void read_file(queue<student> &q, string path){
- queue<student> more_ten; //для больше 10
- queue<student> nine_or_ten; // для 10 или 9
- queue<student> two; // для 2
- ifstream info_students(path);
- string line;
- student student;
- stringstream ss;
- while(getline(info_students, line)){
- ss << line;
- ss >> student.name;
- ss >> student.score;
- if(student.score > 10){
- more_ten.push(student);
- }
- else if(student.score > 8 && student.score < 11){
- nine_or_ten.push(student);
- }
- else{
- two.push(student);
- }
- ss.clear();
- }
- //вывод! для больше 10
- while(!more_ten.empty()){
- q.push(more_ten.front());
- more_ten.pop();
- }
- //вывод! для 10 или 9
- while(!nine_or_ten.empty()){
- q.push(nine_or_ten.front());
- nine_or_ten.pop();
- }
- //вывод! для 2
- while(!two.empty()){
- q.push(two.front());
- two.pop();
- }
- }
- /**
- * Вывод!
- * @param q что вывести
- */
- void print_queue(queue<student> q){
- while(!q.empty()){
- cout << "Name : " << q.front().name << endl
- << "Score : " << q.front().score << endl << endl;
- q.pop();
- }
- }
- int main()
- {
- queue<student> students_info;
- read_file(students_info, "D:\\C++\\Task_17\\students_info.txt");
- print_queue(students_info);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement