Advertisement
Guest User

Untitled

a guest
May 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.06 KB | None | 0 0
  1. //#praga once
  2.  
  3. struct tek{
  4.     double cena;
  5.     char vid[size];
  6.     int kol;
  7.     char name[size];
  8.     int kod;
  9.     int index_magazin;
  10. };
  11. struct tek tech[size];
  12. int techSize=0;
  13.  
  14. void chitatTechniku(){
  15.     FILE *file;
  16.     file=fopen("tech", "rb");
  17.     fread(&techSize,sizeof(techSize),1,file);
  18.     fread(tech,sizeof(struct tek),techSize,file);
  19.     fclose(file);
  20. }
  21. void pisatTechniku(){
  22.     FILE *file;
  23.     file=fopen("tech", "w+b");
  24.     fwrite(&techSize,sizeof(techSize),1,file);
  25.     fwrite(tech,sizeof(struct tek),techSize,file);
  26.     fclose(file);
  27. }
  28.  
  29. void dobavitTechniku();
  30. void izmenitTechniku();
  31. void udalitTechniku();
  32. void vivestiTechniku();
  33. void sortirovatTechniku();
  34.  
  35. void menuTechniki(){
  36.     while (1){
  37.         cls;
  38.         printf("1 - Добавить\n");
  39.         printf("2 - Изменить\n");
  40.         printf("3 - Удалить\n");
  41.         printf("4 - Вывести\n");
  42.         printf("5 - Отсортировать\n");
  43.         printf("6 - Назад\n");
  44.         switch (_getch()){
  45.             case '1':
  46.                 dobavitTechniku();
  47.                 break;
  48.             case '2':
  49.                 izmenitTechniku();
  50.                 break;
  51.             case '3':
  52.                 udalitTechniku();
  53.                 break;
  54.             case '4':
  55.                 vivestiTechniku();
  56.                 break;
  57.             case '5':
  58.                 sortirovatTechniku();
  59.                 break;
  60.             case '6':
  61.                 return;
  62.             default:
  63.                 break;
  64.         }
  65.     }
  66. }
  67.  
  68. void dobavitTechniku(){
  69.     vivestiMagazin();
  70.     int nomer;
  71.     printf("Номер магазина\n");
  72.     scanf("%d", &nomer);
  73.     nomer--;
  74.     if (nomer>magazinSize || nomer<0){
  75.         printf("Ошибка\n");
  76.         pause;
  77.         return;
  78.     }
  79.     tech[techSize].index_magazin=magazin[nomer].index_magazin;
  80.     printf("Название\n");
  81.     fflush(stdin);
  82.     gets(tech[techSize].name);
  83.     printf("Вид\n");
  84.     fflush(stdin);
  85.     gets(tech[techSize].vid);
  86.     printf("Цена\n");
  87.     fflush(stdin);
  88.     scanf("%lf", &tech[techSize].cena);
  89.     printf("Количество\n");
  90.     fflush(stdin);
  91.     scanf("%d", &tech[techSize].kol);
  92.     printf("Код\n");
  93.     fflush(stdin);
  94.     scanf("%d", &tech[techSize].kod);
  95.     techSize++;
  96.     pisatTechniku();
  97. }
  98.  
  99. void izmenitTechniku(){
  100.     vivestiTechniku();
  101.     int nomer;
  102.     printf("Номер техники\n");
  103.     scanf("%d", &nomer);
  104.     nomer--;
  105.     if (nomer>techSize || nomer<0){
  106.         printf("Ошибка\n");
  107.         pause;
  108.         return;
  109.     }
  110.     while (1){
  111.         cls;
  112.         printf("1 - Название\n");
  113.         printf("2 - Вид\n");
  114.         printf("3 - Цена\n");
  115.         printf("4 - Количество\n");
  116.         printf("5 - Код\n");
  117.         printf("6 - Выход\n");
  118.         switch (_getch()){
  119.             case '1':
  120.                 printf("Введите новое название\n");
  121.                 fflush(stdin);
  122.                 gets(tech[nomer].name);
  123.                 break;
  124.             case '2':
  125.                 printf("Введите новый вид\n");
  126.                 fflush(stdin);
  127.                 gets(tech[nomer].vid);
  128.                 break;
  129.             case '3':
  130.                 printf("Введите новую цену\n");
  131.                 fflush(stdin);
  132.                 scanf("%lf", &tech[nomer].cena);
  133.                 break;
  134.             case '4':
  135.                 printf("Введите новое количество\n");
  136.                 fflush(stdin);
  137.                 scanf("%d", &tech[nomer].kol);
  138.                 break;
  139.             case '5':
  140.                 printf("Введите новый код\n");
  141.                 fflush(stdin);
  142.                 scanf("%d", &tech[nomer].kod);
  143.                 break;
  144.             case '6':
  145.                 pisatTechniku();
  146.                 return;
  147.             default:
  148.                 break;
  149.         }
  150.     }
  151. }
  152.  
  153. void udalitTechniku(){
  154.     vivestiTechniku();
  155.     int nomer;
  156.     printf("Номер техники\n");
  157.     scanf("%d", &nomer);
  158.     nomer--;
  159.     if (nomer>techSize || nomer<0){
  160.         printf("Ошибка\n");
  161.         pause;
  162.         return;
  163.     }
  164.     int i;
  165.     techSize--;
  166.     for (i=nomer;i<techSize;i++){
  167.         tech[i]=tech[i+1];
  168.     }
  169.     pisatTechniku();
  170. }
  171.  
  172. void vivestiTechniku(){
  173.     cls;
  174.     printf("_____________________________________________________________________________\n");
  175.     printf("|#    |Название            |Вид            |Цена      |Количество|Код       |\n");
  176.     printf("|_____|____________________|_______________|__________|__________|__________|\n");
  177.     int i;
  178.     char str[size];
  179.     for (i=0;i<techSize;i++){
  180.         sprintf(str,"%d", i+1);
  181.         printf("|%5s|", str);
  182.         printf("%20s|", tech[i].name);
  183.         printf("%20s|", tech[i].vid);
  184.         sprintf(str,"%lf", tech[i].cena);
  185.         printf("%10s|", str);
  186.         sprintf(str,"%d", tech[i].kol);
  187.         printf("%10s|", str);
  188.         sprintf(str,"%d", tech[i].kod);
  189.         printf("%10s|", str);
  190.         printf("|_____|____________________|_______________|__________|__________|__________|\n");
  191.     }
  192.     pause;
  193. }
  194.  
  195. void sortirovatTechniku(){
  196.     cls;
  197.    
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement