Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- #include <locale>
- #include <iomanip>
- using namespace std;
- struct book {
- char nazi[255];
- int gre;
- int v;
- double st;
- };
- void main()
- {
- setlocale(LC_ALL, "Russian");
- char code;
- cout << "Если вы хотите добавить предприятие, нажмите y" << endl;
- cin >> code;
- book a;
- if (code == 'y') {
- ofstream fout("input.txt", ios::app);
- while (code == 'y') {
- cout << endl;
- cout << "Введите наименование предприятия" << endl;
- cin >> a.nazi;
- cout << "Введите годовой расход электроэнергии предприятия" << endl;
- cin >> a.gre;
- cout << "Введите объем выпуска товара предприятием" << endl;
- cin >> a.v;
- cout << "Введите себестоимость товара, выпускаемого предприятием" << endl;
- cin >> a.st;
- cout << endl;
- fout << a.nazi << " " << a.gre << " " << a.v << " " << a.st << endl;
- cout << "Если вы хотите добавить предприятие, нажмите y" << endl;
- cin >> code;
- }
- fout.close();
- }
- ifstream fin("input.txt");
- int d = 35;
- double bb = INT64_MAX * 1.0;
- double ud;
- book b;
- cout << setw(d) << "Наименование " << setw(d) << "Удельный расход энергии " << setw(d) << "Стоимость произведенной продукции" << endl;
- while (!fin.eof()) {
- fin >> a.nazi >> a.gre >> a.v >> a.st;
- if (strcmp(a.nazi, "") != 0)
- cout << setw(d - 1) << a.nazi << setw(d) << (a.gre * 1.0) / a.v << setw(d + 1) << a.v * a.st << endl;
- ud = (a.gre * 1.0) / (a.v * a.v * a.st);
- if (bb > ud) {
- strcpy(b.nazi, a.nazi);
- b.gre = a.gre;
- b.v = a.v;
- b.st = a.st;
- bb = ud;
- }
- }
- cout << "Лучшее предприятие - " << b.nazi << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement