0% found this document useful (0 votes)
5 views

Code

Uploaded by

nargisimran73
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Code

Uploaded by

nargisimran73
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 30

#include <iostream>

#include <string>
#include <iomanip>
#include <conio.h>
#include <fstream>
using namespace std;

const int MAX_PILOTS = 100;


const int MAX_AIR_HOSTESSES = 100;
const int MAX_FLIGHTS = 100;
const int MAX_WEATHER = 30;
const int MAX_CUSTOMERS_PER_FLIGHT = 50;
int mainChoice;

bool isValidTime(const string &time);


bool isValidDate(const string &date);

bool noDigits(const string &input);


bool isNumeric(const string &input);
bool isValidEmail(const string &email);
bool isValidPhoneNumber(const string &phone);
bool isValidInput(bool isValid, string inputStr,int &input);

string pilots[MAX_PILOTS];
string pilot_license_numbers[MAX_PILOTS];
string airHostesses[MAX_AIR_HOSTESSES];
string air_hostess_employee_ids[MAX_AIR_HOSTESSES];
string duty_start_times[MAX_AIR_HOSTESSES];
string duty_end_times[MAX_AIR_HOSTESSES];
string weather_dates[MAX_WEATHER];
int weather_windSpeed[MAX_WEATHER];
int weather_visibility[MAX_WEATHER];
string flight_names[MAX_FLIGHTS];
string flight_times[MAX_FLIGHTS];
string customer_names[MAX_FLIGHTS][MAX_CUSTOMERS_PER_FLIGHT];
string customer_phone[MAX_FLIGHTS][MAX_CUSTOMERS_PER_FLIGHT]; // New phone array
string customer_email[MAX_FLIGHTS][MAX_CUSTOMERS_PER_FLIGHT];
string customer_passport_number[MAX_FLIGHTS][MAX_CUSTOMERS_PER_FLIGHT];
int customer_count[MAX_FLIGHTS] = {0};
int pilot_count = 0, air_hostess_count = 0, flight_count = 0, weather_count = 0;

void mainmenu();
void addPilot(string pilots[], string pilot_license_numbers[], int &pilot_count);
void deletePilot(string pilots[], string pilot_license_numbers[], int
&pilot_count);
void updatePilot(string pilots[], string pilot_license_numbers[], int pilot_count);
void listPilots(const string pilots[], const string pilot_license_numbers[], int
pilot_count);

void addAirHostess(string airHostesses[], string duty_start_times[], string


duty_end_times[], string air_hostess_employee_ids[], int &air_hostess_count);
void deleteAirHostess(string airHostesses[], string duty_start_times[], string
duty_end_times[], string air_hostess_employee_ids[], int &air_hostess_count);
void updateAirHostess(string airHostesses[], string duty_start_times[], string
duty_end_times[], string air_hostess_employee_ids[], int air_hostess_count);
void listAirHostesses(const string airHostesses[], const string duty_start_times[],
const string duty_end_times[], const string air_hostess_employee_ids[], int
air_hostess_count);
void addWeatherCondition(string weather_dates[], int weather_windSpeed[], int
weather_visibility[], int &weather_count);
void deleteWeather(string weather_dates[], int weather_windSpeed[], int
weather_visibility[], int &weather_count);
void updateWeather(string weather_dates[], int weather_windSpeed[], int
weather_visibility[], int weather_count);
void listWeather(const string weather_dates[], const int weather_windSpeed[], const
int weather_visibility[], int weather_count);
void checkWeatherSuitability(string weather_dates[], const int &windSpeed, const
int &visibility, int weather_count);

void addFlight(string flight_names[], string flight_times[], int &flight_count);


void deleteFlight(string flight_names[], string flight_times[], int &flight_count);
void updateFlightTime(string flight_names[], string flight_times[], int
flight_count);
void listFlights(const string flight_names[], const string flight_times[], int
flight_count);
void addCustomer(int flightIndex);
void listCustomers(int flightIndex);
void updateCustomer(int flightIndex);

void saveCustomerDataToFile(int flightIndex, int customerCount, string


customerNames[][MAX_CUSTOMERS_PER_FLIGHT], string customerPhones[]
[MAX_CUSTOMERS_PER_FLIGHT], string customerEmails[][MAX_CUSTOMERS_PER_FLIGHT]);
void saveWeatherData(const string weather_dates[], const int weather_windSpeed[],
const int weather_visibility[], int weather_count);
void addFlightToFile(const string flight_names[], const string flight_times[], int
flight_count);
void saveAirHostessesToFile(string airHostesses[], string duty_start_times[],
string duty_end_times[], string air_hostess_employee_ids[], int air_hostess_count);
void loadWeatherData(string weather_dates[], int weather_windSpeed[], int
weather_visibility[], int &weather_count);
void loadAirHostessesFromFile(string airHostesses[], string duty_start_times[],
string duty_end_times[], string air_hostess_employee_ids[], int
&air_hostess_count);

void mainmenu()
{
do{
system("cls");
cout << "
-----------------------------------------------------------------------------------
----------------------------" << endl;
cout << "
___________________________________________________________________________________
________________________" << endl;
cout << " |
|" << endl;
cout << " | __ |__ _______ ___ ___
__ ___________ _______ |__ ___ ___ |" << endl;
cout << " | /\"\"\\ |\" \\ /\" \\
|\" \\ /\" | /\"\"\\(\" _ \")/\" \\ |\" \\ |\" \\/\" |
|" << endl;
cout << " | / \\ || | |: | \\ \\ // |
/ \\)__/ \\\\__/|: | || | \\ \\ / |" << endl;
cout << " | /' /\\ \\ |: | |_____/ ) /\\\\ \\ /. |
/' /\\ \\ \\\\_ / |_____/ ) |: | \\\\ \\/ |" << endl;
cout << " | // __' \\ |. | // / |: \\.
| // __' \\ |. | // / |. | /\\. \\ |" << endl;
cout << " | / / \\\\ \\ /\\ |\\ |: __ \\ |. \\ /:
| / / \\\\ \\\\: | |: __ \\ /\\ |\\ / \\ \\ |" << endl;
cout << " | (___/ \\___)(__\\_|_)|__| \\___) |___|\\__/|___|
(___/ \\___)\\__| |__| \\___)(__\\_|_)|___/\\___| |" << endl;
cout << " |
___________________________________________________________________________________
_______________________|" << endl;
cout << "
-----------------------------------------------------------------------------------
----------------------------" << endl;
cout << " " << endl;
cout <<
" ,------------------------------------------------------------------------------
------------------------------------," << endl;
cout << " | 1. Pilot Menu
2. Air Hostess Menu |" << endl;
cout << " | 3. Flight Menu
4. Weather Menu |" << endl;
cout << " | 5. Exit
|" << endl;
cout << " \\
___________________________________________________________________________________
________________________________/" << endl;
cout << " ->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->-
>->->->->->->->->->->->->->->->->->->->->->->->->->->->-" << endl;
cout << "[Enter your choice] ";
cin >> mainChoice;
} while(!isValidInput);
}

// pilot menu functions.


void addPilot(string pilots[], string pilot_license_numbers[], int &pilot_count)
{
if (pilot_count < MAX_PILOTS)
{
cout << "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[ ADD PILOT
RECORD ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n";
do
{
cout << "Enter pilot name: ";
getline(cin, pilots[pilot_count]);
{
if (pilots[pilot_count].empty())
{
cout << "Pilot name cannot be empty. Please try again.\n";
}
if (noDigits(pilots[pilot_count]))
{
cout << "Invalid input! The string should not contain numbers."
<< endl;
}
}
} while (pilots[pilot_count].empty() || noDigits(pilots[pilot_count]));
do
{
cout << "Enter pilot license number: ";
getline(cin, pilot_license_numbers[pilot_count]);
{
if (pilot_license_numbers[pilot_count].empty())
{
cout << "License number cannot be empty. Please try again.\n";
}
if (!isNumeric(pilot_license_numbers[pilot_count]))
{
cout << "Invalid license number! It should contain only
digits.\n";
}
}
} while (pilot_license_numbers[pilot_count].empty() || !
isNumeric(pilot_license_numbers[pilot_count]));
cout << " Pilot added successfully!\n";

ofstream file("pilots.txt", ios::app);


if (file.is_open())
{
file << pilots[pilot_count] << "," <<
pilot_license_numbers[pilot_count] << "\n";
file.close();
}
pilot_count++;
getch();
}
else
{
cout << "Maximum pilot limit reached.\n";
}
system("cls");
}

void deletePilot(string pilots[], string pilot_license_numbers[], int &pilot_count)


{
cout << "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[ DELETE PILOT
RECORD ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n";
if (pilot_count == 0)
{
cout << "No pilots to delete.\n";
getch();
return;
}

listPilots(pilots, pilot_license_numbers, pilot_count);


int index;
cout << "Enter the index of the pilot to delete: ";
cin >> index;
cin.ignore();
if (index >= 0 && index < pilot_count)
{
for (int i = index; i < pilot_count - 1; i++)
{
pilots[i] = pilots[i + 1];
pilot_license_numbers[i] = pilot_license_numbers[i + 1];
}
pilot_count--;
ofstream file("pilots.txt", ios::trunc);
if (file.is_open())
{
for (int i = 0; i < pilot_count; i++)
{
file << pilots[i] << "," << pilot_license_numbers[i] << "\n";
}
file.close();
}
cout << "Pilot deleted successfully.\n";
}
else
{
cout << "Invalid index.\n";
}
getch();
}

void updatePilot(string pilots[], string pilot_license_numbers[], int pilot_count)


{
cout << "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[ UPDATE PILOT
RECORD ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n";
if (pilot_count == 0)
{
cout << "No pilots to update.\n";
getch();
return;
}

listPilots(pilots, pilot_license_numbers, pilot_count);


int index;
cout << "Enter the index of the pilot to update: ";
cin >> index;
cin.ignore();

if (index >= 0 && index < pilot_count)


{
do
{
cout << "Enter new pilot name: ";
getline(cin, pilots[index]);
{
if (pilots[index].empty())
{
cout << "Pilot name cannot be empty. Please try again." <<
endl;
}
if (noDigits(pilots[index]))
{
cout << "Invalid input! The string should not contain numbers."
<< endl;
}
}
} while (pilots[index].empty() || noDigits(pilots[index]));
do
{
cout << "Enter new pilot license number: ";
getline(cin, pilot_license_numbers[index]);
{
if (pilot_license_numbers[index].empty())
{
cout << "License number cannot be empty. Please try again.\n";
}
if (!isNumeric(pilot_license_numbers[index]))
{
cout << "Invalid license number! It should contain only
digits.\n";
}
}
} while (pilot_license_numbers[index].empty() || !
isNumeric(pilot_license_numbers[index]));
ofstream file("pilots.txt", ios::trunc);
{
if (file.is_open())
{
for (int i = 0; i < pilot_count; i++)
file << pilots[i] << "," << pilot_license_numbers[i] << "\n";
}
file.close();
}
cout << "Pilot updated successfully.\n";
}
else
{
cout << "Invalid index.\n";
}
getch();
}

void listPilots(const string pilots[], const string pilot_license_numbers[], int


pilot_count)
{

if (pilot_count == 0)
{
cout << "No pilots to display.\n";
getch();
return;
}
cout << "\n>>>>>>>>[ LIST PILOT RECORD ]<<<<<<<<\n";
cout << left << setw(20) << "Index" << setw(20) << "Name" << setw(20) <<
"License" << endl;
for (int i = 0; i < pilot_count; i++)
{
cout << left << setw(20) << i << setw(20) << pilots[i] << setw(20) <<
pilot_license_numbers[i] << endl;
}
getch();
}
// airhostess menu functions
void addAirHostess(string airHostesses[], string duty_start_times[], string
duty_end_times[], string air_hostess_employee_ids[], int &air_hostess_count)
{
cout << "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[ ADD Air
Hostesses ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n";
if (air_hostess_count < MAX_AIR_HOSTESSES)
{
do
{
cout << "Enter air hostess name: ";
getline(cin, airHostesses[air_hostess_count]);
{
if (airHostesses[air_hostess_count].empty())
{
cout << "Air Hostesses name can't be empty.Try again.";
}
if (noDigits(airHostesses[air_hostess_count]))
{
cout << "Invalid input! Name should not contain numbers." <<
endl;
}
}
} while (airHostesses[air_hostess_count].empty() ||
(noDigits(airHostesses[air_hostess_count])));
do
{
cout << "Enter air hostess employee ID: ";
getline(cin, air_hostess_employee_ids[air_hostess_count]);
{
if (air_hostess_employee_ids[air_hostess_count].empty())
{
cout << "Air Hostesses employee id can't be empty.Try again.";
}
if (!isNumeric(air_hostess_employee_ids[air_hostess_count]))
{
cout << "Invalid employee id! \n";
}
}
} while (air_hostess_employee_ids[air_hostess_count].empty() || !
isNumeric(air_hostess_employee_ids[air_hostess_count]));
do
{
cout << "Enter duty start time: ";
cin >> duty_start_times[air_hostess_count];
if (!isValidTime(duty_start_times[air_hostess_count]))
{
cout << "Invalid flight time. Please enter in HH:MM format (00:00 -
23:59).\n";
}
} while (!isValidTime(duty_start_times[air_hostess_count]));
do
{
cout << "Enter duty end time: ";
cin >> duty_end_times[air_hostess_count];
if (!isValidTime(duty_end_times[air_hostess_count]))
{
cout << "Invalid flight time. Please enter in HH:MM format (00:00 -
23:59).\n";
}
} while (!isValidTime(duty_end_times[air_hostess_count]));
cin.ignore();
air_hostess_count++;
saveAirHostessesToFile(airHostesses, duty_start_times, duty_end_times,
air_hostess_employee_ids, air_hostess_count);
cout << "Air hostess added successfully.\n";
}
else
{
cout << "Maximum number of air hostess limit reached.\n";
}
getch();
}
void deleteAirHostess(string airHostesses[], string duty_start_times[], string
duty_end_times[], string air_hostess_employee_ids[], int &air_hostess_count)
{
cout << "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[ DELETE Air
Hostesses ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n";
if (air_hostess_count == 0)
{
cout << "No air hostesses to delete.\n";
getch();
return;
}

listAirHostesses(airHostesses, air_hostess_employee_ids, duty_start_times,


duty_end_times, air_hostess_count);
int index;
cout << "Enter the index of the air hostess to delete: ";
cin >> index;
cin.ignore();
if (index >= 0 && index < air_hostess_count)
{
for (int i = index; i < air_hostess_count - 1; i++)
{
airHostesses[i] = airHostesses[i + 1];
air_hostess_employee_ids[i] = air_hostess_employee_ids[i + 1];
duty_start_times[i] = duty_start_times[i + 1];
duty_end_times[i] = duty_end_times[i + 1];
}
air_hostess_count--;
saveAirHostessesToFile(airHostesses, duty_start_times, duty_end_times,
air_hostess_employee_ids, air_hostess_count);
cout << "Air hostess deleted successfully.\n";
}
else
{
cout << "Invalid index.\n";
}
getch();
}

void updateAirHostess(string airHostesses[], string duty_start_times[], string


duty_end_times[], string air_hostess_employee_ids[], int air_hostess_count)
{
cout << "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[ UPDATE Air
Hostesses ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n";
if (air_hostess_count == 0)

{
cout << "No air hostesses to update.\n";
getch();
return;
}

listAirHostesses(airHostesses, air_hostess_employee_ids, duty_start_times,


duty_end_times, air_hostess_count);
int index;
cout << "Enter the index of the air hostess to update: ";
cin >> index;
cin.ignore();
if (index >= 0 && index < air_hostess_count)
{
do
{
cout << "Enter new air hostess name: ";
getline(cin, airHostesses[index]);
{
if (airHostesses[index].empty())
{
cout << "Air Hostess Name can't be empty.";
}
if (noDigits(airHostesses[index]))
{
cout << "Invalid input! The string should not contain numbers."
<< endl;
}
}
} while (airHostesses[index].empty() || noDigits(airHostesses[index]));
do
{
cout << "Enter new air hostess employee ID: ";
getline(cin, air_hostess_employee_ids[index]);
{
if (air_hostess_employee_ids[index].empty())
{
cout << "Air Hostess Name can't be empty.";
}
if (!isNumeric(airHostesses[index]))
{
cout << "Invalid license number! It should contain only
digits.\n";
}
}
} while (air_hostess_employee_ids[index].empty() || !
isNumeric(airHostesses[index]));
do
{
cout << "Enter new duty start time: ";
getline(cin, duty_start_times[index]);
if (!isValidTime(duty_start_times[index]))
{
cout << "Invalid flight time. Please enter in HH:MM format (00:00 -
23:59).\n";
}
} while (!isValidTime(duty_start_times[index]) ||
duty_start_times[index].empty());
do
{
cout << "Enter new duty end time: ";
getline(cin, duty_end_times[index]);
if (!isValidTime(duty_end_times[index]))
{
cout << "Invalid flight time. Please enter in HH:MM format (00:00 -
23:59).\n";
}
} while (!isValidTime(duty_end_times[index]) ||
duty_end_times[index].empty());

cout << "Air hostess updated successfully.\n";


}
else
{
cout << "Invalid index.\n";
}
getch();
}

void listAirHostesses(const string airHostesses[], const string


air_hostess_employee_ids[], const string duty_start_times[], const string
duty_end_times[], int air_hostess_count)
{
if (air_hostess_count == 0)
{
cout << "No air hostesses to display.\n";
return;
}
cout << "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[ LIST Air
Hostesses ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n";
cout << left << setw(15) << "Index" << setw(20) << "Name" << setw(20) <<
"Employee ID" << setw(20) << "Duty Start" << setw(20) << "Duty End" << endl;
for (int i = 0; i < air_hostess_count; i++)
{
cout << left << setw(15) << i << setw(20) << airHostesses[i] << setw(20) <<
air_hostess_employee_ids[i]
<< setw(20) << duty_start_times[i] << setw(10) << duty_end_times[i] <<
endl;
}
}

// weather functions
void addWeatherCondition(string weather_dates[], int weather_windSpeed[], int
weather_visibility[], int &weather_count)
{
cout << "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[ ADD
WEATHER ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n";
if (weather_count < MAX_WEATHER)
{
do
{
cout << "Enter date (e.g. DD/MM/YYYY): ";
getline(cin, weather_dates[weather_count]);
} while (!isValidDate(weather_dates[weather_count]));
if (weather_count < MAX_WEATHER)
{
cout << "Enter wind speed (in km/h): ";
cin >> weather_windSpeed[weather_count];
cout << "Enter visibility (in meters): ";
cin >> weather_visibility[weather_count];
cin.ignore();
weather_count++;
saveWeatherData(weather_dates, weather_windSpeed, weather_visibility,
weather_count);
cout << "Weather condition added successfully.\n";
}
}
else
{
cout << "Maximum weather conditions reached.\n";
}
}

void deleteWeather(string weather_dates[], int weather_windSpeed[], int


weather_visibility[], int &weather_count)
{
cout << "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[ DELETE
WEATHER ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n";
if (weather_count == 0)
{
cout << "No weather conditions to delete.\n";
return;
}

listWeather(weather_dates, weather_windSpeed, weather_visibility,


weather_count);

int index;
cout << "Enter the index of the weather condition to delete: ";
cin >> index;
cin.ignore();

if (index >= 0 && index < weather_count)


{
for (int i = index; i < weather_count - 1; i++)
{
weather_dates[i] = weather_dates[i + 1];
weather_windSpeed[i] = weather_windSpeed[i + 1];
weather_visibility[i] = weather_visibility[i + 1];
}
weather_count--;
saveWeatherData(weather_dates, weather_windSpeed, weather_visibility,
weather_count);
cout << "Weather condition deleted successfully.\n";
}
else
{
cout << "Invalid index.\n";
}
}
void updateWeather(string weather_dates[], int weather_windSpeed[], int
weather_visibility[], int weather_count)
{
cout << "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[ UPDATE
WEATHER ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n";
if (weather_count == 0)
{
cout << "No weather conditions to update.\n";
return;
}

listWeather(weather_dates, weather_windSpeed, weather_visibility,


weather_count);

int index;
cout << "Enter the index of the weather condition to update: ";
cin >> index;
cin.ignore();
if (index >= 0 && index < weather_count)
{
do
{
cout << "Enter new weather date (DD/MM/YYYY): ";
cin >> weather_dates[index];
} while (!isValidDate(weather_dates[index]));
cout << "Enter new wind speed: ";
cin >> weather_windSpeed[index];
cout << "Enter new visibility: ";
cin >> weather_visibility[index];
saveWeatherData(weather_dates, weather_windSpeed, weather_visibility,
weather_count);
cout << "Weather condition updated successfully.\n";
}
else
{
cout << "Invalid index.\n";
}
}

void listWeather(const string weather_dates[], const int weather_windSpeed[], const


int weather_visibility[], int weather_count)
{
cout << "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[ UPDATE FLIGHT
RECORD ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n";
if (weather_count == 0)
{
cout << "No weather conditions to display.\n";
return;
}

cout << "\nIndex\tDate\t\tWind Speed\tVisibility\n";


for (int i = 0; i < weather_count; i++)
{
cout << i << "\t" << weather_dates[i] << "\t" << weather_windSpeed[i] << "\
t\t" << weather_visibility[i] << endl;
}
getch();
}
void checkWeatherSuitability(int weather_count, string weather_dates[], int
weather_windSpeed[], int weather_visibility[])
{
cout << "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[ WEATHER
SUITABILITY ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n";
if (weather_count == 0)
{
cout << "No weather data available.\n";
return;
}

string dateToCheck;
do
{
cout << "Enter the date you want to check (e.g. (DD/MM/YYYY)): ";
getline(cin, dateToCheck);
} while (!isValidDate(dateToCheck));
bool found = false;
for (int i = 0; i < weather_count; i++)
{
if (weather_dates[i] == dateToCheck)
{
cout << "\n--- Weather on " << weather_dates[i] << " ---\n";
cout << "Wind Speed: " << weather_windSpeed[i] << " km/h\n";
cout << "Visibility: " << weather_visibility[i] << " meters\n";

if (weather_windSpeed[i] > 50)


{
cout << "Condition: Not suitable (High wind speed)\n";
}
else if (weather_visibility[i] < 1000)
{
cout << "Condition: Not suitable (Poor visibility)\n";
}
else
{
cout << "Condition: Suitable for flying.\n";
}

found = true;
break;
}
}

if (!found)
{
cout << "No weather data found for the date: " << dateToCheck << endl;
}
}
void listWeatherConditions(const string weather_dates[], const string
weather_windSpeed[], const string weather_visibility[], int weather_count)
{

if (weather_count == 0)
{
cout << "No weather conditions to display.\n";
return;
}
cout << "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[ LIST
WEATHER ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n";
cout << left << setw(15) << "Date"
<< setw(20) << "Wind Speed (km/h)"
<< setw(20) << "Visibility (meters)" << endl;
for (int i = 0; i < weather_count; i++)
{
cout << left << setw(15) << weather_dates[i]
<< setw(20) << weather_windSpeed[i]
<< setw(20) << weather_visibility[i] << endl;
}
getch();
}
// Flight Record functions
void addFlight(string flight_names[], string flight_times[], int &flight_count)
{
cout << "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[ ADD FLIGHT
RECORD ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n";
if (flight_count < MAX_FLIGHTS)
{
do
{
cout << "Enter flight name: ";
getline(cin, flight_names[flight_count]);
{
if (flight_names[flight_count].empty())
{
cout << "Flight Name can't be empty." << endl;
}
}
} while (flight_names[flight_count].empty() );
do
{
cout << "Enter flight time(e.g. HH:MM): ";
getline(cin, flight_times[flight_count]);
{
if (!isValidTime(flight_times[flight_count]))
{
cout << "Invalid flight time. Please enter in HH:MM format
(00:00 - 23:59).\n";
}
}
} while (!isValidTime(flight_times[flight_count]));
flight_count++;

{
ofstream file("flights.txt", ios::app);
if (file)
{
file << flight_names[flight_count - 1] << "," <<
flight_times[flight_count - 1] << endl;
}
file.close();
}
cout << "Flight added successfully.\n";
}
else
{
cout << "Maximum flight limit reached.\n";
}
}

void deleteFlight(string flight_names[], string flight_times[], int &flight_count)


{
cout << "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[ DELETE FLIGHT
RECORD ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n";
if (flight_count == 0)
{
cout << "No flights to delete.\n";
return;
}

listFlights(flight_names, flight_times, flight_count);

int index;
cout << "Enter the index of the flight to delete: ";
cin >> index;
cin.ignore();
if (index >= 0 && index < MAX_FLIGHTS)
{
for (int i = index; i < flight_count - 1; i++)
{
flight_names[i] = flight_names[i + 1];
flight_times[i] = flight_times[i + 1];
}
flight_count--;
ofstream file("flights.txt");
if (file)
{
for (int i = 0; i < flight_count; i++)
{
file << flight_names[i] << "," << flight_times[i] << endl;
}
file.close();

cout << "Flight deleted successfully.\n";


}
else
{
cout << "Invalid index.\n";
}
}
}
void listFlights(const string flight_names[], const string flight_times[], int
flight_count)
{
if (flight_count == 0)
{
cout << "No flights to display.\n";
return;
}
cout << "\n-----------------[ LIST FLIGHTS ]------------------\n";
cout << left << setw(20) << "Index" << setw(20) << "Flight Name" << setw(20) <<
"Flight Time" << endl;
for (int i = 0; i < flight_count; i++)
{
cout << left << setw(20) << i << setw(20) << flight_names[i] << setw(20) <<
flight_times[i] << endl;
}
getch();
}

void updateFlightTime(string flight_names[], string flight_times[], int


flight_count)
{
if (flight_count == 0)
{
cout << "No flights to update.\n";
return;
}

listFlights(flight_names, flight_times, flight_count);


int index;
cout << "Enter the index of the flight to update: ";
cin >> index;
cin.ignore();
if (index >= 0 && index < flight_count)
{
do
{
cout << "Enter new flight name: ";
getline(cin, flight_names[index]);
{
if (flight_names[index].empty())
{
cout << "Flight name can't be empty." << endl;
}
}
} while (flight_names[index].empty());
do
{
cout << "Enter new flight time: ";
getline(cin, flight_times[index]);
if (!isValidTime(flight_times[index]))
{
cout << "Invalid flight time. Please enter in HH:MM format (00:00 -
23:59).\n";
}
} while (!isValidTime(flight_times[index]));
ofstream file("flights.txt");
if (file)
{
for (int i = 0; i < flight_count; i++)
{
file << flight_names[i] << "," << flight_times[i] << endl;
}
file.close();
cout << "Flight updated successfully.\n";
}
else
{
cout << "Invalid index.\n";
}
}
}
void addCustomer(int flightIndex)
{
if (customer_count[flightIndex] < MAX_CUSTOMERS_PER_FLIGHT)
{
string customer_name, phone, email, passport_number;
do
{
cout << "Enter customer name: ";
getline(cin, customer_name);
{
if (customer_name.empty())
{
cout << "Customer Name can't be empty.";
}
if (noDigits(customer_name))
{
cout << "Invalid input! Name should not contain numbers.";
}
}
} while (customer_name.empty() || noDigits(customer_name));
do
{
cout << "Enter customer phone number: ";
getline(cin, phone);
if (!isValidPhoneNumber(phone))
{
cout << "Invalid phone number.\n";
}
} while (!isValidPhoneNumber(phone));
do
{
cout << "Enter customer email: ";
getline(cin, email);
if (!isValidEmail(email))
{
cout << "Invalid email address.\n";
}
} while (!isValidEmail(email));
// Store customer data
customer_names[flightIndex][customer_count[flightIndex]] = customer_name;
customer_phone[flightIndex][customer_count[flightIndex]] = phone;
customer_email[flightIndex][customer_count[flightIndex]] = email;
customer_passport_number[flightIndex][customer_count[flightIndex]] =
passport_number;

customer_count[flightIndex]++;

cout << "Customer added to flight " << flight_names[flightIndex] << ".\n";
saveCustomerDataToFile(flightIndex, customer_count[flightIndex],
customer_names, customer_phone, customer_email);
}
else
{
cout << "This flight is fully booked.\n";
}
}

void listCustomers(int flightIndex)


{
cout << "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[ CUSTOMER
LIST ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n";
cout << "FLIGHT:" << flight_names[flightIndex] << " ---\n";
if (customer_count[flightIndex] == 0)
{
cout << "No customers for this flight.\n";
return;
}
for (int i = 0; i < customer_count[flightIndex]; i++)
{
cout << left << setw(5) << "index"
<< setw(20) << "customers"
<< setw(20) << "phone no."
<< setw(30) << "email address" << endl;
cout << left << setw(5) << i + 1
<< setw(20) << customer_names[flightIndex][i]
<< setw(20) << customer_phone[flightIndex][i]
<< setw(30) << customer_email[flightIndex][i] << endl;
}
getch();
}
void updateCustomer(int flightIndex)
{
if (customer_count[flightIndex] == 0)
{
cout << "No customers to update for this flight.\n";
return;
}

// List the customers for selection


cout << "\n--------------------------| Customer List for Flight
|-----------------------------\n";
cout << "FLIGHT:" << flight_names[flightIndex] << " ---\n";
for (int i = 0; i < customer_count[flightIndex]; i++)
{
cout << left << setw(5) << i + 1
<< setw(20) << customer_names[flightIndex][i] << setw(20) <<
customer_phone[flightIndex][i]
<< setw(30) << customer_email[flightIndex][i] << endl;
}
cout << "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[ UPDATE CUSTOMER
RECORD ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n";
int customerIndex;
cout << "Enter the customer index to update: ";
cin >> customerIndex;
cin.ignore();

if (customerIndex < 1 || customerIndex > customer_count[flightIndex])


{
cout << "Invalid customer number.\n";
return;
}

customerIndex--;

string new_name, new_phone, new_email, new_passport;


do
{
cout << "Enter new name (or press Enter to keep the current name): ";
getline(cin, new_name);
{
if (new_name != "")
customer_names[flightIndex][customerIndex] = new_name;
}
if (noDigits(new_name))
{
cout << "Invalid input! The string should not contain numbers." <<
endl;
}
} while (new_name != "" || noDigits(new_name));
do
{
{
cout << "Enter new phone number (or press Enter to keep the current
phone number): ";
getline(cin, new_phone);
{
{
if (new_phone != "")
customer_phone[flightIndex][customerIndex] = new_phone;
}
{
if (!isValidPhoneNumber(new_phone))
cout << "Invalid phone number.\n";
}
}
}
} while (!isValidPhoneNumber(new_phone) || new_phone != "");
do
{
cout << "Enter new email (or press Enter to keep the current email): ";
getline(cin, new_email);
{
{
if (new_email != "")
customer_email[flightIndex][customerIndex] = new_email;
}
{
if (!isValidEmail(new_email))
{
cout << "Invalid email address.\n";
}
}
}
} while (!isValidEmail(new_email));
cout << "Enter new passport number (or press Enter to keep the current passport
number): ";
getline(cin, new_passport);
if (new_passport != "")
{
customer_passport_number[flightIndex][customerIndex] = new_passport;
}

cout << "Customer record updated successfully.\n";


saveCustomerDataToFile(flightIndex, customer_count[flightIndex],
customer_names, customer_phone, customer_email);
}

// MAIN FUNCTION

int main()
{
do
{
mainmenu();
if (mainChoice == 1)
{
int pilotChoice;
string pilots[MAX_PILOTS];
string pilot_license_numbers[MAX_PILOTS];
do
{
system("cls");
cout << " _______ |__ ___ ______
___________ ___ ___ _______ _____ ___ ____ ____ \n";
cout << " | __ \"\\ |\" \\ |\" | / \" \\
(\" _ \") |\" \\ /\" | /\" \"| (\\\" \\|\" \\ (\" _||_ \" |
\n";
cout << " (. |__) :) || | || | //
____ \\ )__/ \\\\__/ \\ \\ // |(: ______) |.\\\\ \\ | |
( ) : | \n";
cout << " |: ____/ |: | |: | / / ) :) \\\\_
/ /\\\\ \\/. | \\/ | |: \\. \\\\ | (: | | . ) \n";
cout << " (| / |. | \\ |___ (: (____/ // |.
| |: \\. | // ___)_ |. \\ \\. | \\\\ \\__/ // \n";
cout << " /|__/ \\ /\\ |\\ ( \\_|: \\ \\ /
\\: | |. \\ /: |(: \"| | \\ \\ | /\\\\ __ //\\ \n";
cout << " (_______) (__\\_|_) \\
_______) \\\"_____/ \\__| |___|\\__/|___| \\_______) \\___|\\
____\\) (__________) \n";
cout << "
\n";
cout << " " << endl;
cout <<
" ,------------------------------------------------------------------------------
------------------------------------," << endl;
cout << " | 1. Add Pilot
2. Delete Pilot |" << endl;
cout << " | 3. Update Pilot
4. List Pilot |" << endl;
cout << " | 5. Back to
Main Menu |" << endl;
cout << " \\
___________________________________________________________________________________
________________________________/" << endl;
cout << " ->->->->->->->->->->->->->->->->->->->->->->->->->->->->-
>->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->-" << endl;

do
{
cout << "[Enter your choice]:";
cin >> pilotChoice;
if (pilotChoice < 1 && pilotChoice > 5)
cout << "Please Enter a valid choice.";
} while (pilotChoice < 1 && pilotChoice > 5);
cin.ignore();
switch (pilotChoice)
{
case 1:
addPilot(pilots, pilot_license_numbers, pilot_count);
break;
case 2:
deletePilot(pilots, pilot_license_numbers, pilot_count);
break;
case 3:
updatePilot(pilots, pilot_license_numbers, pilot_count);
break;
case 4:
listPilots(pilots, pilot_license_numbers, pilot_count);
break;
case 5:
break;
default:
cout << "Invalid choice.\n";
}
} while (pilotChoice != 5);
}
else if (mainChoice == 2)
{
int hostessChoice;
do
{
system("cls");
cout << " __ |__ _______ __ __ ______
________ ___________ _______ ________ ________ ___ ___ _______
_____ ___ ____ ____ " << endl;
cout << " /\"\"\\ |\" \\ /\" \\ /\" |
| \"\\ / \" \\ /\" )(\"
_ \") /\" \"| /\" ) /\" ) |\" \\ /\" | /\" \"|
(\\\" \\|\" \\ (\" _||_ \" | " << endl;
cout << " / \\ || | |: |(: (__) :) //
____ \\ (: \\___/ )__/ \\\\__/ (: ______)(: \\___/ (: \\
___/ \\ \\ // |(: ______) |.\\\\ \\ | | ( ) | " << endl;
cout << " /' /\\ \\ |: | |
_____/ ) \\/ \\/ / / ) :) \\___ \\ \\\\_ / \\/ | \\
___ \\ \\___ \\ /\\\\ \\/. | \\/ | |: \\. \\\\ | | | | |
" << endl;
cout << " // __' \\ |. | // / // __ \\\\(:
(____/ // __/ \\\\ |. | // ___)_ __/ \\\\ __/ \\\\ |: \\.
| // ___)_ |. \\ \\. | | \\__/ | " << endl;
cout << " / / \\\\ \\ /\\ |\\ |: __ \\ |: ( ) |\\
/ /\" \\ :) \\: | (: \"| /\" \\ :) /\" \\ :) |. \\ /:
|(: \"| | \\ \\ | \\ / " << endl;
cout << "(___/ \\___)(__\\_|_) |__| \\___) \\__| |
__/ \\\"_____/ (_______/ \\__| \\_______)(_______/ (_______/ |
___|\\_/|___| \\_______) \\___|\\____\\| \\______/ " << endl;
cout << "
" << endl;
cout << " " << endl;
cout <<
" ,-------------------------------------------------------------------
-----------------------------------------------," << endl;
cout << " | 1. Add AirHostess
2. Delete AirHostess |" << endl;
cout << " | 3. Update AirHostess
4. List AirHostess |" << endl;
cout << " |
5. Back to Main Menu |" << endl;
cout << " \\
___________________________________________________________________________________
________________________________/" << endl;
cout << " ->->->->->->->->->->->->->->->->->->->->->->->->->->->->-
>->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->-
>->->->->->->->->->->->-" << endl;
do
{
cout << "[Enter your choice] ";
cin >> hostessChoice;
if (hostessChoice > 5 && hostessChoice < 1)
cout << "Please Enter a valid choice.";
} while (hostessChoice > 5 && hostessChoice < 1);
cin.ignore();

switch (hostessChoice)
{
case 1:
addAirHostess(airHostesses, duty_start_times, duty_end_times,
air_hostess_employee_ids, air_hostess_count);
break;
case 2:
deleteAirHostess(airHostesses, duty_start_times,
duty_end_times, air_hostess_employee_ids, air_hostess_count);
break;
case 3:
updateAirHostess(airHostesses, duty_start_times,
duty_end_times, air_hostess_employee_ids, air_hostess_count);
break;
case 4:
listAirHostesses(airHostesses, duty_start_times,
duty_end_times, air_hostess_employee_ids, air_hostess_count);
getch();
break;
case 5:
break;
default:
cout << "Invalid choice.\n";
}
} while (hostessChoice != 5);
}
else if (mainChoice == 3)
{
int flightChoice;
do
{
system("cls");
cout << " _______ ___ |__ _______ __ __
___________ ___ ___ _______ _____ ___ ____ ____ \n";
cout << " /\" \"| |\" | |\" \\ /\" _ \"| /\"
| | \"\\ (\" _ \") |\" \\ /\" | /\" \"| (\\\" \\|\" \\ (\"
_||_ \" | \n";
cout << " |: ______) || | || | (: ( \\___) (:
(__) :) )__/ \\\\__/ \\ \\ // |(: ______) |.\\\\ \\ | | ( ) :
| \n";
cout << " \\/ | |: | |: | \\/ \\ \\/
\\/ \\\\_ / /\\\\ \\/. | \\/ | |: \\. \\\\ | (: | | . )
\n";
cout << " // ___) \\ |___ |. | // \\ ___ //
__ \\\\ |. | |: \\. | // ___)_ |. \\ \\. | \\\\ \\
__/ // \n";
cout << " |: ( ( \\_|: \\ /\\ |\\ (: _( _| (: ( )
:) \\: | |. \\ /: |(: \"| | \\ \\ | /\\\\ __ //\\ \
n";
cout << " \\__/ \\_______) (__\\_|_) \\_______) \\__| |
__/ \\__| |___|\\__/|___| \\_______) \\___|\\____\\) (__________) \
n";
cout << "
\n";
cout << " " << endl;
cout <<
" ,-----------------------------------------------------------------------
-------------------------------------------," << endl;
cout << " | 1. Add Flight
2. List Flight |" << endl;
cout << " | 3. Update Flight
4. Delete Flight |" << endl;
cout << " | 5. Add Customer
6. List Customer |" << endl;
cout << " | 7. Update Customer
8. Back to Main Menu |" << endl;
cout << " \\
___________________________________________________________________________________
________________________________/" << endl;
cout << " ->->->->->->->->->->->->->->->->->->->->->->->->->->->->-
>->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->-
>->->->->-" << endl;
do
{
cout << "[Enter your choice] ";
cin >> flightChoice;
if (flightChoice > 8 && flightChoice < 1)
cout << "Invalid Choice.";
} while (flightChoice > 8 && flightChoice < 1);
cin.ignore();
int flightIndex;
switch (flightChoice)
{
case 1:
addFlight(flight_names, flight_times, flight_count);
getch();
break;
case 2:
listFlights(flight_names, flight_times, flight_count);
getch();
break;
case 3:
updateFlightTime(flight_names, flight_times, flight_count);
getch();
break;
case 4:
deleteFlight(flight_names, flight_times, flight_count);
getch();
break;
case 5:
listFlights(flight_names, flight_times, flight_count);
cout << "Enter flight index to add customer: ";
cin >> flightIndex;
cin.ignore();
if (flightIndex >= 0 && flightIndex < flight_count)
{
addCustomer(flightIndex);
}
else
{
cout << "Invalid flight index.\n";
}
getch();
break;
case 6:
{
cout << "Enter flight index to list customers: ";
cin >> flightIndex;
cin.ignore();
if (flightIndex >= 0 && flightIndex < flight_count)
{
listCustomers(flightIndex);
}
else
{
cout << "Invalid flight index.\n";
getch();
}
}
break;
case 7:
cout << "Enter flight index to update customer: ";
cin >> flightIndex;
cin.ignore();
if (flightIndex >= 0 && flightIndex < flight_count)
{
updateCustomer(flightIndex);
}
else
{
cout << "Invalid flight index.\n";
}
getch();
break;

case 8:
break;
default:
cout << "Invalid choice.\n";
getch();
break;
}
} while (flightChoice != 8);
}
else if (mainChoice == 4)
{
int weatherChoice;
do
{
system("cls");
cout << " __ __ ___ _______ __ ___________ __
__ _______ _______ ___ ___ _______ _____ ___ ____ ____ \
n";
cout << " |\" |/ \\| \"| /\" \"| /\"\"\\ (\" _
\") /\" | | \"\\ /\" \"| /\" \\ |\" \\ /\" | /\" \"| (\\\"
\\|\" \\ |\" _||_ \" | \n";
cout << " |' / \\: |(: ______) / \\ )__/ \\\\__/ (:
(__) :) (: ______)|: | \\ \\ // |(: ______) |.\\\\ \\ | | |
| : | \n";
cout << " |: /' | \\/ | /' /\\ \\ \\\\
_ / \\/ \\/ \\/ | |_____/ ) /\\\\ \\/. | \\/ | |: \\.
\\\\ | |: | | . | \n";
cout << " \\// /\\' | // ___)_ // __' \\ |. | //
__ \\\\ // ___)_ // / |: \\. | // ___)_ |. \\ \\. | | |
| | \n";
cout << " / / \\\\ |(: \"| / / \\\\ \\ \\: |
(: ( ) :) (: \"||: __ \\ |. \\ /: |(: \"| | \\ \\
| \\ \\__/ / \n";
cout << " |___/ \\___| \\_______) (___/ \\___) \\
__| \\__| |__/ \\_______)|__| \\___) |___|\\__/|___| \\_______) \\___|\\
____\\) \\_______/ \n";
cout << "
\n";
cout << " " << endl;
cout <<
" ,---------------------------------------------------------------------
---------------------------------------------," << endl;
cout << " | 1. Add Weather Condition
2. List Weather Conditions |" << endl;
cout << " | 3. Delete Weather
Conditions 4. Update Weather Conditions |" <<
endl;
cout << " | 5. Check Weather
Suitability 6. Back to Main Menu |"
<< endl;
cout << " \\
___________________________________________________________________________________
________________________________/" << endl;
cout << " ->->->->->->->->->->->->->->->->->->->->->->->->->->->->-
>->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->->-
>->->->->-" << endl;
do
{
cout << "[Enter your choice] ";
cin >> weatherChoice;
if (weatherChoice < 1 && weatherChoice > 6)
cout << "Please Enter a valid choice.";
} while (weatherChoice < 1 && weatherChoice > 6);
cin.ignore();

switch (weatherChoice)
{
case 1:
addWeatherCondition(weather_dates, weather_windSpeed,
weather_visibility, weather_count);
getch();
break;
case 2:
listWeather(weather_dates, weather_windSpeed,
weather_visibility, weather_count);
getch();
break;
case 3:
deleteWeather(weather_dates, weather_windSpeed,
weather_visibility, weather_count);
getch();
break;
case 4:
updateWeather(weather_dates, weather_windSpeed,
weather_visibility, weather_count);
getch();
break;
case 5:
checkWeatherSuitability(weather_count, weather_dates,
weather_windSpeed, weather_visibility);
getch();
break;
case 6:
break;
default:
cout << "Invalid choice.Please select a valid option.\n";
}
} while (weatherChoice != 6);
}
else if (mainChoice == 5)
{
cout << "Exiting program...\n";
}

else
{
cout << "Invalid choice. Try again.\n";
}
} while (mainChoice != 5);

return 0;
}

//validations

bool isValidTime(const string &time)


{
if (time.length() != 5 || time[2] != ':')
{
return false;
}
int hours = (time[0] - '0') * 10 + (time[1] - '0');
int minutes = (time[3] - '0') * 10 + (time[4] - '0');
if (hours < 0 || hours > 23 || minutes < 0 || minutes > 59)
{
return false;
}
return true;
}
bool isValidDate(const string &date)
{
if (date.length() != 10 || date[2] != '/' || date[5] != '/')
{
return false;
}
int day = (date[0] - '0') * 10 + (date[1] - '0');
int month = (date[3] - '0') * 10 + (date[4] - '0');
int year = (date[6] - '0') * 1000 + (date[7] - '0') * 100 + (date[8] - '0') *
10 + (date[9] - '0');
if (month < 1 || month > 12)
{
return false;
}
bool isLeapYear = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month
== 10 || month == 12)
{
if (day < 1 || day > 31)
{
return false;
}
}
else if (month == 4 || month == 6 || month == 9 || month == 11)
{
if (day < 1 || day > 30)
{
return false;
}
}
else if (month == 2)
{
if ((isLeapYear && (day < 1 || day > 29)) || (!isLeapYear && (day < 1 ||
day > 28)))
{
return false;
}
}
return true;
}
bool isValidEmail(const string &email)
{
int atCount = 0;
bool dotAfterAt = false;

for (int i = 0; email[i] != '\0'; i++)


{
if (email[i] == '@')
atCount++;
if (atCount == 1 && email[i] == '.')
dotAfterAt = true;
}

return atCount == 1 && dotAfterAt;


}
bool isValidPhoneNumber(const string &phone)
{
int length = 0;

for (int i = 0; phone[i] != '\0'; i++)


{
if (i == 0 && phone[i] == '+')
continue;
if (phone[i] < '0' || phone[i] > '9')
return false;
length++;
}

return length >= 10 && length <= 11;


}
bool noDigits(const string &input)
{
for (char c : input)
{
if (isdigit(c))
{
return true;
}
}
return false;
}
bool isNumeric(const string &input)
{
for (char c : input)
{
if (!isdigit(c))
{
return false;
}
}
return !input.empty();
}
bool isValidInput(bool isValid, string inputStr,int &input) {
// Validate that the input is numeric
isValid = true;

for (int i = 0; i < inputStr.length(); i++) {


if (inputStr[i] < '0' || inputStr[i] > '5') {
isValid = false; // Non-digit character found
break;
}
}

}
//file handling functions
void loadAirHostessesFromFile(string airHostesses[], string duty_start_times[],
string duty_end_times[], string air_hostess_employee_ids[], int &air_hostess_count)
{
ifstream infile("airhostess.txt");
if (infile)
{
while (getline(infile, airHostesses[air_hostess_count]))
{
getline(infile, duty_start_times[air_hostess_count]);
getline(infile, duty_end_times[air_hostess_count]);
getline(infile, air_hostess_employee_ids[air_hostess_count]);
air_hostess_count++;
}
infile.close();
}
else
{
cout << "Unable to open file for reading.\n";
}
}
void saveAirHostessesToFile(string airHostesses[], string duty_start_times[],
string duty_end_times[], string air_hostess_employee_ids[], int air_hostess_count)
{
ofstream outfile("airhostess.txt");
for (int i = 0; i < air_hostess_count; i++)
{
outfile << airHostesses[i] << ",";
outfile << duty_start_times[i] << ",";
outfile << duty_end_times[i] <<",";
outfile << air_hostess_employee_ids[i] << endl;
}
outfile.close();
}
void loadWeatherData(string weather_dates[], int weather_windSpeed[], int
weather_visibility[], int &weather_count)
{
ifstream inFile("weather.txt", ios::in);
if (!inFile)
{
cout << "Error opening weather file!" << endl;
return;
}

while (inFile >> weather_dates[weather_count] >>


weather_windSpeed[weather_count] >> weather_visibility[weather_count])
{
weather_count++;
}
inFile.close();
}
void saveWeatherData(const string weather_dates[], const int weather_windSpeed[],
const int weather_visibility[], int weather_count)
{
ofstream outFile("weather.txt", ios::out | ios::trunc); // overwrite the file
if (!outFile)
{
cout << "Error opening weather file!" << endl;
return;
}

for (int i = 0; i < weather_count; i++)


{
outFile << weather_dates[i] << " " << weather_windSpeed[i] << " " <<
weather_visibility[i] << endl;
}
outFile.close();
}
void addFlightToFile(const string flight_names[], const string flight_times[], int
flight_count)
{
ofstream flightFile("flights.txt", ios::app);
if (!flightFile)
{
cout << "Error opening file!" << endl;
return;
}
for (int i = 0; i < flight_count; i++)
{
flightFile << flight_names[i] << "," << flight_times[i] << endl;
}
flightFile.close();
}
void saveCustomerDataToFile(int flightIndex, int customerCount, string
customerNames[][MAX_CUSTOMERS_PER_FLIGHT], string customerPhones[]
[MAX_CUSTOMERS_PER_FLIGHT], string customerEmails[][MAX_CUSTOMERS_PER_FLIGHT])
{
// Open the file in append mode
ofstream file("customers.txt", ios::app);

if (!file.is_open())
{
cout << "Error: Unable to open file.\n";
return;
}

file << "Flight Index: " << flightIndex + 1 << "\n";


file << "Index\tCustomer Name\t\tPhone\t\tEmail\n";
for (int i = 0; i < customerCount; i++)
{
file << i + 1 << "\t" << customerNames[flightIndex][i] << "\t\t"
<< customerPhones[flightIndex][i] << "\t"
<< customerEmails[flightIndex][i] << "\n";
}
file.close();
cout << "Customer data saved to file successfully.\n";
}

You might also like