Advertisement
Guest User

ruslan228

a guest
Dec 12th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.91 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #include <stdio.h>
  4.  
  5. #include <stdlib.h>
  6.  
  7. #include <string.h>
  8.  
  9. #include <conio.h>
  10.  
  11.  
  12.  
  13. using namespace std;
  14.  
  15. FILE* f1;
  16.  
  17. typedef struct
  18.  
  19. {
  20.  
  21.     char imya[30];
  22.  
  23.     char familia[30];
  24.  
  25.     char otchestvo[30];
  26.  
  27.     char srball[30];
  28.  
  29.     int minzp;
  30.  
  31.  
  32.  
  33. } Tabitur;
  34.  
  35.  
  36.  
  37. Tabitur abitur[30];
  38.  
  39. char name[20];
  40.  
  41. int nst = 0;
  42.  
  43. int menu();
  44.  
  45. void nnf();
  46.  
  47. void newf();
  48.  
  49. void spisok();
  50.  
  51. void opf();
  52.  
  53. void resc();
  54.  
  55. void resf();
  56.  
  57.  
  58.  
  59. int main()
  60.  
  61. {
  62.  
  63.     while (true)
  64.  
  65.     {
  66.  
  67.         switch (menu())
  68.  
  69.         {
  70.  
  71.         case 1:nnf(); break;
  72.  
  73.         case 2:newf(); break;
  74.  
  75.         case 3:spisok(); break;
  76.  
  77.         case 4:opf(); break;
  78.  
  79.         case 5:resc(); break;
  80.  
  81.         case 6:resf(); break;
  82.  
  83.         case 7:return 0;
  84.  
  85.         default:"Vibrano ne pravilno !";
  86.  
  87.         }
  88.  
  89.         puts("Press any key to continue");
  90.  
  91.         getch();    system("cls");
  92.  
  93.     }
  94.  
  95. }
  96.  
  97. int menu()
  98.  
  99. {
  100.  
  101.     cout << "Viberite:" << endl;
  102.  
  103.     cout << "1.Vvod file name" << endl;
  104.  
  105.     cout << "2.New file" << endl;
  106.  
  107.     cout << "3.Vvesti spisok" << endl;
  108.  
  109.     cout << "4.Open file" << endl;
  110.  
  111.     cout << "5.Vivesti result" << endl;
  112.  
  113.     cout << "6.Vivesti v file" << endl;
  114.  
  115.     cout << "7.Exit" << endl;
  116.  
  117.     int i;
  118.  
  119.     cin >> i;
  120.  
  121.     return i;
  122.  
  123. }
  124.  
  125. void nnf()
  126.  
  127. {
  128.  
  129.     cout << "Vvedite file name" << endl;
  130.  
  131.     cin >> name;
  132.  
  133. }
  134.  
  135. void newf()
  136.  
  137. {
  138.  
  139.     if ((f1 = fopen(name, "wb")) == NULL)
  140.  
  141.     {
  142.  
  143.         cout << "Oshibka pri sozdanii" << endl;
  144.  
  145.         exit(1);
  146.  
  147.     }
  148.  
  149.     cout << "OK" << endl;
  150.  
  151.     fclose(f1);
  152.  
  153. }
  154.  
  155. void spisok()
  156.  
  157. {
  158.  
  159.     if ((f1 = fopen(name, "rb+")) == NULL)
  160.  
  161.     {
  162.  
  163.         cout << "Oshibka pri sozdanii" << endl;
  164.  
  165.         exit(1);
  166.  
  167.     }
  168.  
  169.     cout << "Vvedite chislo abiturientov" << endl;
  170.  
  171.     cin >> nst;
  172.  
  173.     for (int i = 0; i < nst; i++)
  174.  
  175.     {
  176.  
  177.         cout << "Vvedite imya:";
  178.  
  179.         cin >> abitur[i].imya;
  180.  
  181.         cout << "Vvedite familiu:";
  182.  
  183.         cin >> abitur[i].familia;
  184.  
  185.         cout << "Vvedite otchestvo:";
  186.  
  187.         cin >> abitur[i].otchestvo;
  188.  
  189.         cout << "Vvedite srball:";
  190.  
  191.         cin >> abitur[i].srball;
  192.  
  193.         cout << "Vvedite  minzp:";
  194.  
  195.         cin >> abitur[i].minzp;
  196.  
  197.         fwrite(&abitur[i], sizeof(Tabitur), 1, f1);
  198.  
  199.     }
  200.  
  201.     fclose(f1);
  202.  
  203. }
  204.  
  205. void opf()
  206.  
  207. {
  208.  
  209.     if ((f1 = fopen(name, "rb")) == NULL)
  210.  
  211.     {
  212.  
  213.         cout << "Oshibka pri otkritii" << endl;
  214.  
  215.         exit(1);
  216.  
  217.     }
  218.  
  219.     nst = 0; Tabitur std;
  220.  
  221.     while (true)
  222.  
  223.     {
  224.  
  225.         int nwrt = fread(&std, sizeof(Tabitur), 1, f1);
  226.  
  227.         if (nwrt != 1) break;
  228.  
  229.         abitur[nst] = std;
  230.  
  231.         cout << abitur[nst].imya << "" << abitur[nst].familia << "" << abitur[nst].otchestvo << "" << abitur[nst].srball << "" << abitur[nst].minzp << endl;
  232.  
  233.         nst++;
  234.  
  235.     }
  236.  
  237.     fclose(f1);
  238.  
  239. }
  240.  
  241. void resc()
  242.  
  243. {
  244.     int i;
  245.  
  246.     for (i = 0; i < nst; i++)
  247.  
  248.         if (abitur[i].minzp < 15000)
  249.  
  250.             cout << abitur[i].imya << "" << abitur[i].familia << "" << abitur[i].otchestvo << "" << abitur[i].srball << "" << abitur[i].minzp << endl;
  251.  
  252. }
  253.  
  254. void resf()
  255.  
  256. {
  257.  
  258.     char namet[30];
  259.  
  260.     FILE* f1;
  261.  
  262.     cout << "Vvedite imya file" << endl;
  263.  
  264.     cin >> namet;
  265.  
  266.     if ((f1 = fopen(namet, "w")) == NULL)
  267.  
  268.     {
  269.  
  270.         cout << "Oshibka pri sozdanii" << endl;
  271.  
  272.         exit(1);
  273.  
  274.     }
  275.  
  276.     char s[80];
  277.  
  278.     for (int i = 0; i < nst; i++)
  279.  
  280.         if (abitur[i].minzp < 15000)
  281.  
  282.         {
  283.  
  284.             strcpy(s, abitur[i].imya);
  285.  
  286.             strcat(s, "");
  287.  
  288.             fputs(s, f1);
  289.  
  290.             strcpy(s, abitur[i].familia);
  291.  
  292.             strcat(s, "");
  293.  
  294.             fputs(s, f1);
  295.  
  296.             strcpy(s, abitur[i].otchestvo);
  297.  
  298.             strcat(s, "");
  299.  
  300.             fputs(s, f1);
  301.  
  302.             strcpy(s, abitur[i].srball);
  303.  
  304.             strcat(s, "");
  305.  
  306.             fputs(s, f1);
  307.  
  308.         }
  309.  
  310.     fclose(f1);
  311.  
  312. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement