Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.14 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <locale.h>
  4. #include <conio.h>
  5. #include <string.h>
  6. struct instrument
  7. {
  8. char name[20];
  9. float price;
  10. int grt_period_day;
  11. };
  12. struct zamov
  13. {
  14. char name[40];
  15. char adress[40];
  16. int kolvo;
  17. };
  18. struct measurement
  19. {
  20. int array[20];
  21. char veli[15];
  22. float top[20];
  23. float lower[20];
  24. float delta[20];
  25. };
  26.  
  27. int main()
  28. {
  29. int a=20,j,i;
  30. int k=0;
  31. struct instrument inst[a];
  32. struct zamov zm[a];
  33. struct measurement mst[a];
  34. setlocale(LC_ALL,"rus");
  35. FILE *input=NULL;
  36. do
  37. {
  38. k=0;
  39. printf("Кол-во инструментов: ");
  40. scanf("%d",&a);
  41. if(a<1)
  42. {
  43. printf("Минимальное значения для данного параметра - 1\n");
  44. k=1;
  45. }
  46. }
  47. while(k!=0);
  48. for(i=0;i<a;i++)
  49. {
  50. printf("Название: ");
  51. scanf("%s",inst[i].name);
  52. //gets(inst[i].name);
  53. do
  54. {
  55. k=0;
  56. printf("Цена: ");
  57. scanf("%f",&inst[i].price);
  58. if(inst[i].price<10)
  59. {
  60. printf("Введите цену побольше!\n");
  61. k=1;
  62. }
  63. }
  64. while(k!=0);
  65.  
  66. do
  67. {
  68. k=0;
  69. printf("Гарантичный срок (дней): ");
  70. scanf("%d",&inst[i].grt_period_day);
  71. if(inst[i].grt_period_day<29)
  72. {
  73. printf("Гарантийный строк должен быть не менее 30 дней!\n");
  74. k=1;
  75. }
  76. }
  77. while(k!=0);
  78. printf("ФИО заказчика: ");
  79. scanf("%s",zm[i].name);
  80. printf("Адрес: ");
  81. scanf("%s",zm[i].adress);
  82. do
  83. {
  84. printf("Колво товаров: ");
  85. k=0;
  86. scanf("%d",&zm[i].kolvo);
  87. }
  88.  
  89. while(k!=0);
  90. do
  91. {
  92. k=0;
  93. printf("Сколько велечин измеряет инструмент?\n@: ");
  94. scanf("%d",&mst[i].array[i]);
  95. if(mst[i].array[i]<1)
  96. {
  97. printf("Минимальное значения для данного параметра - 1\n");
  98. k=1;
  99. }
  100. }
  101. while(k!=0);
  102. for(j=0;j<mst[i].array[i];j++)
  103. {
  104. printf("Велечина: ");
  105. scanf("%s",&mst[i].veli[j]);
  106. printf("Нижняя грань: ");
  107. scanf("%f",&mst[i].lower[j]);
  108. do
  109. {
  110. k=0;
  111. printf("Верхняя грань: ");
  112. scanf("%f",&mst[i].top[j]);
  113. if(mst[i].top[j]<mst[i].lower[j]+10)
  114. {
  115. printf("Введите значения побольше!\n");
  116. k=1;
  117. }
  118. }
  119. while(k!=0);
  120. do
  121. {
  122. k=0;
  123. printf("Погрешность: ");
  124. scanf("%f",&mst[i].delta[j]);
  125. if(mst[i].delta[j]<0)
  126. {
  127. printf("Погрешность не может быть ниже 0\n");
  128. k=1;
  129. }
  130. }
  131. while(k!=0);
  132. puts(" ");
  133. }
  134. }
  135.  
  136.  
  137.  
  138. input=fopen("1input","wb");
  139. if (input == NULL)
  140. {
  141. printf("Ошибка при открытии файла");
  142. return 0;
  143. }
  144.  
  145. fwrite(&inst, sizeof(struct instrument), a, input);
  146. fclose(input);
  147. input = fopen("1input", "rb");
  148. if (input == NULL)
  149. {
  150. printf("Ошибка при открытии файла");
  151. return 0;
  152. }
  153. fread(&inst, sizeof(struct instrument), a, input);
  154.  
  155. input=fopen("2input","wb");
  156. if (input == NULL)
  157. {
  158. printf("Ошибка при открытии файла");
  159. return 0;
  160. }
  161.  
  162. fwrite(&inst, sizeof(struct zamov), a, input);
  163. fclose(input);
  164. input = fopen("2input", "rb");
  165. if (input == NULL)
  166. {
  167. printf("Ошибка при открытии файла");
  168. return 0;
  169. }
  170. fread(&inst, sizeof(struct zamov), a, input);
  171.  
  172. input=fopen("3input","wb");
  173. if (input == NULL)
  174. {
  175. printf("Ошибка при открытии файла");
  176. return 0;
  177. }
  178.  
  179. fwrite(&inst, sizeof(struct measurement), a, input);
  180. fclose(input);
  181. input = fopen("3input", "rb");
  182. if (input == NULL)
  183. {
  184. printf("Ошибка при открытии файла");
  185. return 0;
  186. }
  187. fread(&inst, sizeof(struct measurement), a, input);
  188.  
  189. float delt;
  190. do
  191. {
  192. k=0;
  193. printf("Погрешность: ");
  194. scanf("%f",&delt);
  195. if(delt<0)
  196. {
  197. printf("Введите значения побольше!\n");
  198. k=1;
  199. }
  200. }
  201. while(k!=0);
  202. int h=1;
  203. for(i=0;i<a;i++)
  204. {
  205. k=0;
  206. for(j=0;j<mst[i].array[i];j++)
  207. {
  208. if(delt>=mst[i].delta[j])
  209. {
  210. if(k==0)
  211. {
  212. printf("\n%d) %s\n",h,zm[i].name);
  213. h++;
  214. k=1;
  215. }
  216. }
  217. }
  218. }
  219. fclose(input);
  220. return 0;
  221.  
  222. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement