Tvor0zhok

Структуры II

Dec 8th, 2020 (edited)
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <string>
  5. #include <limits>
  6. using namespace std;
  7.  
  8. //открываем глобальные файловые потоки
  9. ifstream in("input.txt");
  10. ofstream out("output.txt");
  11.  
  12. struct vedomost
  13. {
  14. int price, amount;
  15. string vid, sort;
  16. void print(float x); //член-функция для вывода информации в файл
  17. };
  18.  
  19. void vedomost::print(float x)
  20. {
  21. out << setw(10) << vid << setw(10) << x*(float)price << setw(10) << sort << setw(10) << amount << endl;
  22. }
  23.  
  24. int main()
  25. {
  26. int n; cout << "Введите число наименований (продуктов): "; cin >> n;
  27. vedomost* product = new vedomost[n];
  28.  
  29. float x;
  30. cout << "Стоимость каждого вида продукции увеличена на (процентов): ";
  31. cin >> x;
  32.  
  33. x /= 100; x += 1;
  34.  
  35. n = 0; //значение n больше не нужно, воспользуемся этой переменной для нумерации элементов массива
  36.  
  37. while (in.peek() != EOF)
  38. {
  39. in >> product[n].vid;
  40. in >> product[n].price;
  41. in >> product[n].sort;
  42. in >> product[n].amount;
  43. product[n].print(x);
  44. ++n;
  45. }
  46.  
  47. in.close();
  48. out.close();
  49. delete[] product;
  50. return 0;
  51. }
Add Comment
Please, Sign In to add comment