Advertisement
Kentoo

V#3

Jan 16th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.50 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <locale>
  5.  
  6. using namespace std;
  7.  
  8. struct order {
  9.     int id;
  10.     int art;
  11.     char description[256];
  12.     int kol;
  13.     int price;
  14.     char name[32];
  15. };
  16.  
  17. void main()
  18. {
  19.     setlocale(LC_ALL, "Russian");
  20.     order a;
  21.     char code;
  22.     cout << "Добавить заказ? y - да, любой другой символ - нет" << endl;
  23.     cin >> code;
  24.     if (code == 'y' || code == 'у') {
  25.         ofstream fout("input.txt", ios::app);
  26.         while (code == 'y' || code == 'у') {
  27.             cout << endl;
  28.             cout << "Введите id заказа" << endl;
  29.             cin >> a.id;
  30.             cout << "Введите артикул заказа" << endl;
  31.             cin >> a.art;
  32.             cout << "Введите описание заказа" << endl;
  33.             cin >> a.description;
  34.             cout << "Введите количество товара в заказе" << endl;
  35.             cin >> a.kol;
  36.             cout << "Введите суммарную стоимость заказа" << endl;
  37.             cin >> a.price;
  38.             cout << "Введите имя заказчика" << endl;
  39.             cin >> a.name;
  40.             fout << a.id << " " << a.art << " " << a.description << " " << a.kol << " " << a.price << " " << a.name << endl;
  41.             cout << endl;
  42.             cout << "Добавить заказ? y - да, любой другой символ - нет" << endl;
  43.             cin >> code;
  44.         }
  45.         fout.close();
  46.     }
  47.     ifstream fin("input.txt");
  48.     int n = 0;
  49.     order am[64];
  50.     while (!fin.eof()) {
  51.         fin >> am[n].id >> am[n].art >> am[n].description >> am[n].kol >> am[n].price >> am[n].name;
  52.         n++;
  53.     }
  54.     n--;
  55.     fin.close();
  56.     ofstream fout2("output.txt");
  57.     if (n > 1) {
  58.         int j = -1;
  59.         bool flag = true;
  60.         while (flag) {
  61.             flag = false;
  62.             for (int i = j + 1; i < n; i++) {
  63.                 if (am[i].id != -1) {
  64.                     a = am[i];
  65.                     j = i;
  66.                     am[i].id = -1;
  67.                     flag = true;
  68.                     break;
  69.                 }
  70.             }
  71.             if (flag) {
  72.                 for (int i = j + 1; i < n; i++) {
  73.                     if (a.id == am[i].id && strcmp(a.name, am[i].name) == 0) {
  74.                         am[i].id = -1;
  75.                         a.kol += am[i].kol;
  76.                         a.price += am[i].price;
  77.                         string s1 = a.description;
  78.                         string s2 = am[i].description;
  79.                         string s3 = s1 + ',' + s2;
  80.                         strcpy(a.description, s3.c_str());
  81.                     }
  82.                 }
  83.                 fout2 << a.id << " " << a.art << " " << a.description << " " << a.kol << " " << a.price << " " << a.name << " " << endl;
  84.             }
  85.         }
  86.     }
  87.     else {
  88.         fout2 << am[0].id << " " << am[0].art << " " << am[0].description << " " << am[0].kol << " " << am[0].price << " " << am[0].name << " " << endl;
  89.     }
  90.     system("pause");
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement