Advertisement
evcamels

timp_2-18

Dec 23rd, 2021
779
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <fstream>
  5. #include <cstdlib>
  6.  
  7. using namespace std;
  8.  
  9. string musor;
  10.  
  11. struct Student {
  12.     string Name;
  13.     string Surname;
  14.     string Fathername;
  15.     string Pol;
  16.     string Faculty;
  17.     int Course;
  18.     string Group;
  19.     int Oc[5]; //дневник
  20.     string Residence;
  21.     Student() {
  22.  
  23.     }
  24.     Student(string Name, string Surname, string Fathername, string Pol, string Faculty, int Course, string Group, int O[5], string Residence) {
  25.         this->Name = Name;
  26.         this->Surname = Surname;
  27.         this->Fathername = Fathername;
  28.         this->Pol = Pol;
  29.         this->Faculty = Faculty;
  30.         this->Course = Course;
  31.         this->Group = Group;
  32.         for (int i = 0; i < 5; i++) {
  33.             Oc[i] = O[i];
  34.         }
  35.         this->Residence = Residence;
  36.     }
  37.     void S() {
  38.         cout << "Имя: ";
  39.         getline(cin, Name);
  40.         cout << "Фамилия: ";
  41.         getline(cin, Surname);
  42.         cout << "Отчество: ";
  43.         getline(cin, Fathername);
  44.         cout << "Пол: ";
  45.         getline(cin, Pol);
  46.         cout << "Факультет: ";
  47.         getline(cin, Faculty);
  48.         cout << "Курс: ";
  49.         cin >> Course;
  50.         getline(cin, musor);
  51.         cout << "Группа: ";
  52.         getline(cin, Group);
  53.         cout << "Оценка по предметам: " << endl;
  54.         for (int i = 0; i < 5; i++) {
  55.             cout << i + 1 << " предмет: ";
  56.             cin >> Oc[i];
  57.         }
  58.         getline(cin, musor);
  59.         cout << "Место жительства: ";
  60.         getline(cin, Residence);
  61.     }
  62.     void Show() {
  63.         cout << "Имя: " << Name << endl;
  64.         cout << "Фамилия: " << Surname << endl;
  65.         cout << "Отчество: " << Fathername << endl;
  66.         cout << "Пол: " << Pol << endl;
  67.         cout << "Факультет: " << Faculty << endl;
  68.         cout << "Курс: " << Course << endl;
  69.         cout << "Группа: " << Group << endl;
  70.         cout << "Оценка по предметам: " << endl;;
  71.         for (int i = 0; i < 5; i++) {
  72.             cout << i + 1 << " предмет: " << Oc[i] << endl;
  73.         }
  74.         cout << "Место жительства: " << Residence << endl;
  75.     }
  76. };
  77.  
  78. int main() {
  79.     std::setlocale(LC_CTYPE, "");
  80.     SetConsoleCP(1251);
  81.     SetConsoleOutputCP(1251);
  82.     vector <Student> Students;
  83.     ifstream in("C:\\Users\\Никита\\Desktop\\folder\\TIMP2\\file2.txt");
  84.     int k;
  85.     if (in.is_open()) {
  86.         in >> k;
  87.         for (int i = 0; i < k; i++) {
  88.             string Name;
  89.             string Surname;
  90.             string Fathername;
  91.             string Pol;
  92.             string Faculty;
  93.             int Course;
  94.             string Group;
  95.             int Oc[5]; //дневник
  96.             string Residence;
  97.             in >> Name;
  98.             in >> Surname;
  99.             in >> Fathername;
  100.             in >> Pol;
  101.             in >> Faculty;
  102.             in >> Course;
  103.             in >> Group;
  104.             in >> Oc[0];
  105.             in >> Oc[1];
  106.             in >> Oc[2];
  107.             in >> Oc[3];
  108.             in >> Oc[4];
  109.             in >> Residence;
  110.             Student s(Name, Surname, Fathername, Pol, Faculty, Course, Group, Oc, Residence);
  111.             Students.push_back(s);
  112.         }
  113.     }
  114.     in.close();
  115.     vector <Student> D; //список задолжников
  116.     vector <Student> F; //список обычных студентов
  117.     for (int j = 0; j < Students.size(); j++) {
  118.         int c = 0;
  119.         for (int i = 0; i < 5; i++) {
  120.             if (Students[j].Oc[i] == 0) {
  121.                 c++; //оценка 0 - задолженность
  122.             }
  123.         }
  124.         if (c == 2) {
  125.             D.push_back(Students[j]);
  126.         }
  127.         else {
  128.             F.push_back(Students[j]);
  129.         }
  130.         c = 0;
  131.     }
  132.     for (int i = D.size() - 1; i > 0; i--) { //сортировка по алфавиту
  133.         for (int j = 0; j <= i; j++) {
  134.             if (D[j].Surname[0] > D[i].Surname[0]) {
  135.                 swap(D[j], D[i]);
  136.             }
  137.         }
  138.     }
  139.     cout << "Задолжники по 2 предметам: " << endl;
  140.     for (int i = 0; i < D.size(); i++) {
  141.         cout << D[i].Surname << endl;
  142.     }
  143.     ofstream out;
  144.     out.open("C:\\Users\\Никита\\Desktop\\folder\\TIMP2\\file.txt");
  145.     if (out.is_open())
  146.     {
  147.         out << "Задолжники по 2 предметам: " << endl;
  148.         for (int i = 0; i < D.size(); i++) {
  149.             out << D[i].Name << endl;
  150.             out << D[i].Surname << endl;
  151.             out << D[i].Fathername << endl;
  152.             out << "Пол: " << D[i].Pol << endl;
  153.             out << "Факультет: " << D[i].Faculty << endl;
  154.             out << "Курс: " << D[i].Course << endl;
  155.             out << "Группа: " << D[i].Group << endl;
  156.             out << "Оценки: " << endl;
  157.             for (int j = 0; j < 5; j++) {
  158.                 out << j + 1 << " предмет: " << D[i].Oc[j];
  159.                 out << endl;
  160.             }
  161.             out << "Адрес проживания: " << D[i].Residence << endl;
  162.             out << endl;
  163.         }
  164.         out << "Другие студенты: " << endl;
  165.         for (int i = 0; i < F.size(); i++) {
  166.             out << F[i].Name << endl;
  167.             out << F[i].Surname << endl;
  168.             out << F[i].Fathername << endl;
  169.             out << "Пол: " << F[i].Pol << endl;
  170.             out << "Факультет: " << F[i].Faculty << endl;
  171.             out << "Курс: " << F[i].Course << endl;
  172.             out << "Группа: " << F[i].Group << endl;
  173.             out << "Оценки: " << endl;
  174.             for (int j = 0; j < 5; j++) {
  175.                 out << j + 1 << " предмет: " << F[i].Oc[j];
  176.                 out << endl;
  177.             }
  178.             out << "Адрес проживания: " << F[i].Residence << endl;
  179.             out << endl;
  180.         }
  181.     }
  182.     out.close();
  183.     system("pause");
  184.     return 0;
  185. }
  186.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement