Модуль 2 / M2L3
.docx#include <iostream>
#include <iomanip>
using namespace std;
int main() {
setlocale(LC_ALL, "russian");
struct goods
{
int number;
char *name;
char* min_descript;
double price;
char* date;
} gds[5];
gds[0] = { 1, "Хлебушек", "Вкусный, домашний", 7.90, "годен до 24.02.16" };
gds[1] = { 2, "Гелевая ручка", "Обычная, бесммысленная", 1.20, "~" };
gds[2] = { 3, "Сыр Бельгийский", "Замечательный", 17.88, "годен до 11.02.16" };
gds[3] = { 4, "Молоко Домашнее", "Свежее", 18.55, "годно до 12.01.16" };
gds[4] = { 5, "Колбаса Колбико", "Докторская", 22.30, "годна до 22.03.16" };
cout << "\t----------------------------------------------------------------------------" << endl;
cout << "\t| Продовольчий магазин \"Антониус\" |" << endl;
cout << "\t----------------------------------------------------------------------------" << endl;
cout << "\t----------------------------------------------------------------------------" << endl;
cout << "\t|№ Товара | Наименование | Описание | Цена | Срок годности |" << endl;
for (int i = 0; i < 5; i++) {
cout << "\t----------------------------------------------------------------------------" << endl;
cout << "\t|" << setw(9) << gds[i].number << "|"
<< setw(16) << gds[i].name << "|"
<< setw(22) << gds[i].min_descript << "|"
<< setw(6) << gds[i].price << "|"
<< setw(17) << gds[i].date << "|" << endl;
}
cout << "\t----------------------------------------------------------------------------" << endl;
S:
cout << "\t Выберите один из нижеперечисленных опций:" << endl;
cout << "\t Самый дорогой продукт - нажать 1" << endl;
cout << "\t Для самого дешевого продукта - 2" << endl;
cout << "\t Для выхода - 3" << endl;
int m;
cin >> m;
double comp;
int p;
if (m == 1) {
double comp = 0;
int p = 0;
comp = gds[0].price;
for (int i = 0;i < 5;i++) {
if (gds[i].price >= comp) {
comp = gds[i].price;
p = i;
}
}
cout << "\t Самый дорогой продукт = " << gds[p].name << endl << endl;
goto S;
}
if (m == 2) {
double comp = 0;
int p = 0;
comp = gds[0].price;
for (int i = 0;i < 5;i++) {
if (gds[i].price <= comp) {
comp = gds[i].price;
p = i;
}
}
cout << "\t Самый дешевый продукт = " << gds[p].name << endl << endl;
goto S;
}
if (m == 3) {
cout << "\t Спасибо за использование нашей системы структуризации информации." << endl;;
goto F;
}
F:
system("pause");
return 0;
}