Untitled
unknown
plain_text
a year ago
4.0 kB
2
Indexable
Never
#include <iostream> #include "windows.h" using namespace std; struct Watch { char Case; union { struct { char watchName[15], Model[9], dial[10]; } Retailer; struct { char watchName[15]; int NumId; } Stock; }; char Address[40]; int Length; }; Watch InpWatchInfo(char cs) { Watch watch; watch.Case = cs; if (watch.Case) { cout << "Производитель часов: "; cin >> watch.Stock.watchName; cout << "Номер: "; cin >> watch.Stock.NumId; } else { cout << "Производитель часов: "; cin >> watch.Retailer.watchName; cout << "Модель часов: "; cin >> watch.Retailer.Model; cout << "Цвет циферблата: "; cin >> watch.Retailer.dial; } cout << "Адрес: "; cin >> watch.Address; watch.Length = 0; return watch; } void OutWatchInfo(Watch watch) { if (watch.Case) { cout << watch.Stock.watchName << " | "; cout << watch.Stock.NumId; } else cout << watch.Retailer.watchName << " | " << watch.Retailer.Model << " | " << watch.Retailer.dial; cout << " | " << watch.Address << endl << "Длина: " << watch.Length << "зв." << endl; } Watch &AddLength(Watch &watch, int length) { watch.Length += length; return watch; } Watch *SubLength(Watch *watch, int length) { watch->Length -= length; return watch; } int main() { SetConsoleOutputCP(CP_UTF8); Watch DataBase[10], watch = {0, {"", "", 0}, "", 0}; int i, j; for (i = 0; i < sizeof(DataBase) / sizeof(Watch); i++) { DataBase[i] = watch; } while (1) { cout << " Меню СУБД:" << endl << "1. Ввод данных." << endl << "2. Вывод информации о товаре." << endl << "3. Вывод всей информации." << endl << "4. Увеличить длину браслета." << endl << "5. Уменьшить длину браслета." << endl << "6. Удалить данные." << endl << "7. Закончить работу." << endl << ">"; cin >> i; switch (i) { case 1: cout << "Номер: "; cin >> i; cout << "Вариант (0-магазин, 1-наличие в городе): "; cin >> j; DataBase[i] = InpWatchInfo(j); break; case 2: cout << "Номер: "; cin >> i; OutWatchInfo(DataBase[i]); break; case 3: for (i = 0; i < sizeof(DataBase) / sizeof(Watch); i++) if (DataBase[i].Address[0]) { cout << "Часы: " << i << ":" << endl; OutWatchInfo(DataBase[i]); } break; case 4: cout << "Номер: "; cin >> i; cout << "Длина: "; cin >> j; AddLength(DataBase[i], j); break; case 5: cout << "Номер: "; cin >> i; cout << "Насколько уменьшить длину: "; cin >> j; SubLength(DataBase + i, j); break; case 6: cout << "Номер: "; cin >> i; DataBase[i] = watch; break; case 7: return 0; default: cout << "Повторите ввод!" << endl; } } }