
Patrick B. answered 12/29/20
Math and computer tutor/teacher
This solution I offer is for the "FLIGHT INFO. SYSTEM" that you had posted....
I have also posted some source code for the hotel info. system for another student.
----------------------------------------------------------------------------------------------------------------------
/******************************
FLIGHT INFORMATION SYSTEM
*******************************/
using namespace std;
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define GATE_STR_LEN (6)
#define TIME_STR_LEN (6)
#define CITY_STR_LEN (55)
typedef enum _FlightStatus
{
FLIGHT_STATUS_CANCELLED=-1,
FLIGHT_STATUS_ON_TIME,
FLIGHT_STATUS_DELAYED
} TFlightStatus;
class Flight
{
protected:
char gate[GATE_STR_LEN ];
char time[TIME_STR_LEN];
char city[CITY_STR_LEN];
int flightNum;
public:
Flight( int num)
{
flightNum = num;
memset(gate,0,GATE_STR_LEN);
memset(time,0,TIME_STR_LEN);
memset(city,0,CITY_STR_LEN);
}
Flight(Flight & flight)
{
memcpy(this->gate,flight.gate,GATE_STR_LEN);
memcpy(this->time,flight.time,TIME_STR_LEN);
memcpy(this->city,flight.city,CITY_STR_LEN);
this->flightNum = flight.flightNum;
}
int GetFlightNum() { return(flightNum); }
char * GetGate( char * gateBuff) { memcpy(gateBuff,gate,GATE_STR_LEN); return(gateBuff); }
char * GetTime( char * timeBuff) { memcpy(timeBuff,time,TIME_STR_LEN); return(timeBuff); }
char * GetCity( char * cityBuff) { memcpy(cityBuff,city,CITY_STR_LEN); return(cityBuff); }
void SetGate(char * gateBuff) { memcpy(gate,gateBuff,GATE_STR_LEN); }
void SetTime(char * timeBuff) { memcpy(time,timeBuff,TIME_STR_LEN); }
void SetCity(char * cityBuff) { memcpy(city,cityBuff,CITY_STR_LEN); }
};
class OnTimeFlight: public Flight
{
protected:
TFlightStatus flightStatus;
public:
OnTimeFlight( int flightNum) : Flight(flightNum)
{
flightStatus = FLIGHT_STATUS_ON_TIME;
}
TFlightStatus GetFlightStatus() { return(flightStatus); }
};
class CancelledFlight: public Flight
{
protected:
TFlightStatus flightStatus;
public:
CancelledFlight( int flightNum) : Flight(flightNum)
{
flightStatus = FLIGHT_STATUS_CANCELLED;
}
TFlightStatus GetFlightStatus() { return(flightStatus); }
};
class DelayedFlight: public Flight
{
protected:
TFlightStatus flightStatus;
public:
DelayedFlight( int flightNum) : Flight(flightNum)
{
flightStatus = FLIGHT_STATUS_DELAYED;
}
TFlightStatus GetFlightStatus() { return(flightStatus); }
};
Flight * ParseFlightInfo( char* flightInfoBuff, TFlightStatus * flightStatusReturn)
{
int flightNum;
char gateStrBuff[GATE_STR_LEN];
char timeBuff[TIME_STR_LEN];
char cityBuff[CITY_STR_LEN];
TFlightStatus flightStatus;
char tokenBuff[255];
memset(tokenBuff,0,255);
strcpy(tokenBuff,strtok(flightInfoBuff,","));
flightNum = atoi(tokenBuff);
memset(tokenBuff,0,255);
strcpy(gateStrBuff,strtok(NULL,","));
memset(tokenBuff,0,255);
strcpy(timeBuff,strtok(NULL,","));
memset(tokenBuff,0,255);
strcpy(cityBuff,strtok(NULL,","));
memset(tokenBuff,0,255);
strcpy(tokenBuff,strtok(NULL,","));
Flight * flightReturn=NULL;
switch (atoi(tokenBuff))
{
case -1:
{
flightReturn= new CancelledFlight(flightNum) ;
*flightStatusReturn = FLIGHT_STATUS_CANCELLED;
break;
}
case 0:
{
flightReturn = new OnTimeFlight(flightNum);
*flightStatusReturn = FLIGHT_STATUS_ON_TIME;
break;
}
case 1:
{
flightReturn = new DelayedFlight(flightNum);
*flightStatusReturn = FLIGHT_STATUS_DELAYED;
break;
}
}
flightReturn->SetGate(gateStrBuff);
flightReturn->SetTime(timeBuff);
flightReturn->SetCity(cityBuff);
return(flightReturn);
}
void DisplayFlightInfo( Flight * flight, TFlightStatus flightStatus)
{
char outbuff[255];
char flightStatusBuff[25];
char gateBuff[GATE_STR_LEN];
char timeBuff[TIME_STR_LEN];
char cityBuff[CITY_STR_LEN];
switch (flightStatus)
{
case FLIGHT_STATUS_CANCELLED:
{
strcpy(flightStatusBuff,"CANCELLED");
break;
}
case FLIGHT_STATUS_ON_TIME:
{
strcpy(flightStatusBuff,"ON TIME");
break;
}
case FLIGHT_STATUS_DELAYED:
{
strcpy(flightStatusBuff,"DELAYED");
break;
}
}
sprintf(outbuff,"%d %s %s %s %s",flight->GetFlightNum(),
flight->GetGate(gateBuff),
flight->GetTime(timeBuff),
flight->GetCity(cityBuff),
flightStatusBuff);
cout << outbuff << endl;
}
Go()
{
char * flightInfo[] = { (char *) "123,240B,16:45,Orlando,-1",
(char *) "321,245C,16:52,Orlando,0",
(char *) "423,256A,16:49,Orlando,1"
};
for (int iLoop=0; iLoop<3; iLoop++)
{
char flightInfoBuff[100];
TFlightStatus flightStatus;
strcpy(flightInfoBuff,flightInfo[iLoop]);
Flight * flight = ParseFlightInfo(flightInfoBuff,&flightStatus);
DisplayFlightInfo(flight,flightStatus);
}
};
int main()
{
Go();
}
Malik U.
Can you please send me the source code for hotel management system .12/29/20
Malik U.
I checked that student answer but the link to the source code was not available to me so kindly if you can send me the link here12/29/20
Malik U.
kindly if you can guide me how to approach answer of hotel management system because i cannot see the answer12/30/20
Malik U.
Please send me the link to the answer for hotel management system12/30/20

Patrick B.
https://www.wyzant.com/resources/files/729300/c_hotel_project12/31/20

Patrick B.
As I have explained above, this solution posting is for the AIRLINE that you had posted, but it was taken away... you now have the link to the hotel project for which SEVERAL of you have been asking12/31/20
Malik U.
You are adding a different code here sir12/29/20