
5,13,21,29 |
Создать структуру для электронного ценника (товар, цена, секция магазина). Ввести с клавиатуры данные о нескольких ценниках. Создать дин. массив товаров заданной секции (создать дин.массив результата, секцию ввести с клавиатуры). В новом массиве подсчитать общую сумму товаров одной секции. Все результаты выводить на экран. |
#include <iostream>
#include <clocale>
#include <time.h>
#include <string>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;
int main()
{
setlocale(LC_ALL, "RUS");
printf("Подсчет количества слов, букв в введённом тексте, разбивка текста на страницы с определенными параметрами.%c", '\n');
struct tag
{
vector<char> product;
float price;
vector<char> section;
};
vector<tag> tags;
while(true)
{
tag temp_tag;
string input_string;
fseek(stdin, 0, SEEK_END);
printf("Введите название товара на ценнике: ");
do
{
char inp_char;
if (scanf("%c", &inp_char) != 1)
{
while (getchar() != '\n');
printf("Ошибка при вводе названия.%cВведите его снова:\n", '\n');
continue;
}
input_string += inp_char;
} while (input_string [input_string.length() - 1] != '\n');
for (int i = 0; i < input_string.length(); i++)
{
temp_tag.product.push_back(input_string[i]);
//printf("%c", temp_tag.product.data()[i]);
}
printf("Введите цену товара: ");
float input;
do
{
input = -1;
if (scanf("%f", &input) != 1)
{
printf("Ошибка при вводе цены. Введите цену снова: ");
while (getchar() != '\n');
continue;
}
if (input < 0)
{
printf("Цена не может быть отрицательной. Введите цену снова: ");
while (getchar() != '\n');
continue;
}
} while (input < 0);
temp_tag.price = input;
input_string.clear();
fseek(stdin, 0, SEEK_END);
printf("Введите название отдела, в котором расположен товар: ");
do
{
char inp_char;
if (scanf("%c", &inp_char) != 1)
{
while (getchar() != '\n');
printf("Ошибка при вводе названия. Введите его снова:\n");
continue;
}
input_string += inp_char;
} while (input_string[input_string.length() - 1] != '\n');
for (int i = 0; i < input_string.length(); i++)
{
temp_tag.section.push_back(input_string[i]);
//printf("%c", temp_tag.section.data()[i]);
}
tags.push_back(temp_tag);
fseek(stdin, 0, SEEK_END);
printf("Введите 1, если хотите выйти. Введите любое другое число, если хотите ввести еще один товар: ");
int leave = -1;
input = -1;
while(true)
{
if (scanf("%f", &input) != 1)
{
printf("Ошибка при вводе. Повторите ввод: ");
while (getchar() != '\n');
continue;
}
if (input == 1) leave = 1;
break;
}
if (leave == 1)break;
}
string input_string;
fseek(stdin, 0, SEEK_END);
printf("Введите название отдела, товары из которого нужно вывести и подсчитать стоимость: ");
while (1)
{
do
{
char inp_char;
if (scanf("%c", &inp_char) != 1)
{
while (getchar() != '\n');
printf("Ошибка при вводе названия.%cВведите его снова:\n", '\n');
continue;
}
input_string += inp_char;
} while (input_string[input_string.length() - 1] != '\n');
vector<int> tags_id;
for (int i = 0; i < tags.size(); i++)
{
for(int j = 0; j < tags.data()[i].section.size(); i++)
{
if (tags[i].section.data()[j] == input_string[j]) tags_id.push_back(i);
}
//printf("%c", temp_tag.section.data()[i]);
}
tag* count_tag = new tag[tags_id.size()];
float summ = 0;
for(int i = 0; i < tags_id.size(); i++)
{
printf("Название: ");
for (int j = 0; j < tags.data()[i].product.size(); j++)
{
printf("%c", tags.data()[i].product.data()[j]);
}
printf(" Цена: %f Отдел магазина: ", tags.data()[i].price);
for (int j = 0; j < tags.data()[i].section.size(); j++)
{
printf("%c", tags.data()[i].section.data()[j]);
}
count_tag[i] = tags.data()[tags_id.data()[i]];
summ += tags.data()[i].price;
}
printf("\nСумма: %f", summ);
return 0;
}
return 0;
}