Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
993
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. /*
  2. 1. Список товаров, имеющихся на складе, включает в себя наименование
  3. товара, количество единиц товара, цену единицы и дату поступления товара на
  4. склад. Вывести список товаров, хранящихся больше месяца и стоимость которых превышает 1 000 000 р.
  5. */
  6. #include<iostream>
  7. #include<stdio.h>
  8. #include<conio.h>
  9. #include<stdlib.h>
  10. #include<string.h>
  11. #include<windows.h>
  12.  
  13. using namespace std;
  14.  
  15. FILE*fl;
  16. struct Spis
  17. {
  18. char name[30];
  19. char kol[7];
  20. int cost;
  21. int day;
  22. int month;
  23. int year;
  24. } ;
  25.  
  26. Spis spis[30];
  27. char fname[20];
  28. int nspis=0;
  29. int menu();
  30. void nnf();
  31. void newf();
  32. void spisok();
  33. void opf();
  34. void resc();
  35. void resf(int i);
  36.  
  37. int main()
  38. {
  39. using namespace std;
  40.  
  41. while(true)
  42. {
  43. switch (menu())
  44. {
  45. case 1: nnf(); break;
  46. case 2: newf(); break;
  47. case 3: spisok(); break;
  48. case 4: opf(); break;
  49. case 5: resc(); break;
  50. case 6: return 0;
  51. default: cout << "Error! Write NUMBER 1 - 7!" << endl;
  52. }
  53. puts("nazmite clavishy for continues");
  54.  
  55. _getch();
  56. system("cls");
  57. }
  58. }
  59.  
  60. int menu()
  61. {
  62.  
  63. cout << "ВЫБЕРИТЕ:" << endl;
  64. cout << "1. Name of file" << endl;
  65. cout << "2. New file" << endl;
  66. cout << "3. Write spisok" << endl;
  67. cout << "4. Open file" << endl;
  68. cout << "5. Show result and write them in file" << endl;
  69. cout << "6. EXIT" << endl;
  70. int i;
  71. cin >> i;
  72. return i;
  73. }
  74.  
  75. void nnf()
  76. {
  77. cout << "Write name of file: " << endl;
  78. cin >> fname;
  79. }
  80.  
  81. void newf()
  82. {
  83. if ((fl = fopen(fname,"wb")) == NULL)
  84. {
  85. cout << "Error with creating" << endl;
  86. exit(1);
  87. }
  88. cout << "File created" << endl;
  89. fclose(fl);
  90. }
  91.  
  92. void spisok()
  93. {
  94. using namespace std;
  95. if ((fl=fopen(fname,"rb+"))==NULL)
  96. {
  97. cout << "Error with creating" << endl;
  98. exit(1);
  99. }
  100. cout << "Write number of product: " << endl;
  101. cin >> nspis;
  102.  
  103. for(int i=0; i<nspis; i++)
  104. {
  105. cout << "Name of product: ";
  106. cin >> spis[i].name;
  107. cout << "Kol_vo edinits of product: ";
  108. cin >> spis[i].kol;
  109. cout << "Cost of product: ";
  110. cin >> spis[i].cost;
  111. cout << "Year, when u get product: ";
  112. cin >> spis[i].year;
  113. cout << "Month, when u get product: ";
  114. cin >> spis[i].month;
  115. cout << "Day, when u get product: ";
  116. cin >> spis[i].day;
  117.  
  118. fwrite(&spis[i],sizeof(Spis),1,fl);
  119. }
  120. fclose(fl);
  121. }
  122.  
  123. void opf()
  124. {
  125. if ((fl=fopen(fname,"rb"))==NULL)
  126. {
  127. cout << "Error with creating " << endl;
  128. exit(1);
  129. }
  130. nspis=0; Spis std;
  131. while(true)
  132. {
  133. int nwrt=fread(&std, sizeof(Spis),1,fl);
  134. if(nwrt!=1) break;
  135. spis[nspis]=std;
  136. cout << spis[nspis].name << " " << spis[nspis].kol << " " << spis[nspis].cost << " " << spis[nspis].day << spis[nspis].month << spis[nspis].year << endl;
  137. nspis++;
  138. }
  139. fclose(fl);
  140. }
  141.  
  142. void resc()
  143. {
  144. int nyear, nmonth, nday;
  145. cout << "What year, month, day now?\n";
  146. cin >> nyear, nmonth, nday;
  147.  
  148. for(int i=0; i<nspis; i++)
  149. { if(spis[i].cost > 1000000) {
  150. if (nyear == spis[i].year)
  151. { if (((nmonth == spis[i].month) && (nday > spis[i].day)) || (nmonth > spis[i].month))
  152. {
  153. resf(i); // вызов функции для записи в файл
  154. cout << spis[i].name << endl;
  155. }
  156. }
  157.  
  158. else { if (nyear < spis[i].year) {cout << "ERROR!"; exit(1);}
  159. else { if ((nyear - spis[i].year)>=2) { cout << spis[i].name; resf(i); }
  160. else {if (nmonth < 12) {cout << spis[i].name; resf(i); }
  161. else { if (nday> spis[i].day) {cout << spis[i].name; resf(i); }
  162. }
  163. }
  164. }
  165. }
  166. }
  167. }
  168. }
  169.  
  170.  
  171. void resf(int number)
  172. {
  173. char namet[30];
  174. FILE*ft;
  175. ft=fopen("Vivod.txt","a");
  176.  
  177. char s[80];
  178. strcpy(s,spis[number].name);
  179. strcat(s,"\n");
  180. fputs(s,ft);
  181.  
  182. fclose(ft);
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement