Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <list>
- #include <iomanip>
- using namespace std;
- class Request {
- string destination; // Пункт назначения
- int flightNumber{0}; // Номер рейса
- string name; // Фамилия, инициалы
- string date; // Желаемая дата вылета
- public:
- void setDestination(const string &_destination) { destination = _destination; }
- void setFlightNumber(int _flightNumber) { flightNumber = _flightNumber; }
- void setName(const string &_name) { name = _name; }
- void setDate(const string &_date) { date = _date; }
- int getFlightNumber() const { return flightNumber; }
- string getDate() const { return date; }
- void print(bool printHeader) const {
- if (printHeader)
- cout << setw(12) << "Пункт назнач." << '|' << setw(6) << "Рейс №" << '|' << setw(14) << "Фамилия"
- << '|' << setw(12) << "Дата вылета" << endl;
- cout << "-------------------------------------" << endl;
- cout << setw(12) << destination << '|' << setw(6) << flightNumber << '|' << setw(14) << name
- << '|' << setw(12) << date << endl;
- cout << "-------------------------------------" << endl;
- }
- };
- int scanInt() {
- int value;
- while (true) {
- cin >> value;
- if (cin.good())
- return value;
- cin.clear();
- cin.ignore(INTMAX_MAX, '\n');
- cout << "Ошибка! Должно быть введено число." << endl;
- }
- }
- void fillRequest(Request &request) {
- cin.clear();
- cin.ignore(INT_MAX, '\n');
- string destination, name, date;
- int flightNumber;
- cout << "Введите пункт назначения: ";
- getline (cin, destination);
- cout << "Введите фамилию и инициалы: ";
- getline (cin, name);
- cout << "Введите желаемую дату вылета: ";
- getline (cin, date);
- cout << "Введите номер полёта: ";
- flightNumber = scanInt();
- request.setDestination(destination);
- request.setName(name);
- request.setDate(date);
- request.setFlightNumber(flightNumber);
- }
- void filter(list<Request> const &requests) {
- cout << "Введите номер рейса: ";
- int flightNumber = scanInt();
- cout << "Введите дату вылета: ";
- string date;
- cin >> date;
- for (auto iterator = requests.begin(); iterator != requests.end(); iterator++) {
- if (iterator->getFlightNumber() == flightNumber && iterator->getDate() == date)
- iterator->print(iterator == requests.begin());
- }
- }
- int main() {
- setlocale(LC_ALL, "");
- list<Request> requests;
- while (true) {
- cout << "1) Добавить" << endl;
- cout << "2) Удалить" << endl;
- cout << "3) Поиск" << endl;
- cout << "4) Печать" << endl;
- cout << "5) Выход" << endl;
- int choice;
- cin >> choice;
- switch (choice) {
- case 1: {
- Request r;
- fillRequest(r);
- requests.push_back(r);
- }
- break;
- case 2:
- if (!requests.empty()) {
- requests.pop_back();
- cout << "Удалён последний элемент" << endl;
- }
- break;
- case 3:
- filter(requests);
- break;
- case 4:
- for (auto iterator = requests.begin(); iterator != requests.end(); iterator++)
- iterator->print(iterator == requests.begin());
- break;
- case 5:
- return 0;
- default:;
- }
- }
- }
Add Comment
Please, Sign In to add comment