hpnq

FINALLY

Jul 13th, 2024
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 16.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include<windows.h>
  5.  
  6. using namespace std;
  7.  
  8. const int MAX_STUDENTS = 100;
  9. const int MAX_COURSE_PLANS = 100;
  10. const int MAX_PERFORMANCES = 10000; //поменяла
  11.  
  12. //ебаная функция проверяет строку
  13. bool checkint( string s ) {
  14.     for( int i = 0; i < s.length(); i++ ) {
  15.         if( !isdigit( s[i] )) {
  16.             return false;
  17.         }
  18.     }
  19.     return true;
  20. }
  21.  
  22. struct Student {
  23.     string fio;
  24.     string recordBookNumber;
  25.     string group;
  26.     int course;
  27.     bool socialScholarship;
  28.  
  29.     Student() : fio(""), recordBookNumber(""), group(""), course(0), socialScholarship(false) {}
  30.  
  31.     Student(string f, string r, string g, int c, bool s)
  32.             : fio(f), recordBookNumber(r), group(g), course(c), socialScholarship(s) {}
  33. };
  34.  
  35. struct CoursePlan {
  36.     string subject;
  37.     int hours;
  38.     int semester;
  39.     string formOfControl;
  40.  
  41.     CoursePlan() : subject(""), hours(0), semester(0), formOfControl("") {}
  42.     CoursePlan(string sub, int h, int sem, string form)
  43.             : subject(sub), hours(h), semester(sem), formOfControl(form) {}
  44. };
  45.  
  46. struct Performance {
  47.     string studentRecordBookNumber;
  48.     string subject;
  49.     int grade;
  50.  
  51.     Performance() : studentRecordBookNumber(""), subject(""), grade(0) {}
  52.     Performance(string srb, string sub, int g)
  53.             : studentRecordBookNumber(srb), subject(sub), grade(g) {}
  54. };
  55.  
  56. class Deanery {
  57. private:
  58.     Student students[MAX_STUDENTS];
  59.     int studentCount;
  60.     CoursePlan coursePlans[MAX_COURSE_PLANS];
  61.     int coursePlanCount;
  62.     Performance performances[MAX_PERFORMANCES];
  63.     int performanceCount;
  64.  
  65. public:
  66.     Deanery() : studentCount(0), coursePlanCount(0), performanceCount(0) {}
  67.  
  68.     void loadStudents(const string &filename) {
  69.         ifstream inFile(filename);
  70.         if (inFile.is_open()) {
  71.             string f,i,o;
  72.             while (inFile >> f >> i >> o
  73.                           >> students[studentCount].recordBookNumber
  74.                           >> students[studentCount].group
  75.                           >> students[studentCount].course
  76.                           >> students[studentCount].socialScholarship) {
  77.  
  78.                 students[studentCount].fio = f + " " + i + " " + o;
  79.                 studentCount++;
  80.             }
  81.             inFile.close();
  82.         }
  83.         else {
  84.             cerr << "Error opening file: " << filename << endl;
  85.         }
  86.     }
  87.  
  88.     void loadCoursePlans(const string &filename) {
  89.         // проблема со считыванием, когда у нас объект состоит из > 0 пробелов
  90.         ifstream inFile(filename);
  91.         if (inFile.is_open()) {
  92.             while (!inFile.eof()){
  93.                 string x;
  94.                 coursePlans[coursePlanCount].subject = "";
  95.                 while(inFile >> x){
  96.  
  97.                     if(checkint(x)){
  98.                         break;
  99.                     }
  100.                     else{
  101.                         coursePlans[coursePlanCount].subject += x + " ";
  102.                     }
  103.                 }
  104.                 coursePlans[coursePlanCount].subject.pop_back(); // удаляем последний символ.
  105. //                cout << x << endl;
  106.  
  107.  
  108.                 coursePlans[coursePlanCount].hours = stoi(x);
  109.  
  110.                 inFile >> coursePlans[coursePlanCount].semester
  111.                        >> coursePlans[coursePlanCount].formOfControl;
  112.  
  113.                 coursePlanCount++;
  114.             }
  115.             inFile.close();
  116.         } else {
  117.             cerr << "Error opening file: " << filename << endl;
  118.         }
  119.     }
  120.  
  121.     void savePerformance(const string &filename) {
  122.         ofstream outFile(filename);
  123. //        cout << "SAVING\n" << performanceCount << endl;
  124.         if (outFile.is_open()) {
  125.             for (int i = 0; i < performanceCount; ++i) {
  126.                 outFile << performances[i].studentRecordBookNumber << " "
  127.                         << performances[i].subject << " "
  128.                         << performances[i].grade << endl;
  129.             }
  130.             outFile.close();
  131.             cout << "closed!" << endl;
  132.         } else {
  133.             cerr << "Error opening file: " << filename << endl;
  134.         }
  135.     }
  136.  
  137.  
  138.     void changeStudentFile(){
  139.         string y, w, z;
  140.         char ch;
  141.         cout << "Хотите ли изменить данные о уебки(y/n)" << endl;
  142.         cin >> ch;
  143.         while(ch!='n'){
  144.             cout << "Введите номер зачётки пользователя о котором хотите изменить информацию: " << endl;
  145.             cin >> y; // номер зачетки
  146.             cout << "Введите новую информацию об этом студенте" << endl;
  147.  
  148.             for (int j = 0; j < studentCount; ++j) {
  149.                 if (students[j].recordBookNumber == y) {
  150.                     // апдейтим ещё и перфоманс
  151.  
  152.                     string f,i,o;
  153.                     cin >> f >> i >> o
  154.                         >> students[j].recordBookNumber
  155.                         >> students[j].group
  156.                         >> students[j].course
  157.                         >> students[j].socialScholarship;
  158.  
  159.                     // --------------- UPDATE PERFOMANCES ------------ NEED TO UPDATE GRADE LATER
  160.                     for(int q = 0; q < performanceCount; q++){
  161.                         if(y == performances[q].studentRecordBookNumber ){
  162.                             performances[q].studentRecordBookNumber = students[j].recordBookNumber;
  163.                         }
  164.                     }
  165.                     // --------------- UPDATE PERFOMANCES ------------ NEED TO UPDATE GRADE LATER
  166.  
  167.                     students[j].fio = f + " " + i + " " + o;
  168.                 }
  169.             }
  170.             cout << "Ввести еще слово? (y/n)" << endl;
  171.             cin >> ch;
  172.         }
  173.     }
  174.  
  175.     void changeStudy_planFile(){
  176.         string y, w, z;
  177.         char ch;
  178.         cout << "Хотите ли вы изменить информацию о предмете?(y/n)\n";
  179.         cin >> ch;
  180.         while(ch!='n'){
  181.             cout << "Введите предмет, информацию о котором хотите изменить: " << endl;
  182.             //не уверена насчёт ввода, потому что слов может быть несколько
  183.             cin.ignore();
  184.             getline(cin,y);
  185.             cout << "Введите информацию о новом предмете";
  186.             for (int i = 0; i < coursePlanCount; ++i) {
  187.                 if (coursePlans[i].subject == y) {
  188.                     string s1;
  189.                     while(cin >> s1){
  190.                         if(checkint(s1)){
  191.                            break;
  192.                         }else{
  193.                             coursePlans[i].subject += s1;
  194.                         }
  195.                     }
  196.  
  197.                     coursePlans[i].hours = stoi(s1);
  198.                     cin
  199.                         >> coursePlans[i].semester
  200.                         >> coursePlans[i].formOfControl;
  201.  
  202.                     // --------------- UPDATE PERFOMANCES ------------ NEED TO UPDATE GRADE LATER
  203.  
  204.                     for(int q = 0; q < performanceCount; q++){
  205.                         if(y == performances[q].subject ){
  206.                             performances[q].subject = coursePlans[i].subject;
  207.                         }
  208.                     }
  209.                     // --------------- UPDATE PERFOMANCES ------------ NEED TO UPDATE GRADE LATER
  210.  
  211.                 }
  212.             }
  213.             cout<<"Ввести еще слово? (y/n)"<<endl;
  214.             cin>>ch;
  215.         }
  216.  
  217.     }
  218.  
  219.     void updatePerformanceFile(const string &filename) {
  220.         ofstream outFile(filename);
  221.         if (outFile.is_open()) {
  222.             for (int i = 0; i < studentCount; ++i) {
  223.                 //вот тут у меня проблемы... короче, мы думали, что у студента может смениться номер зачётки, но ещё может смениться и номер курса
  224.                 //я не знаю что писать, может придумаю позже. подумай пока ты
  225.             }
  226.             outFile.close();
  227.         } else {
  228.             cerr << "Error opening file: " << filename << endl;
  229.         }
  230.     }
  231.  
  232.     void updateStudentFile(const string &filename) {
  233.         ofstream outFile(filename);
  234.         if (outFile.is_open()) {
  235.             for (int i = 0; i < studentCount; ++i) {
  236.                 outFile << students[i].fio << " "
  237.                         << students[i].recordBookNumber << " "
  238.                         << students[i].group << " "
  239.                         << students[i].course << " "
  240.                         << students[i].socialScholarship << endl;
  241.             }
  242.             outFile.close();
  243.         } else {
  244.             cerr << "Error opening file: " << filename << endl;
  245.         }
  246.     }
  247.  
  248.     void updateCoursePlanFile(const string &filename) {
  249.         ofstream outFile(filename);
  250.         if (outFile.is_open()) {
  251.             for (int i = 0; i < coursePlanCount; ++i) {
  252.                 outFile << coursePlans[i].subject << " "
  253.                         << coursePlans[i].hours << " "
  254.                         << coursePlans[i].semester << " "
  255.                         << coursePlans[i].formOfControl << endl;
  256.             }
  257.             outFile.close();
  258.         } else {
  259.             cerr << "Error opening file: " << filename << endl;
  260.         }
  261.     }
  262.  
  263.     void selectStudentsByGroup(const string &group) {
  264.         for (int i = 0; i < studentCount; ++i) {
  265.             if (students[i].group == group) {
  266.                 cout << students[i].fio << " "
  267.                      << students[i].recordBookNumber << " "
  268.                      << students[i].group << " "
  269.                      << students[i].course << " "
  270.                      << students[i].socialScholarship << endl;
  271.             }
  272.         }
  273.     }
  274.  
  275.     void listFailingStudents() {
  276.         for (int i = 0; i < studentCount; ++i) {
  277.             bool failing = false;
  278.             for (int j = 0; j < performanceCount; ++j) {
  279.                 if (performances[j].studentRecordBookNumber == students[i].recordBookNumber && performances[j].grade < 3 &&performances[j].grade!=1 ) {
  280.                     failing = true;
  281.                     break;
  282.                 }
  283.             }
  284.             if (failing) {
  285.                 cout << students[i].fio << " " << students[i].recordBookNumber << endl;
  286.             }
  287.         }
  288.     }
  289.  
  290.     void promoteStudents() {
  291.         for (int i = 0; i < studentCount; ++i) {
  292.             bool passing = true;
  293.             for (int j = 0; j < performanceCount; ++j) {
  294.                 if (performances[j].studentRecordBookNumber == students[i].recordBookNumber && performances[j].grade < 3 && performances[j].grade != 1) {
  295.                     passing = false;
  296.                     break;
  297.                 }
  298.             }
  299.             if (passing) {
  300.                 students[i].course++;
  301.             }
  302.         }
  303.     }
  304.  
  305.     void assignScholarships() {
  306.         for (int i = 0; i < studentCount; ++i) {
  307.             bool eligible = true;
  308.             for (int j = 0; j < performanceCount; ++j) {
  309.                 if (performances[j].studentRecordBookNumber == students[i].recordBookNumber && performances[j].grade < 4 && performances[j].grade != 1) {
  310.                     eligible = false;
  311.                     break;
  312.                 }
  313.             }
  314.             if (eligible) {
  315.                 cout << "Scholarship assigned to: " << students[i].fio << endl;
  316.             }
  317.         }
  318.     }
  319.  
  320.  
  321.     string getSubjectType(string sub){
  322.         for(int i = 0; i < coursePlanCount; i++){
  323.             if(coursePlans[i].subject == sub){
  324.                 return coursePlans[i].formOfControl;
  325.             }
  326.         }
  327.         return "error"; // типо ввели неправильно
  328.     }
  329.     void out_s(){
  330.         cout << "STUDENTS\n";
  331.         cout << studentCount << endl;
  332.         for(int i = 0 ; i < studentCount; i++ ){
  333.             cout << students[i].fio <<" "
  334.                  << students[i].recordBookNumber << " "
  335.                  << students[i].course << "\n";
  336.         }
  337.     }
  338.     bool good_book(string &n){ // проверка на то что такая зачетка у кого то есть
  339.         for(int i = 0; i < studentCount; i++){
  340.             if(students[i].recordBookNumber == n){
  341.                 return true;
  342.             }
  343.         }
  344.         return false;
  345.     }
  346.  
  347.     void adddddddPerformance(){
  348.         int k = 0;
  349.         for(int i=0; i < studentCount; i++){
  350.  
  351.             cout << students[i].recordBookNumber << endl;
  352.  
  353.             for(int j = 0; j < coursePlanCount; j++){
  354.  
  355.                 if((students[i].course * 2) == coursePlans[j].semester or
  356.                 (students[i].course * 2) == (coursePlans[j].semester + 1)){
  357.  
  358.                     //тут я хочу проверить если курс студента *2 равен семестру или семестру +1(из файла с предметами) то добавляем предмет в файл grade
  359.                     performances[k].studentRecordBookNumber = students[i].recordBookNumber;
  360.                     performances[k].subject = coursePlans[j].subject;
  361.  
  362.                     int grade;
  363.                     string ans = getSubjectType(coursePlans[j].subject);
  364.                     cout << coursePlans[j].subject << endl;
  365.  
  366.                     while(true){
  367.                         if(ans == "зачет"){
  368.                             cout << "Enter 0(bad) or 1(good)\n";
  369. //                            cin >> grade;
  370.                             grade = 1;
  371.                             performances[k].grade = grade;
  372.                             break;
  373.                         }else if(ans == "экзамен"){
  374.                             cout << "Enter from 2(bad) to 5(excellent)\n";
  375. //                            cin >> grade;
  376.                             grade = 4;
  377.                             performances[k].grade = grade;
  378.                             break;
  379.                         }else{
  380.                             cout << "Wrong subject. try again";
  381.                         }
  382.                     }
  383.                     k++;
  384.                 }
  385.             }
  386.         }
  387.         // ------------------------------ UPDATED ---------------------------------------
  388.         performanceCount = k;
  389.         // ------------------------------ UPDATED ---------------------------------------
  390.  
  391.     }
  392. };
  393.  
  394. int main() {
  395.     system("chcp 1251");
  396.     Deanery deanery;
  397.  
  398.     // Загрузка данных студентов и учебных планов
  399.     deanery.loadStudents("Students.txt");
  400.  
  401.     deanery.loadCoursePlans("Study_plan.txt");
  402. //    deanery.out_s();
  403.  
  404.     //заполняем про успеваемость
  405.     deanery.adddddddPerformance();
  406.     deanery.savePerformance("Grade.txt");
  407.  
  408.  
  409.  
  410.     //----------------------------------------------------------------------------------------------------
  411.     //тут мои записки сумасшедшего
  412.     //дописать изменение массивов студент и студент план
  413.     deanery.changeStudentFile();
  414.     deanery.changeStudy_planFile();
  415.  
  416.  
  417.  
  418.  
  419.     //изменить файл грэйд(если меняем номер зачётной книжки у студента)
  420. //    deanery.updatePerformanceFile("Grade.txt");
  421.     // вместо этой хуйни я написал обновления МАССИВа сразу, как мы меняем что-то. нужно обновить файл перфомансов.
  422.     //-------------------------------------------------------------------------------------------------------------
  423.  
  424.  
  425.     // Вносим изменения в файлы
  426.     deanery.updateStudentFile("Students.txt");
  427.     deanery.updateCoursePlanFile("Study_plan.txt");
  428.  
  429.     // Делаем выборку по группе
  430.     string group;
  431.     cout << "Group: " << endl;
  432.     cin >> group;
  433.     cout << "Students in group " << group << ":" << endl;
  434.     deanery.selectStudentsByGroup(group);
  435.  
  436.     // Выводим неуспевающих студентов
  437.     cout << "Failing students:" << endl;
  438.     deanery.listFailingStudents();
  439.  
  440.     // Переводим студентов на следующий курс
  441.     deanery.promoteStudents();
  442.     deanery.updateStudentFile("Students.txt");
  443.  
  444.     // Назначаем стипендию
  445.     deanery.assignScholarships();
  446.  
  447.     return 0;
  448. }
  449.  
Advertisement
Add Comment
Please, Sign In to add comment