Advertisement
codegod313

Sashka:)

Jan 9th, 2021
816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <Windows.h>
  5.  
  6. using namespace std;
  7.  
  8. struct Student {
  9.     string name{};
  10.     string surname{};
  11.     string patronymic{};
  12.     int number_group{};
  13.     int birthYear{};
  14.     int physics{};
  15.     int math{};
  16.     int informatics{};
  17.     int chemistry{};
  18.     double gap = (physics + math + informatics + chemistry) / 4.;
  19. } spisok[5], student;
  20. int n = 0;
  21.  
  22. void menu();
  23. void add() {
  24.     ofstream fout("File.txt", ios::app);
  25.     string temp;
  26.     int temp_int = 0;
  27.     int middle = 0;
  28.     cout << "Enter name : ";
  29.     cin >> temp;
  30.     fout << temp << " ";
  31.     cout << "Enter surname : ";
  32.     cin >> temp;
  33.     fout << temp << " ";
  34.     cout << "Enter patronymic : ";
  35.     cin >> temp;
  36.     fout << temp << " ";
  37.     cout << "Enter number of group : ";
  38.     cin >> temp_int;
  39.     fout << temp_int << " ";
  40.     cout << "Enter year of birth : ";
  41.     cin >> temp_int;
  42.     fout << temp_int << " ";
  43.     cout << "Enter mark of physics : ";
  44.     cin >> temp_int;
  45.     middle += temp_int;
  46.     fout << temp_int << " ";
  47.     cout << "Enter mark of math : ";
  48.     cin >> temp_int;
  49.     middle += temp_int;
  50.     fout << temp_int << " ";
  51.     cout << "Enter mark of informatics : ";
  52.     cin >> temp_int;
  53.     middle += temp_int;
  54.     fout << temp_int << " ";
  55.     cout << "Enter mark of chemistry : ";
  56.     cin >> temp_int;
  57.     middle += temp_int;
  58.     fout << temp_int << " ";
  59.     fout << middle / 4.;
  60.     fout << endl;
  61. }
  62.  
  63. void show() {
  64.     ifstream fin("File.txt", ios::in);
  65.     string temp;
  66.     int t = 0;
  67.     double tt = 0;
  68.     while (!fin.eof()) {
  69.         fin >> temp;
  70.         if (temp == "") break;
  71.         cout<< "Name : " << temp << endl;
  72.         fin >> temp;
  73.         cout << "Surname : " << temp << endl;
  74.         fin >> temp;
  75.         cout << "Patronymic : " << temp << endl;
  76.         fin >> t;
  77.         cout << "Group : " << t << endl;
  78.         fin >> t;
  79.         cout << "Year of birth : " << t << endl;
  80.         fin >> t;
  81.         cout << "Physics : " << t << endl;
  82.         fin >> t;
  83.         cout << "Math : " << t << endl;
  84.         fin >> t;
  85.         cout << "Informatics : " << t << endl;
  86.         fin >> t;
  87.         cout << "Chemistry : " << t << endl;
  88.         fin >> tt;
  89.         cout << "Middle mark : " << tt << endl;
  90.         temp = "";
  91.         t = 0;
  92.         tt = 0;
  93.     }
  94. }
  95. void individual() {
  96.     system("cls");
  97.     ifstream fin("File.txt", ios::in);
  98.     n = 0;
  99.     while (!fin.eof()) {
  100.         fin >> spisok[n].name;
  101.         fin >> spisok[n].surname;
  102.         fin >> spisok[n].patronymic;
  103.         fin >> spisok[n].number_group;
  104.         fin >> spisok[n].birthYear;
  105.         fin >> spisok[n].physics;
  106.         fin >> spisok[n].math;
  107.         fin >> spisok[n].informatics;
  108.         fin >> spisok[n].chemistry;
  109.         fin >> spisok[n].gap;
  110.         n++;
  111.     }
  112.  
  113.     ofstream fout("File1.txt", ios::app);
  114.     for (int i = 0; i < n; i++) {
  115.         if (spisok[i].math >= 4 && spisok[i].informatics >= 4) {
  116.             fout << endl;
  117.             fout << spisok[i].surname << " ";
  118.             cout << spisok[i].surname << endl;
  119.             fout << spisok[i].name << " ";
  120.             cout << spisok[i].name << endl;
  121.             fout << spisok[i].patronymic << " ";
  122.             cout << spisok[i].patronymic << endl;
  123.             fout << spisok[i].number_group << " ";
  124.             cout << spisok[i].number_group << endl;
  125.             fout << spisok[i].birthYear << " ";
  126.             cout << spisok[i].birthYear << endl;
  127.             fout << spisok[i].physics << " ";
  128.             cout << spisok[i].physics << endl;
  129.             fout << spisok[i].math << " ";
  130.             cout << spisok[i].math << endl;
  131.             fout << spisok[i].informatics << " ";
  132.             cout << spisok[i].informatics << endl;
  133.             fout << spisok[i].chemistry << " ";
  134.             cout << spisok[i].chemistry << endl;
  135.             fout << spisok[i].gap;
  136.             cout << spisok[i].gap << endl;
  137.         }
  138.     }
  139. }
  140. void edit() {
  141.     system("cls");
  142.     cout << "Vvedite nomer studenta korogo nuzhno izmenit: ";
  143.     int num;
  144.     cin >> num;
  145.     num = num - 1;
  146.     ifstream fin("File.txt", ios::in);
  147.     n = 0;
  148.     while (!fin.eof()) {
  149.         fin >> spisok[n].name;
  150.         if (spisok[n].name == "") break;
  151.         fin >> spisok[n].surname;
  152.         fin >> spisok[n].patronymic;
  153.         fin >> spisok[n].number_group;
  154.         fin >> spisok[n].birthYear;
  155.         fin >> spisok[n].physics;
  156.         fin >> spisok[n].math;
  157.         fin >> spisok[n].informatics;
  158.         fin >> spisok[n].chemistry;
  159.         fin >> spisok[n].gap;
  160.         n++;
  161.     }
  162.     cout << "Viberite chto vam nyzhno izmenit: " << endl;
  163.     cout << "1 - Name" << endl;
  164.     cout << "2 - Surname" << endl;
  165.     cout << "3 - patronymic" << endl;
  166.     cout << "4 - nember_group" << endl;
  167.     cout << "5 - birthYear" << endl;
  168.     cout << "6 - physics" << endl;
  169.     cout << "7 - math" << endl;
  170.     cout << "8 - informatics" << endl;
  171.     cout << "9 - chemistry" << endl;
  172.     int kl = 0;
  173.     cin >> kl;
  174.     system("cls");
  175.     if (kl == 1) {
  176.         cout << "Vvedite imya: ";
  177.         string nam;
  178.         cin >> nam;
  179.         spisok[num].name = nam;
  180.     }
  181.     else
  182.         if (kl == 2) {
  183.             cout << "Vvedite famil: ";
  184.             string nam;
  185.             cin >> nam;
  186.             spisok[num].surname = nam;
  187.         }
  188.         else
  189.             if (kl == 3) {
  190.                 cout << "Vvedite otchestv: ";
  191.                 string nam;
  192.                 cin >> nam;
  193.                 spisok[num].patronymic = nam;
  194.             }
  195.             else
  196.                 if (kl == 4) {
  197.                     cout << "Vvedite nomer_group: ";
  198.                     int nam;
  199.                     cin >> nam;
  200.                     spisok[num].number_group = nam;
  201.                 }
  202.                 else
  203.                     if (kl == 5) {
  204.                         cout << "Vvedite data rozhdeniya: ";
  205.                         int nam;
  206.                         cin >> nam;
  207.                         spisok[num].birthYear = nam;
  208.                     }
  209.                     else
  210.                         if (kl == 6) {
  211.                             cout << "Vvedite ocenky po fizike: ";
  212.                             int nam;
  213.                             cin >> nam;
  214.                             spisok[num].physics = nam;
  215.                         }
  216.                         else
  217.                             if (kl == 7) {
  218.                                 cout << "Vvedite ocenky po mat: ";
  219.                                 int nam;
  220.                                 cin >> nam;
  221.                                 spisok[num].math = nam;
  222.                             }
  223.                             else
  224.                                 if (kl == 8) {
  225.                                     cout << "Vvedite ocenky po informat: ";
  226.                                     int nam;
  227.                                     cin >> nam;
  228.                                     spisok[num].informatics = nam;
  229.                                 }
  230.                                 else
  231.                                     if (kl == 9) {
  232.                                         cout << "Vvedite ocenky po himii: ";
  233.                                         int nam;
  234.                                         cin >> nam;
  235.                                         spisok[num].chemistry = nam;
  236.                                     }
  237.     ofstream fout("File.txt", ios::out);
  238.     for (int i = 0; i < n; i++) {
  239.         fout << spisok[i].name << " ";
  240.         fout << spisok[i].surname << " ";
  241.         fout << spisok[i].patronymic << " ";
  242.         fout << spisok[i].number_group << " ";
  243.         fout << spisok[i].birthYear << " ";
  244.         fout << spisok[i].physics << " ";
  245.         fout << spisok[i].math << " ";
  246.         fout << spisok[i].informatics << " ";
  247.         fout << spisok[i].chemistry << " ";
  248.         fout << spisok[i].gap << endl;
  249.     }
  250.     system("cls");
  251.     cout << "Izmenino!!!" << endl;
  252. }
  253.  
  254. bool isGood(Student &s)
  255. {
  256.     if (s.informatics > 4 && s.math > 4)
  257.         return true;
  258.     return false;
  259. }
  260.  
  261.  
  262. void showGood()
  263. {
  264.     ifstream fin("File.txt", ios::in);
  265.     string temp;
  266.     int t = 0;
  267.     double tt = 0;
  268.     while (!fin.eof()) {
  269.         fin >> temp;
  270.         if (temp == "") break;
  271.         student.name = temp;
  272.         fin >> temp;
  273.         student.surname = temp;
  274.         fin >> temp;
  275.         student.patronymic = temp;
  276.         fin >> t;
  277.         student.number_group = t;
  278.         fin >> t;
  279.         student.birthYear = t;
  280.         fin >> t;
  281.         student.physics = t;
  282.         fin >> t;
  283.         student.math = t;
  284.         fin >> t;
  285.         student.informatics = t;
  286.         fin >> t;
  287.         student.chemistry = t;
  288.         fin >> tt;
  289.         student.gap = tt;
  290.         temp = "";
  291.         t = 0;
  292.         tt = 0;
  293.         if (isGood(student))
  294.         {
  295.             cout << "Name : " << student.name << endl;
  296.             cout << "Surname : " << student.surname << endl;
  297.             cout << "Patronymic : " << student.patronymic << endl;
  298.             cout << "Group : " << student.number_group << endl;
  299.             cout << "Year of birth : " << student.birthYear << endl;
  300.             cout << "Physics : " << student.physics << endl;
  301.             cout << "Math : " << student.math << endl;
  302.             cout << "Informatics : " << student.informatics << endl;
  303.             cout << "Chemistry : " << student.chemistry << endl;
  304.             cout << "Middle mark : " << student.gap << endl;
  305.         }
  306.     }
  307. }
  308.  
  309.  
  310. int main()
  311. {
  312.     while (true)
  313.     {
  314.         system("cls");
  315.         int choise = 0;
  316.         menu();
  317.         cin >> choise;
  318.         switch (choise)
  319.         {
  320.         case 1: show(); break;
  321.         case 2: edit(); break;
  322.         case 3: add(); break;
  323.         case 4: individual(); break;
  324.         case 5: showGood(); break;
  325.         case 0: return 0;
  326.         default:"ERROR!";
  327.         }
  328.         system("pause");
  329.     }
  330. }
  331.  
  332. void menu()
  333. {
  334.     cout << "Enter , what do you want :" << endl;
  335.     cout << "1 - Show all data " << endl;
  336.     cout << "2 - Edit " << endl;
  337.     cout << "3 - Add " << endl;
  338.     cout << "4 - Individual task " << endl;
  339.     cout << "5 - Show good students" << endl;
  340.     cout << "0 - Exit" << endl;
  341. }
  342.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement