Advertisement
evcamels

lab-2_var-17

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