Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Creatures.h"
- #include <iostream>
- #include <iomanip>
- void PrintChar(char c, int count)
- {
- for (int i(0); i < count; i++)
- printf("%c", c);
- printf("\n");
- }
- void InputCtgMenu(int from, int to, int* pTask)
- {
- setlocale(LC_ALL, "rus");
- if (!pTask)
- return;
- while (true)
- {
- std::cout << "Введите номер операции: [" << from << "-" << to << "]: ";
- std::cin >> *pTask;
- if (std::cin.good())
- {
- std::cin.ignore(100, '\n');
- if (from <= *pTask && *pTask <= to)
- break;
- std::cout << "Значения должны быть в диапазоне: [" << from << "-" << to << "]: " << std::endl;
- continue;
- }
- std::cin.clear();
- std::cout << "Вы ввели недопустимые символы." << std::endl;
- std::cin.ignore(100, '\n');
- }
- }
- bool Menu(int* pTask)
- {
- setlocale(LC_ALL, "rus");
- std::cout << "Меню программы" << std::endl;
- std::cout << "1. Вывести на экран список шедевров искусства" << std::endl;
- std::cout << "2. Добавить новый шедевр искусства" << std::endl;
- std::cout << "3. Удалить существующий шедерв искусства" << std::endl;
- std::cout << "0. Выход\n" << std::endl;
- InputCtgMenu(MENU_EXIT, MENU_DEL, pTask);
- return *pTask != MENU_EXIT;
- }
- void InsertList(List** begin, Creature* C)
- {
- List* Ins = new List;
- Ins->C = *C;
- List* End = new List;
- End = *begin;
- if (*begin == NULL)
- {
- Ins->next = NULL;
- *begin = Ins;
- End = *begin;
- return;
- }
- while (End->next != NULL)
- End = End->next;
- List* newList = new List;
- newList->C = *C;
- newList->next = NULL;
- End->next = newList;
- }
- void PrintList(List *L)
- {
- List *Print = L;
- PrintChar('-', 80);
- std::cout << "Год" << std::setw(15) << "Название" << std::setw(15) << "Автор" << std::setw(15) << "Музей" << std::endl;
- PrintChar('-', 80);
- while (Print)
- {
- std::cout << Print->C.year << std::setw(15) << Print->C.name << std::setw(15) << Print->C.author << std::setw(15) << Print->C.museum << std::endl;
- Print = Print->next;
- }
- PrintChar('-', 80);
- }
- void InputCreature(Creature* pCreature)
- {
- setlocale(LC_ALL, "rus");
- if (!pCreature)
- return;
- int year;
- std::cout << "Введите год: ";
- std::cin >> year;
- if (std::cin.good())
- pCreature->year = year;
- std::cin.clear();
- std::cout << "Введите автора: ";
- std::cin >> pCreature->author;
- std::cout << "Введите имя шедевра: ";
- std::cin >> pCreature->name;
- std::cout << "Введите музей: ";
- std::cin >> pCreature->museum;
- }
- void AddCreature(List** begin)
- {
- Creature temp;
- InputCreature(&temp);
- InsertList(begin, &temp);
- }
- void DeleteCreature(List** begin)
- {
- int key;
- std::cout << "Введите год шедевра, который хотите удалить: ";
- std::cin >> key;
- if (*begin == NULL)
- return;
- List* temp = *begin;
- if (temp->C.year == key)
- {
- *begin = temp->next;
- delete temp;
- return;
- }
- List* temp2 = temp->next;
- while (temp2)
- {
- if (temp2->C.year == key)
- {
- temp->next = temp2->next;
- delete temp2;
- return;
- }
- temp = temp2;
- temp2 = temp2->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement