Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

В2_4

.cpp
Скачиваний:
10
Добавлен:
01.02.2019
Размер:
10.52 Кб
Скачать
#include <iostream>
#include <stdio.h>
#include <cstdlib>

using namespace std;

#define MAX_FLIGHTS 16

const char name_days[][3] = { "Пн", "Вт", "Ср", "Чт", "Пт", "Сб", "Вс" };
const char airplane_types[][32] = { "Узкофюзеляжный", "Широкофюзеляжный", "Местный", "Региональный" };

class Aeroflot {
	char * destination;     // Пункт назначения
	short type_airplane;    // Тип самолёта
	short flight_number;    // Номер рейса
	short hh, mm;           // Время вылета (часы, минуты)
	short days[7];          // Дни недели
public:
	void add(int id) {
		flight_number = id;
		cout << "Пункт назначения" << endl << "ENTER: ";
		destination = new char;
		cin.getline(destination, 24);
		system("cls");
		cout << "Тип самолёта" << endl << "0 - узкофюзеляжный | 1 - широкофюзеляжный" << endl << "2 - местный | 3 - региональный" << endl << "ENTER: ";
		cin >> type_airplane;
		system("cls");
		cout << "Дни недели (0 - нет | 1 - да)" << endl;
		for (int i = 0; i < 7;) {
			cout << name_days[i] << ": ";
			cin >> days[i];
			if (days[i] > 1) 
				cout << "Неверное значение! (0 - нет | 1 - да)" << endl;
			else i++;
		}
		system("cls");
		cout << "Время вылета" << endl << "Час: ";
		cin >> hh;
		cout << "Минуты: ";
		cin >> mm;
		system("cls");
	}
	void show() {
		cout << " ****************************************" << endl;
		cout << " * Номер рейса: " << flight_number << endl;
		cout << " * Тип самолёта: " << airplane_types[type_airplane] << endl;
		cout << " * Пункт назначения: " << destination << endl;
		cout << " * Время вылета: " << hh << ":" << mm << endl;
		cout << " * Дни недели: ";
		for (int i = 0; i < 7; i++) if (days[i]) cout << name_days[i] << " ";
		cout << endl << " ****************************************" << endl;
	}
	void show_by_day(short day) {
		for (int i = 0; i < 7; i++) if (days[i] && day == i) { show(); break; }
	}
	void show_by_destination(char * p_destination) {
		bool valid_str = true;
		int length = 0;
		int length_2 = 0;
		for (; *(p_destination + length) != '\0'; length++);
		for (; *(destination + length_2) != '\0'; length_2++);
		if (length == length_2) {
			for (int i = 0; i < length; i++) if (*(destination + i) != *(p_destination + i)) valid_str = false;
			if (valid_str) show();
		}
	}
	void show_by_day_and_more_time(short day, short p_hh, short p_mm) {
		for (int i = 0; i < 7; i++) if (days[i] && day == i && p_hh <= hh && p_mm < mm) { show(); break; }
	}
	void edit_destination() {
		cout << "Пункт назначения" << endl << "ENTER: ";
		destination = new char;
		cin.getline(destination, 24);
	}
	void edit_time() {
		cout << "Время вылета" << endl << "Час: ";
		cin >> hh;
		cout << "Минуты: ";
		cin >> mm;
	}
	void edit_date() {
		cout << "Дни недели (0 - нет | 1 - да)" << endl;
		for (int i = 0; i < 7; i++) {
			cout << name_days[i] << ": ";
			cin >> days[i];
		}
	}
	void edit_type_airplane() {
		cout << "Тип самолёта" << endl << "0 - узкофюзеляжный | 1 - широкофюзеляжный" << endl << "2 - местный | 3 - региональный" << endl << "ENTER: ";
		cin >> type_airplane;
	}
};

int main()
{
	setlocale(0, "");
	Aeroflot flights[MAX_FLIGHTS];
	short main_menu_id = 0;
	short count_aeroflot = 0;
	while (1) {
		system("cls");
		char c;
		cout << " ****************************************************************************************" << endl;
		cout << " *                                    Терминал аэрофлота                                *" << endl;
		cout << " *                                                                                      *" << endl;
		cout << " * 1) Добавить новый рейс                                                               *" << endl;
		cout << " * 2) Список рейсов по пункту назначения                                                *" << endl;
		cout << " * 3) Список рейсов по дню недели                                                       *" << endl;
		cout << " * 4) Список всех рейсов                                                                *" << endl;
		cout << " * 5) Список рейсов для заданного дня недели, время вылета для которых больше заданного *" << endl;
		cout << " * 6) Редактирование рейсов                                                             *" << endl;
		cout << " * 0) Выход                                                                             *" << endl;
		cout << " ****************************************************************************************" << endl;
		cout << endl << "ENTER: ";
		cin >> main_menu_id;
		if (!main_menu_id) break;
		switch (main_menu_id) {
		case 1: {
			while ((c = getchar()) == '\0');
			system("cls");
			if (count_aeroflot < MAX_FLIGHTS) {
				flights[count_aeroflot].add(count_aeroflot);
				count_aeroflot++;
			}
			break;
		}
		case 2: {
			while ((c = getchar()) == '\0');
			system("cls");
			char * destination = new char;
			cout << "Пункт назначения" << endl << "ENTER: ";
			cin.getline(destination, 24);
			for (int i = 0; i < count_aeroflot; i++) flights[i].show_by_destination(destination);
			system("pause");
			break;
		}
		case 3: {
			while ((c = getchar()) == '\0');
			system("cls");
			short day;
			cout << "День недели" << endl << "ENTER: ";
			cin >> day;
			for (int i = 0; i < count_aeroflot; i++) flights[i].show_by_day(day);
			system("pause");
			break;
		}
		case 4: {
			while ((c = getchar()) == '\0');
			system("cls");
			if (!count_aeroflot) cout << "Список пуст!" << endl;
			for (int i = 0; i < count_aeroflot; i++) flights[i].show();
			system("pause");
			break;
		}
		case 5: {
			while ((c = getchar()) == '\0');
			system("cls");
			short day, hh, mm;
			cout << "День недели" << endl << "ENTER: ";
			cin >> day;
			cout << "Час" << endl << "ENTER: ";
			cin >> hh;
			cout << "Минуты" << endl << "ENTER: ";
			cin >> mm;
			for (int i = 0; i < count_aeroflot; i++) flights[i].show_by_day_and_more_time(day, hh, mm);
			system("pause");
			break;
		}
		case 6: {
			while ((c = getchar()) == '\0');
			short sub_menu_id = 0;
			short flight_number = 0;
			while (1) {
				system("cls");
				if (sub_menu_id == 0) {
					cout << " ****************************************************************************************" << endl;
					cout << " *                                    Терминал аэрофлота                                *" << endl;
					cout << " *                                                                                      *" << endl;
					cout << " * 1) Выбрать рейс                                                                      *" << endl;
					cout << " * 2) Список рейсов                                                                     *" << endl;
					cout << " * 0) Назад                                                                             *" << endl;
					cout << " ****************************************************************************************" << endl;
					cout << endl << "ENTER: ";
					cin >> sub_menu_id;
					if (!sub_menu_id) break;
					switch (sub_menu_id) {
					case 1: {
						cout << "Номер рейса" << endl << "ENTER: ";
						cin >> flight_number;
						if (flight_number < 0 && flight_number > count_aeroflot) {
							system("cls");
							cout << "Данного рейса не существует!";
							system("pause");
							sub_menu_id = 0;
							break;
						}
						else {
							sub_menu_id = -1;
							break;
						}
					}
					case 2: {
						while ((c = getchar()) == '\0');
						system("cls");
						if (!count_aeroflot) cout << "Список пуст!" << endl;
						for (int i = 0; i < count_aeroflot; i++) flights[i].show();
						system("pause");
						sub_menu_id = 0;
						break;
					}
					}
				}
				else if (sub_menu_id == -1) {
					cout << " ****************************************************************************************" << endl;
					cout << " *                                    Терминал аэрофлота                                *" << endl;
					cout << " *                                                                                      *" << endl;
					cout << " * 1) Изменить пункт назначения                                                         *" << endl;
					cout << " * 2) Изменить время вылета                                                             *" << endl;
					cout << " * 3) Изменить тип самолёта                                                             *" << endl;
					cout << " * 4) Изменить дни вылета                                                               *" << endl;
					cout << " * 0) Назад                                                                             *" << endl;
					cout << " ****************************************************************************************" << endl;
					cout << endl << "ENTER: ";
					cin >> sub_menu_id;
					if (!sub_menu_id) sub_menu_id = 0;
					switch (sub_menu_id) {
					case 1: {
						while ((c = getchar()) == '\0');
						system("cls");
						flights[flight_number].edit_destination();
						sub_menu_id = -1;
						break;
					}
					case 2: {
						system("cls");
						flights[flight_number].edit_time();
						sub_menu_id = -1;
						break;
					}
					case 3: {
						system("cls");
						flights[flight_number].edit_type_airplane();
						sub_menu_id = -1;
						break;
					}
					case 4: {
						system("cls");
						flights[flight_number].edit_date();
						sub_menu_id = -1;
						break;
					}
					}
				}
			}
			break;
		}
		default: break;
		}
	}
	return 0;
}
Соседние файлы в предмете Программирование на C++