hpnq

хуйня

Jul 11th, 2024
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. const int MAX_STUDENTS = 100;
  8. const int MAX_COURSE_PLANS = 100;
  9. const int MAX_PERFORMANCES = 100;
  10.  
  11. struct Student {
  12.     string fio;
  13.     string recordBookNumber;
  14.     string group;
  15.     int course;
  16.     bool socialScholarship;
  17.  
  18.     Student() : fio(""), recordBookNumber(""), group(""), course(0), socialScholarship(false) {}
  19.     Student(string f, string r, string g, int c, bool s)
  20.         : fio(f), recordBookNumber(r), group(g), course(c), socialScholarship(s) {}
  21. };
  22.  
  23. struct CoursePlan {
  24.     string subject;
  25.     int hours;
  26.     int semester;
  27.     string formOfControl;
  28.  
  29.     CoursePlan() : subject(""), hours(0), semester(0), formOfControl("") {}
  30.     CoursePlan(string sub, int h, int sem, string form)
  31.         : subject(sub), hours(h), semester(sem), formOfControl(form) {}
  32. };
  33.  
  34. struct Performance {
  35.     string studentRecordBookNumber;
  36.     string subject;
  37.     int grade;
  38.  
  39.     Performance() : studentRecordBookNumber(""), subject(""), grade(0) {}
  40.     Performance(string srb, string sub, int g)
  41.         : studentRecordBookNumber(srb), subject(sub), grade(g) {}
  42. };
  43.  
  44. class Deanery {
  45. private:
  46.     Student students[MAX_STUDENTS];
  47.     int studentCount;
  48.     CoursePlan coursePlans[MAX_COURSE_PLANS];
  49.     int coursePlanCount;
  50.     Performance performances[MAX_PERFORMANCES];
  51.     int performanceCount;
  52.  
  53. public:
  54.     Deanery() : studentCount(0), coursePlanCount(0), performanceCount(0) {}
  55.  
  56.     void loadStudents(const string &filename) {
  57.         ifstream inFile(filename);
  58.         if (inFile.is_open()) {
  59.             while (inFile >> students[studentCount].fio
  60.                           >> students[studentCount].recordBookNumber
  61.                           >> students[studentCount].group
  62.                           >> students[studentCount].course
  63.                           >> students[studentCount].socialScholarship) {
  64.                 studentCount++;
  65.             }
  66.             inFile.close();
  67.         } else {
  68.             cerr << "Error opening file: " << filename << endl;
  69.         }
  70.     }
  71.  
  72.     void loadCoursePlans(const string &filename) {
  73.         ifstream inFile(filename);
  74.         if (inFile.is_open()) {
  75.             while (inFile >> coursePlans[coursePlanCount].subject
  76.                           >> coursePlans[coursePlanCount].hours
  77.                           >> coursePlans[coursePlanCount].semester
  78.                           >> coursePlans[coursePlanCount].formOfControl) {
  79.                 coursePlanCount++;
  80.             }
  81.             inFile.close();
  82.         } else {
  83.             cerr << "Error opening file: " << filename << endl;
  84.         }
  85.     }
  86.  
  87.     void savePerformance(const string &filename) {
  88.         ofstream outFile(filename);
  89.         if (outFile.is_open()) {
  90.             for (int i = 0; i < performanceCount; ++i) {
  91.                 outFile << performances[i].studentRecordBookNumber << " "
  92.                         << performances[i].subject << " "
  93.                         << performances[i].grade << endl;
  94.             }
  95.             outFile.close();
  96.         } else {
  97.             cerr << "Error opening file: " << filename << endl;
  98.         }
  99.     }
  100.  
  101.     void updateStudentFile(const string &filename) {
  102.         ofstream outFile(filename);
  103.         if (outFile.is_open()) {
  104.             for (int i = 0; i < studentCount; ++i) {
  105.                 outFile << students[i].fio << " "
  106.                         << students[i].recordBookNumber << " "
  107.                         << students[i].group << " "
  108.                         << students[i].course << " "
  109.                         << students[i].socialScholarship << endl;
  110.             }
  111.             outFile.close();
  112.         } else {
  113.             cerr << "Error opening file: " << filename << endl;
  114.         }
  115.     }
  116.  
  117.     void updateCoursePlanFile(const string &filename) {
  118.         ofstream outFile(filename);
  119.         if (outFile.is_open()) {
  120.             for (int i = 0; i < coursePlanCount; ++i) {
  121.                 outFile << coursePlans[i].subject << " "
  122.                         << coursePlans[i].hours << " "
  123.                         << coursePlans[i].semester << " "
  124.                         << coursePlans[i].formOfControl << endl;
  125.             }
  126.             outFile.close();
  127.         } else {
  128.             cerr << "Error opening file: " << filename << endl;
  129.         }
  130.     }
  131.  
  132.     void selectStudentsByGroup(const string &group) {
  133.         for (int i = 0; i < studentCount; ++i) {
  134.             if (students[i].group == group) {
  135.                 cout << students[i].fio << " "
  136.                      << students[i].recordBookNumber << " "
  137.                      << students[i].group << " "
  138.                      << students[i].course << " "
  139.                      << students[i].socialScholarship << endl;
  140.             }
  141.         }
  142.     }
  143.  
  144.     void listFailingStudents() {
  145.         for (int i = 0; i < studentCount; ++i) {
  146.             bool failing = false;
  147.             for (int j = 0; j < performanceCount; ++j) {
  148.                 if (performances[j].studentRecordBookNumber == students[i].recordBookNumber && performances[j].grade < 3) {
  149.                     failing = true;
  150.                     break;
  151.                 }
  152.             }
  153.             if (failing) {
  154.                 cout << students[i].fio << " " << students[i].recordBookNumber << endl;
  155.             }
  156.         }
  157.     }
  158.  
  159.     void promoteStudents() {
  160.         for (int i = 0; i < studentCount; ++i) {
  161.             bool passing = true;
  162.             for (int j = 0; j < performanceCount; ++j) {
  163.                 if (performances[j].studentRecordBookNumber == students[i].recordBookNumber && performances[j].grade < 3) {
  164.                     passing = false;
  165.                     break;
  166.                 }
  167.             }
  168.             if (passing) {
  169.                 students[i].course++;
  170.             }
  171.         }
  172.     }
  173.  
  174.     void assignScholarships() {
  175.         for (int i = 0; i < studentCount; ++i) {
  176.             bool eligible = true;
  177.             for (int j = 0; j < performanceCount; ++j) {
  178.                 if (performances[j].studentRecordBookNumber == students[i].recordBookNumber && performances[j].grade < 4) {
  179.                     eligible = false;
  180.                     break;
  181.                 }
  182.             }
  183.             if (eligible) {
  184.                 cout << "Scholarship assigned to: " << students[i].fio << endl;
  185.             }
  186.         }
  187.     }
  188.  
  189.     void addPerformance(const string &recordBookNumber, const string &subject, int grade) {
  190.         if (performanceCount < MAX_PERFORMANCES) {
  191.             performances[performanceCount++] = Performance(recordBookNumber, subject, grade);
  192.         } else {
  193.             cerr << "Performance array is full" << endl;
  194.         }
  195.     }
  196. };
  197.  
  198. int main() {
  199.     Deanery deanery;
  200.  
  201.     // Загрузка данных студентов и учебных планов
  202.     deanery.loadStudents("students.txt");
  203.     deanery.loadCoursePlans("course_plans.txt");
  204.  
  205.     // Заполняем файл успеваемости студентов (пример)
  206.     deanery.addPerformance("12345", "Math", 5);
  207.     deanery.addPerformance("12345", "Physics", 4);
  208.     deanery.addPerformance("67890", "Math", 2);
  209.     deanery.addPerformance("67890", "Physics", 3);
  210.  
  211.     // Сохраняем успеваемость студентов
  212.     deanery.savePerformance("performance.txt");
  213.  
  214.     // Вносим изменения в файлы
  215.     deanery.updateStudentFile("students.txt");
  216.     deanery.updateCoursePlanFile("course_plans.txt");
  217.  
  218.     // Делаем выборку по группе
  219.     cout << "Students in group 'A1':" << endl;
  220.     deanery.selectStudentsByGroup("A1");
  221.  
  222.     // Выводим неуспевающих студентов
  223.     cout << "Failing students:" << endl;
  224.     deanery.listFailingStudents();
  225.  
  226.     // Переводим студентов на следующий курс
  227.     deanery.promoteStudents();
  228.     deanery.updateStudentFile("students.txt");
  229.  
  230.     // Назначаем стипендию
  231.     deanery.assignScholarships();
  232.  
  233.     return 0;
  234. }
  235.  
Advertisement
Add Comment
Please, Sign In to add comment