jude
March 25th, 2003, 02:14 AM
I am a novice in C++ and I am really interested to learn it more.I tried to write a program on flight timetable(for fun) which help travellers to plan their flight according to their preferences such as shortest flight, cheapest flight as well as be able to check for delay and cancel flights.Here are my program code so far.I would appreciate if you can comments on my program, so that it be more flexible or be declared in proper way.Thanks for your comments.This program is not completely finish yet as I am having some difficulties in how to declare/distinguish cheapest flight(first class,economy class etc) and shortest flight(direct/transit flight).Please advice.
#include <iostream.h>
#include <string.h>
const int max = 30;
int menu();
void price_search();
void time_search();
struct flight
{
char departure[max];
char arrival[max];
//char carrier[max];
char day[10];
char deptime[8];
};
struct AirportCode
{
char code1[max];
char code2[max];
};
struct new_airport
{
AirportCode name;
flight detail;
};
new_airport array[max];
void read(int b, char code1[], //This function denotes the
char code2[], char departure[], //information available to the
char arrival[], char day[], char deptime[]) //user.
{
strcpy (array[b].name.code1, code1);
strcpy (array[b].name.code2,
code2);
strcpy (array[b].detail.departure, departure);
strcpy (array[b].detail.arrival, arrival);
strcpy (array[b].detail.day, day);
strcpy (array[b].detail.deptime, deptime);
}
void flight(new_airport array[], //This function finds the
char ori[], char dest[]) //address for the requested
{ //person and prints it out.
int fail = 0;
for (int b = 0; b < 10; b++)
{
if ((strcmp (ori,
array[b].name.code1) == 0) &&
(strcmp (dest,
array[b].name.code2) == 0))
{
cout << endl << "Departure: "
<< ori << endl
<< "Destination: "
<< dest << endl
<< "Flight details: "
<< array[b].detail.departure
<< " TO "
<< array[b].detail.arrival
<< ", "
<< array[b].detail.day
<< " "
<< array[b].detail.deptime
<< endl << endl;
fail = 1;
}
}
if (fail == 0)
cout << "Sorry, Flight is not listed."
<< endl;
}
main()
{
int choice = 0;
read(0,"KUL", "JPN", "KUALA LUMPUR MALAYSIA ", //Here, the information about
"TOKYO JAPAN", "MH456","8:15am"); //each FLIGHT is encoded.
read(1,"KUL", "JPN", "KUALA LUMPUR MALAYSIA ",
"TOKYO JAPAN", "JPN6700","9:45am");
read(2, "IND", "PHI", "JAKARTA INDONESIA ",
"MANILA PHILIPPINES", "INA1233","13:15pm");
read(3, "PHI", "INA", "MANILA PHILIPPINES",
"JAKARTA INDONESIA", "PH401","22:05");
read(4, "SIN", "PHI", "CHANGGI SINGAPORE ",
"MANILA PHILIPPINES", "SIN0095","07:55");
read(5, "KUL", "PHI", "KUALA LUMPUR MALAYSIA",
"MANILA PHILIPPINES", "MH8900","09:40");
read(6, "THI", "PHI", "BANGKOK THAILAND",
"MANILA PHILIPPINES", "TH1400","18:20");
read(7, "PHI", "THI", "MANILA PHILIPPINES",
"BANGKOK THAILAND", "PHL433","19:10");
while (choice !=3) //Check char input as invalid!!
{
choice=menu();
switch(choice)
{
case 1: price_search();
break;
case 2: time_search();
break;
case 3: cout<<"Thank you."<<endl<<endl;
break;
default: cout <<"Invalid Choice."<<endl<<endl;
break;
}
}
}
int menu()
{
int choice=0;
cout<<"What would you like to do?"<<endl
<<" 1= Search for the cheapest flight"<<endl
<<" 2= Search for the shortest flight"<<endl
<<" 3= Quit"<<endl<<endl;
cout<<" >> ";
cin>>choice;
return choice;
}
void price_search()
{
char ori[max];
char dest[max];
cout<<"Enter the airport code\n";
cout<< "Departure from"
<< " ?" << endl;
cout<<" KUL - KUALA LUMPUR \n";
cout<<" JPN - TOKYO\n";
cout<<" MAN - MANILA\n";
cout<<" HKG - HONG KONG\n";
cout<<" THI - BANGKOK\n";
cout<<" IND - JAKARTA\n";
cout<<" SIN - SINGAPORE\n";
cout<<" BRN - SERI BEGAWAN\n";
cout<<" CHN - CHINA\n";
cout<<" >> ";
cin >> ori;
cout << endl << "Your destination is"
<< " ?" << endl;
cout<<" KUL - KUALA LUMPUR \n";
cout<<" JPN - TOKYO\n";
cout<<" MAN - MANILA\n";
cout<<" HKG - HONG KONG\n";
cout<<" THI - BANGKOK\n";
cout<<" IND - JAKARTA\n";
cout<<" SIN - SINGAPORE\n";
cout<<" BRN - SERI BEGAWAN\n";
cout<<" CHN - CHINA\n";
cout<<" >> ";
cin >> dest;
flight(array, ori,
dest);
}
void time_search()
{
//code would be the same as price_search except for returning flight with shortest path taken.
}
#include <iostream.h>
#include <string.h>
const int max = 30;
int menu();
void price_search();
void time_search();
struct flight
{
char departure[max];
char arrival[max];
//char carrier[max];
char day[10];
char deptime[8];
};
struct AirportCode
{
char code1[max];
char code2[max];
};
struct new_airport
{
AirportCode name;
flight detail;
};
new_airport array[max];
void read(int b, char code1[], //This function denotes the
char code2[], char departure[], //information available to the
char arrival[], char day[], char deptime[]) //user.
{
strcpy (array[b].name.code1, code1);
strcpy (array[b].name.code2,
code2);
strcpy (array[b].detail.departure, departure);
strcpy (array[b].detail.arrival, arrival);
strcpy (array[b].detail.day, day);
strcpy (array[b].detail.deptime, deptime);
}
void flight(new_airport array[], //This function finds the
char ori[], char dest[]) //address for the requested
{ //person and prints it out.
int fail = 0;
for (int b = 0; b < 10; b++)
{
if ((strcmp (ori,
array[b].name.code1) == 0) &&
(strcmp (dest,
array[b].name.code2) == 0))
{
cout << endl << "Departure: "
<< ori << endl
<< "Destination: "
<< dest << endl
<< "Flight details: "
<< array[b].detail.departure
<< " TO "
<< array[b].detail.arrival
<< ", "
<< array[b].detail.day
<< " "
<< array[b].detail.deptime
<< endl << endl;
fail = 1;
}
}
if (fail == 0)
cout << "Sorry, Flight is not listed."
<< endl;
}
main()
{
int choice = 0;
read(0,"KUL", "JPN", "KUALA LUMPUR MALAYSIA ", //Here, the information about
"TOKYO JAPAN", "MH456","8:15am"); //each FLIGHT is encoded.
read(1,"KUL", "JPN", "KUALA LUMPUR MALAYSIA ",
"TOKYO JAPAN", "JPN6700","9:45am");
read(2, "IND", "PHI", "JAKARTA INDONESIA ",
"MANILA PHILIPPINES", "INA1233","13:15pm");
read(3, "PHI", "INA", "MANILA PHILIPPINES",
"JAKARTA INDONESIA", "PH401","22:05");
read(4, "SIN", "PHI", "CHANGGI SINGAPORE ",
"MANILA PHILIPPINES", "SIN0095","07:55");
read(5, "KUL", "PHI", "KUALA LUMPUR MALAYSIA",
"MANILA PHILIPPINES", "MH8900","09:40");
read(6, "THI", "PHI", "BANGKOK THAILAND",
"MANILA PHILIPPINES", "TH1400","18:20");
read(7, "PHI", "THI", "MANILA PHILIPPINES",
"BANGKOK THAILAND", "PHL433","19:10");
while (choice !=3) //Check char input as invalid!!
{
choice=menu();
switch(choice)
{
case 1: price_search();
break;
case 2: time_search();
break;
case 3: cout<<"Thank you."<<endl<<endl;
break;
default: cout <<"Invalid Choice."<<endl<<endl;
break;
}
}
}
int menu()
{
int choice=0;
cout<<"What would you like to do?"<<endl
<<" 1= Search for the cheapest flight"<<endl
<<" 2= Search for the shortest flight"<<endl
<<" 3= Quit"<<endl<<endl;
cout<<" >> ";
cin>>choice;
return choice;
}
void price_search()
{
char ori[max];
char dest[max];
cout<<"Enter the airport code\n";
cout<< "Departure from"
<< " ?" << endl;
cout<<" KUL - KUALA LUMPUR \n";
cout<<" JPN - TOKYO\n";
cout<<" MAN - MANILA\n";
cout<<" HKG - HONG KONG\n";
cout<<" THI - BANGKOK\n";
cout<<" IND - JAKARTA\n";
cout<<" SIN - SINGAPORE\n";
cout<<" BRN - SERI BEGAWAN\n";
cout<<" CHN - CHINA\n";
cout<<" >> ";
cin >> ori;
cout << endl << "Your destination is"
<< " ?" << endl;
cout<<" KUL - KUALA LUMPUR \n";
cout<<" JPN - TOKYO\n";
cout<<" MAN - MANILA\n";
cout<<" HKG - HONG KONG\n";
cout<<" THI - BANGKOK\n";
cout<<" IND - JAKARTA\n";
cout<<" SIN - SINGAPORE\n";
cout<<" BRN - SERI BEGAWAN\n";
cout<<" CHN - CHINA\n";
cout<<" >> ";
cin >> dest;
flight(array, ori,
dest);
}
void time_search()
{
//code would be the same as price_search except for returning flight with shortest path taken.
}