Advertisement
Kentoo

E#5

Jan 16th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <fstream>
  5. #include <locale>
  6.  
  7. using namespace std;
  8.  
  9. struct prod {
  10.     char shifr[16];
  11.     char name[16];
  12.     char izm[16];
  13.     int plan;
  14.     int res;
  15. };
  16.  
  17. void main()
  18. {
  19.     setlocale(LC_ALL, "Russian");
  20.     ofstream fout("f.dat", ios::binary | ios::out);
  21.     char code;
  22.     cout << "Ввести продукцию? y - да, любой другой символ - нет" << endl;
  23.     cin >> code;
  24.     prod a;
  25.     while (code == 'y' || code == 'у') {
  26.         cout << endl;
  27.         cout << "Введите шифр продукции" << endl;
  28.         cin >> a.shifr;
  29.         cout << "Введите наименование продукции" << endl;
  30.         cin >> a.name;
  31.         cout << "Введите единицу измерения продукции" << endl;
  32.         cin >> a.izm;
  33.         cout << "Введите план выпуска продукции" << endl;
  34.         cin >> a.plan;
  35.         cout << "Введите фактический выпуск продукции" << endl;
  36.         cin >> a.res;
  37.         fout.write((char*)&a, sizeof a);
  38.         cout << endl;
  39.         cout << "Ввести продукцию? y - да, любой другой символ - нет" << endl;
  40.         cin >> code;
  41.     }
  42.     fout.close();
  43.     ifstream fin("f.dat", ios::binary | ios::in);
  44.     cout << endl;
  45.     cout << setw(16) << "Шифр" << " "
  46.         << setw(16) << "Наименование" << " "
  47.         << setw(16) << "Ед. измерения" << " "
  48.         << setw(16) << "План" << " "
  49.         << setw(16) << "Выпуск" << " "
  50.         << setw(16) << "Недовыполнение" << endl;
  51.     while (fin.read((char*)&a, sizeof prod)) {
  52.         if (a.res < a.plan) {
  53.             cout << setw(16) << a.shifr << " "
  54.                 << setw(16) << a.name << " "
  55.                 << setw(16) << a.izm << " "
  56.                 << setw(16) << a.plan << " "
  57.                 << setw(16) << a.res << " "
  58.                 << setw(15) << (((a.plan - a.res) * 1.0) / (a.plan)) * 100 << "%" << endl;
  59.         }
  60.     }
  61.     fin.close();
  62.     system("pause");
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement