Advertisement
Kentoo

Zh#!

Jan 21st, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.95 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <locale>
  5. #include <iomanip>
  6.  
  7. using namespace std;
  8.  
  9. struct book {
  10.     char nazi[255];
  11.     int gre;
  12.     int v;
  13.     double st;
  14. };
  15.  
  16. void main()
  17. {
  18.     setlocale(LC_ALL, "Russian");
  19.     char code;
  20.     cout << "Если вы хотите добавить предприятие, нажмите y" << endl;
  21.     cin >> code;
  22.     book a;
  23.     if (code == 'y') {
  24.         ofstream fout("input.txt", ios::app);
  25.         while (code == 'y') {
  26.             cout << endl;
  27.             cout << "Введите наименование предприятия" << endl;
  28.             cin >> a.nazi;
  29.             cout << "Введите годовой расход электроэнергии предприятия" << endl;
  30.             cin >> a.gre;
  31.             cout << "Введите объем выпуска товара предприятием" << endl;
  32.             cin >> a.v;
  33.             cout << "Введите себестоимость товара, выпускаемого предприятием" << endl;
  34.             cin >> a.st;
  35.             cout << endl;
  36.             fout << a.nazi << " " << a.gre << " " << a.v << " " << a.st << endl;
  37.             cout << "Если вы хотите добавить предприятие, нажмите y" << endl;
  38.             cin >> code;
  39.         }
  40.         fout.close();
  41.     }
  42.     ifstream fin("input.txt");
  43.     int d = 35;
  44.     double bb = INT64_MAX * 1.0;
  45.     double ud;
  46.     book b;
  47.     cout << setw(d) << "Наименование " << setw(d) << "Удельный расход энергии " << setw(d) << "Стоимость произведенной продукции" << endl;
  48.     while (!fin.eof()) {
  49.         fin >> a.nazi >> a.gre >> a.v >> a.st;
  50.         if (strcmp(a.nazi, "") != 0)
  51.             cout << setw(d - 1) << a.nazi << setw(d) << (a.gre * 1.0) / a.v << setw(d + 1) << a.v * a.st << endl;
  52.         ud = (a.gre * 1.0) / (a.v * a.v * a.st);
  53.         if (bb > ud) {
  54.             strcpy(b.nazi, a.nazi);
  55.             b.gre = a.gre;
  56.             b.v = a.v;
  57.             b.st = a.st;
  58.             bb = ud;
  59.         }
  60.     }
  61.     cout << "Лучшее предприятие - " << b.nazi << endl;
  62.     system("pause");
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement