Oop Project File
Oop Project File
Oop Project File
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
class Schedule {
private:
struct Entry {
string flightNumber;
string departureTime;
string arrivalTime;
Entry(const string& flightNumber, const string& departureTime, const
string& arrivalTime)
: flightNumber(flightNumber), departureTime(departureTime),
arrivalTime(arrivalTime) {}
};
vector<Entry> entries;
string filename;
public:
Schedule(const string& filename) : filename(filename) {
readScheduleFromFile();
}
void add_Entry(const string& flightNumber, const string& departureTime, const
string& arrivalTime) {
entries.push_back(Entry(flightNumber, departureTime, arrivalTime));
writeScheduleToFile();
}
void remove_Entry(const string& flightNumber) {
for (auto it = entries.begin(); it != entries.end(); ++it) {
if (it->flightNumber == flightNumber) {
entries.erase(it);
writeScheduleToFile();
break;
}
}
}
void display_schedule() const {
cout << "Flight Schedule:\n";
for (const auto& entry : entries) {
cout << "Flight Number: " << entry.flightNumber << "\n";
cout << "Departure Time: " << entry.departureTime << "\n";
cout << "Arrival Time: " << entry.arrivalTime << "\n\n";
}
}
string getFilename() const { return filename; }
private:
void readScheduleFromFile() {
ifstream inFile(filename);
if (inFile.is_open()) {
string flightNumber, departureTime, arrivalTime;
while (inFile >> flightNumber >> departureTime >> arrivalTime) {
entries.push_back(Entry(flightNumber, departureTime, arrivalTime));
}
inFile.close();
} else {
cout << "Unable to open schedule file.\n";
}
}
void writeScheduleToFile() {
ofstream outFile(filename);
if (outFile.is_open()) {
for (const auto& entry : entries) {
outFile << entry.flightNumber << " " << entry.departureTime << " "
<< entry.arrivalTime << "\n";
}
outFile.close();
} else {
cout << "Unable to open schedule file for writing\n";
}
}
};
class Inventory {
private:
struct Item {
string name;
int stockLevel;
bool available;
string location;
Item(const string& name, int stockLevel, bool available, const string&
location)
: name(name), stockLevel(stockLevel), available(available),
location(location) {}
};
vector<Item> items;
vector<string> passengerSelections;
public:
void manageInventory() {
cout << "Managing inventory..." << endl;
}
void add_item(const string& item, int stockLevel, bool available, const string&
location) {
items.push_back(Item(item, stockLevel, available, location));
}
void remove_item(const string& item) {
for (auto it = items.begin(); it != items.end(); ++it) {
if (it->name == item) {
items.erase(it);
break;
}
}
}
int get_Stock_Level(const string& item) const {
for (const auto& i : items) {
if (i.name == item) {
return i.stockLevel;
}
}
return -1;
}
void get_Item_Details(const string& itemName) const {
for (const auto& i : items) {
if (i.name == itemName) {
cout << "Item Name: " << i.name << ", " << "Stock Level: " <<
i.stockLevel << ", " << "Availability: " << (i.available ? "Available" : "Not
Available") << ", " << "Location: " << i.location << endl;
return;
}
}
cout << "Item not found." << endl;
}
void addPassengerSelection(const string& itemName) {
cout << "Please select the category of items you want to include:\n";
cout << "1. Beverages\n";
cout << "2. Snacks\n";
cout << "3. Meals\n";
cout << "4. Additional items (Mask, Handfrees etc)\n";
int choice;
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1: {
cout << "You have selected Beverages.\n";
cout << "Available beverages:\n";
// Display a list of available beverages
cout << "1. Water\n";
cout << "2. Soda\n";
cout << "3. Juice\n";
break;
}
case 2: {
cout << "You have selected Snacks.\n";
cout << "Available snacks:\n";
// Display a list of available snacks
cout << "1. Chips\n";
cout << "2. Cookies\n";
cout << "3. Nuts\n";
break;
}
case 3: {
cout << "You have selected Meals.\n";
cout << "Available meals:\n";
// Display a list of available meals
cout << "1. Sandwich\n";
cout << "2. Salad\n";
cout << "3. Pasta\n";
break;
}
case 4: {
cout << "You have selected Additional items.\n";
cout << "Available additional items:\n";
// Display a list of available additional items
cout << "1. Mask\n";
cout << "2. Hand sanitizers\n";
cout << "3. Earphones\n";
break;
}
default:
cout << "Invalid choice. Please select from 1 to 4.\n";
return;
}
int numItems;
cout << "Enter the number of items you want to add: ";
cin >> numItems;
void notifyCrew() {
cout << "Passenger selections: ";
for (const auto& item : passengerSelections) {
cout << item << ", ";
}
cout << endl;
}
};
class Maintenance {
protected:
int maintenanceID;
int aircraftID;
string scheduledDate;
string maintenanceType;
bool completed;
bool reported;
public:
Maintenance(const int& maintenanceID, const int& aircraftID,
const string& scheduledDate, const string& maintenanceType)
: maintenanceID(maintenanceID), aircraftID(aircraftID),
scheduledDate(scheduledDate), maintenanceType(maintenanceType),
completed(false), reported(false) {}
void performMaintenance() {
cout << "Performing maintenance tasks..." << endl;
}
void handle_Maintenance_report(const string& newMaintenanceID) {
maintenanceID = stoi(newMaintenanceID);
reported = true;
cout << "Maintenance report with ID " << maintenanceID << " is being
handled.\n";
updateMaintenanceRecordsToFile();
}
void complete_Maintenance() {
completed = true;
cout << "Maintenance task for aircraft " << aircraftID << " completed.\n";
updateMaintenanceRecordsToFile();
}
void updateMaintenanceRecordsToFile() {
ofstream outFile("maintenance_records.txt", ios::app);
if (outFile.is_open()) {
outFile << "Maintenance ID: " << maintenanceID << ", Aircraft ID: " <<
aircraftID
<< ", Scheduled Date: " << scheduledDate << ", Maintenance
Type: " << maintenanceType
<< ", Completed: " << (completed ? "Yes" : "No") << ",
Reported: " << (reported ? "Yes" : "No")
<< endl;
outFile.close();
cout << "Maintenance records updated.\n";
} else {
cout << "Unable to open file.\n";
}
}
void setMaintenanceIDFromUser() {
cout << "Enter maintenance ID: ";
cin >> maintenanceID;
}
void setAircraftIDFromUser() {
cout << "Enter aircraft ID: ";
cin >> aircraftID;
}
void setScheduledDateFromUser() {
cout << "Enter scheduled date: ";
cin >> scheduledDate;
}
void setMaintenanceTypeFromUser() {
cout << "Enter maintenance type: ";
cin >> maintenanceType;
}
void setCompletedFromUser() {
cout << "Is maintenance completed? (1 for yes, 0 for no): ";
cin >> completed;
}
void setReportedFromUser() {
cout << "Is maintenance reported? (1 for yes, 0 for no): ";
cin >> reported;
}
int getMaintenanceID() const { return maintenanceID; }
int getAircraftID() const { return aircraftID; }
string getScheduledDate() const { return scheduledDate; }
string getMaintenanceType() const { return maintenanceType; }
bool isCompleted() const { return completed; }
bool isReported() const { return reported; }
};
class User {
protected:
string username;
string password;
string role;
public:
User(const string& username, const string& password, const string& role)
: username(username), password(password), role(role) {}
string getUsername() const { return username; }
string getPassword() const { return password; }
string getRole() const { return role; }
void setUsername(const string& newUsername) { username = newUsername; }
void setPassword(const string& newPassword) { password = newPassword; }
void setRole(const string& newRole) { role = newRole; }
virtual void login() = 0;
virtual void signup() = 0;
};
setRole(role);
cout << "Signup successful!\n";
}
};
~Admin() {
delete maintenance;
delete inventory;
}
void performMaintenance() {
maintenance->performMaintenance();
}
void completeMaintenance() {
maintenance->complete_Maintenance();
}
void updateMaintenanceRecordsToFile() {
maintenance->updateMaintenanceRecordsToFile();
}
Admin* operator*() {
return this;
}
Crew* operator*() {
return this;
}
// Setters
void setUsername(const string& username) { this->username = username; }
void setCrewID(int id) { crewID = id; }
void setCertificate(const string& c) { certification = c; }
void setLicenseNumber(const string& l) { licenseNumber = l; }
void setWorkedHours(const double& hw) { hoursWorked=hw;}
// Getters
int getCrewID() const { return crewID; }
string getCertification() const { return certification; }
bool getAvailability() const { return availability; }
string getLicenseNumber() const { return licenseNumber; }
};
int main() {
int choice;
string currentUser;
vector<Admin*> admins;
vector<Crew*> crews;
Schedule schedule("filename.txt");
while (true) {
cout << "****Welcome to our Airline System****" << endl;
cout << "1. Login" << endl;
cout << "2. If you are new,please Sign Up" << endl;
cout << "3. Exit" << endl;
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1: {
string role;
cout << "Enter Role (Admin/Crew): ";
cin >> role;
if (role == "Admin") {
string un, name, pass, ci, sd, mt;
int mid, aid;
cout << "Enter Username: ";
cin >> un;
cout << "Enter Password: ";
cin >> pass;
cout << "Enter Name: ";
cin >> name;
cout << "Enter Contact Info: ";
cin >> ci;
Admin* admin = new Admin(mid, aid, sd, mt, un, pass, name, ci);
if (admin->validateLogin(un, pass)) {
admin->login();
admins.push_back(admin);
currentUser = admin->getUsername();
currentUser = role;
} else {
cout << "Invalid username or password." << endl;
delete admin; // Clean up memory
}
break;
}
else if (role == "Crew") {
string nu, cert, name, ci, li, sf, pass;
int id;
double wh;
cout << "Enter Username: ";
cin >> nu;
cout << "Enter role: ";
cin >> role;
cout << "Enter password: ";
cin >> pass;
cout << "Enter name: ";
cin >> name;
cout << "Enter contact: ";
cin >> ci;
cout << "Enter certificate: ";
cin >> cert;
cout << "Enter licence: ";
cin >> li;
cout << "Enter work hours: ";
cin >> wh;
Crew* crew = new Crew(nu, pass, name, ci, id, cert, li, sf,
wh);
if (crew->validateLogin(nu, pass)) {
crew->login();
crews.push_back(crew);
currentUser = crew->getUsername();
currentUser = role;
} else {
cout << "Invalid username or password." << endl;
delete crew; // Clean up memory
}
} else {
cout << "Invalid role!" << endl;
}
break;
}
case 2: {
string role;
cout << "Enter Role (Admin/Crew): ";
cin >> role;
if (role == "Admin") {
string un, name, pass, ci, sd, mt;
int mid, aid;
cout << "Enter Username: ";
cin >> un;
cout << "Enter Password: ";
cin >> pass;
cout << "Enter Name: ";
cin >> name;
cout << "Enter Contact Info: ";
cin >> ci;
Admin* admin = new Admin(mid, aid, sd, mt, un, pass, name, ci);
admin->signup();
admins.push_back(admin);
currentUser = admin->getUsername();
currentUser = role;
} else if (role == "Crew") {
string nu, cert, name, ci, li, sf, pass;
int id;
double wh;
cout << "Enter Username: ";
cin >> nu;
Crew* crew = new Crew(nu, pass, name, ci, id, cert, li, sf,
wh);
crew->signup();
crews.push_back(crew);
currentUser = crew-> getUsername();
currentUser = role;
} else {
cout << "Invalid role!" << endl;
}
break;
}
case 3: {
cout << "Exiting..." << endl;
return 0;
}
default:
cout << "Invalid choice, please try again." << endl;
}
// After successful login or signup
if (currentUser != "") {
cout << "Welcome, " << currentUser << "!" << endl;
// Admin or Crew specific menu based on role
while (true) {
string username, password, name, contactInfo;
cout << "Enter username: ";
cin >> username;
cout << "Enter password: ";
cin >> password;
cout << "Enter name: ";
cin >> name;
cout << "Enter contact info: ";
cin >> contactInfo;
if (currentUser == "Admin") {
// Admin menu
cout << "Admin Menu:" << endl;
cout << "1. Manage Employees" << endl;
cout << "2. View Employee Details" << endl;
cout << "3. View Financial Reports" << endl;
cout << "4. Manage Maintenance" << endl;
cout << "5. Manage Inventory" << endl;
cout << "6. Logout" << endl;
cout << "Enter your choice: ";
cin >> choice;
Admin* admins;
switch (choice) {
case 1: {
cout << "1. Add Employee" << endl;
cout << "2. Remove Employee" << endl;
cout << "3. Update Employee" << endl;
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1: {
// Create an Employee object using the provided
information
Employee emp(username, password, name, contactInfo);
break;
}
case 2:{
string usernameToRemove;
cout << "Enter username of the employee to remove: ";
cin >> usernameToRemove;
admins[0].remove_Employee(usernameToRemove);
break;
}
case 3:
{
string newUsername,newPassword, newName, newContactInfo;
cout << "Enter username of the employee to update: ";
cin >> newUsername;
cout << "Enter password of the employee to update: ";
cin >> newPassword;
cout << "Enter username of the employee to update: ";
cin >> newName;
cout << "Enter username of the employee to update: ";
cin >> newContactInfo;
Employee updatedEmployee(newUsername, newPassword, newName,
newContactInfo);
admins[0].update_Employee(newUsername, updatedEmployee);
break;
}
default:
cout << "Invalid choice, please try again." <<
endl;
break;
}
case 2: {
(*admins[0])->view_Employee_Details();
break;
}
case 3: {
(*admins[0])->view_Financial_Reports();
break;
}
case 4: {
cout << "Maintenance Menu:" << endl;
cout << "1. Perform Maintenance" << endl;
cout << "2. Handle Maintenance Report" << endl;
cout << "3. Complete Maintenance" << endl;
cout << "4. Update Maintenance Records" << endl;
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1: {
admins[0].performMaintenance();
break;
}
case 2: {
string newMaintenanceID;
cout << "Enter new maintenance ID: ";
cin >> newMaintenanceID;
admins[0].handleMaintenanceReport(newMaintenanceID);
break;
}
case 3: {
admins[0].completeMaintenance();
break;
}
case 4: {
admins[0].updateMaintenanceRecordsToFile();
break;
}
default:
cout << "Invalid choice, please try again." << endl;
break;
}
break; // Add break here to exit case 4
}
// Inside case 5:
case 5: {
cout << "Inventory Menu:" << endl;
cout << "1. Add Item" << endl;
cout << "2. Remove Item" << endl;
cout << "3. Get Stock Level" << endl;
cout << "4. Get Item Details" << endl;
cout << "Enter your choice: ";
cin >> choice;
string item, loc;
int stock;
bool avail;
switch (choice) {
case 1: {
cout << "Following items are available, please select the one you wish
to add: ";
admins[0].addInventoryItem(item, stock, avail, loc);
break;
}
case 2: {
string itemToRemove;
cout << "Enter item to remove: ";
cin >> itemToRemove;
admins[0].removeInventoryItem(itemToRemove);
break;
}
case 3: {
admins[0].getStockLevel(item);
break;
}
case 4: {
admins[0].getItemDetails(item);
break;
}
default:
cout << "Invalid choice, please try again." << endl;
break;
}
}
}
}
}
else if (currentUser == "Crew") {
// Crew menu
cout << "Crew Menu:" << endl;
cout << "1. Assign Crew to Flight" << endl;
cout << "2. Track Work Hours" << endl;
cout << "3. Display Crew Details" << endl;
cout << "4. Assign Certificate" << endl;
cout << "5. Update Schedule" << endl;
cout << "6. Check Fuel Level" << endl;
cout << "7. Check Engine Status" << endl;
cout << "8. Logout" << endl;
cout << "Enter your choice: ";
cin >> choice;
Crew* crews ;
switch (choice) {
case 1: {
(*crews[0]) ->assign_crew_to_flight(schedule);
break;
}
case 2: {
double hours;
cout<<"Enter your worked hours";
(*crews[0]) ->track_work_hours(hours);
break;
}
case 3:{
(*crews[0]) ->display_crew_details();
break;
}
case 4: {
string certificate;
cout << "Enter certificate: ";
cin >> certificate;
(*crews[0]) ->assign_certificate(certificate);
break;
}
case 5: {
string schedule;
cout << "Enter schedule: ";
cin >> schedule;
(*crews[0]) ->update_schedule(schedule);
break;
}
case 6: {
int fuelLevel;
cout << "Enter fuel level: ";
cin >> fuelLevel;
(*crews[0]) ->check_fuel_level(fuelLevel);
break;
}
case 7: {
string engineStatus;
cout << "Enter engine status: ";
cin >> engineStatus;
(*crews[0]) ->check_engine_status(engineStatus);
break;
}
case 8: {
cout << "Logging out..." << endl;
currentUser = "";
break;
}
default:
cout << "Invalid choice, please try again." << endl;
}
}
if (currentUser == "") {
cout<<"Loggout out "<<endl;
}
}
}
}
for (auto admin : admins) {
delete admin;
}
for (auto crew : crews) {
delete crew;
}
return 0;
}