Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- #include <locale>
- using namespace std;
- struct order {
- int id;
- int art;
- char description[256];
- int kol;
- int price;
- char name[32];
- };
- void main()
- {
- setlocale(LC_ALL, "Russian");
- order a;
- char code;
- cout << "Добавить заказ? y - да, любой другой символ - нет" << endl;
- cin >> code;
- if (code == 'y' || code == 'у') {
- ofstream fout("input.txt", ios::app);
- while (code == 'y' || code == 'у') {
- cout << endl;
- cout << "Введите id заказа" << endl;
- cin >> a.id;
- cout << "Введите артикул заказа" << endl;
- cin >> a.art;
- cout << "Введите описание заказа" << endl;
- cin >> a.description;
- cout << "Введите количество товара в заказе" << endl;
- cin >> a.kol;
- cout << "Введите суммарную стоимость заказа" << endl;
- cin >> a.price;
- cout << "Введите имя заказчика" << endl;
- cin >> a.name;
- fout << a.id << " " << a.art << " " << a.description << " " << a.kol << " " << a.price << " " << a.name << endl;
- cout << endl;
- cout << "Добавить заказ? y - да, любой другой символ - нет" << endl;
- cin >> code;
- }
- fout.close();
- }
- ifstream fin("input.txt");
- int n = 0;
- order am[64];
- while (!fin.eof()) {
- fin >> am[n].id >> am[n].art >> am[n].description >> am[n].kol >> am[n].price >> am[n].name;
- n++;
- }
- n--;
- fin.close();
- ofstream fout2("output.txt");
- if (n > 1) {
- int j = -1;
- bool flag = true;
- while (flag) {
- flag = false;
- for (int i = j + 1; i < n; i++) {
- if (am[i].id != -1) {
- a = am[i];
- j = i;
- am[i].id = -1;
- flag = true;
- break;
- }
- }
- if (flag) {
- for (int i = j + 1; i < n; i++) {
- if (a.id == am[i].id && strcmp(a.name, am[i].name) == 0) {
- am[i].id = -1;
- a.kol += am[i].kol;
- a.price += am[i].price;
- string s1 = a.description;
- string s2 = am[i].description;
- string s3 = s1 + ',' + s2;
- strcpy(a.description, s3.c_str());
- }
- }
- fout2 << a.id << " " << a.art << " " << a.description << " " << a.kol << " " << a.price << " " << a.name << " " << endl;
- }
- }
- }
- else {
- fout2 << am[0].id << " " << am[0].art << " " << am[0].description << " " << am[0].kol << " " << am[0].price << " " << am[0].name << " " << endl;
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement