I write a program to c++,for buy bus ticket.
with link list and struct.
my program is bad working,please help me to work better(up to now)?!
and tell how do i write
search and show travels between two dates,
and search and show travels with specified origin and destination in specified date,
in this program.
thanks
Expand|Select|Wrap|Line Numbers
- #include <iostream.h>
- #include <iomanip.h>
- #include <conio.h>
- #include <process.h>
- #include <string.h>
- //-----------------------------------------------------
- //-----------------------------------------------------
- struct Bus
- {
- char* BusID;
- char* Type;
- int SeatNumber;
- };
- //-----------------------------------------------------
- //-----------------------------------------------------
- struct Passenger
- {
- int PassengerID;
- char* Name;
- char* Family;
- char* TellNumber;
- };
- //-----------------------------------------------------
- //-----------------------------------------------------
- struct Date
- {
- int Year;
- int Month;
- int Day;
- };
- //-----------------------------------------------------
- //-----------------------------------------------------
- struct Travel
- {
- char* Origin;
- char* Destination;
- char* BusID;
- Date date;
- bool State ;
- int* Passengers;
- };
- //-----------------------------------------------------
- //-----------------------------------------------------
- struct BuyTicketNode
- {
- Bus bus;
- Passenger passenger;
- Travel travel;
- Date date;
- BuyTicketNode* next;
- };
- //-----------------------------------------------------
- //-----------------------------------------------------
- struct BuyTicketLinkedList
- {
- BuyTicketNode* root;
- };
- //-----------------------------------------------------
- //----------------------------------------------------
- void uiDoAction(BuyTicketLinkedList &);
- char uiMainMenu();
- void uiMainMenuSwitch(char ,BuyTicketLinkedList &);
- char uiBusMenu();
- void uiBusMenuSwitch(char ,BuyTicketLinkedList &);
- void uiEditBus(BuyTicketLinkedList &);
- void uiDeleteBus(BuyTicketLinkedList &);
- void uiDisplayBus(BuyTicketLinkedList &);
- void uiAddBus(BuyTicketLinkedList &);
- void uiSearchByBusID(BuyTicketLinkedList &);
- Bus uiGetBus();
- void AddBus(Bus ,BuyTicketLinkedList &);
- void uiDisplay(Bus bus);
- BuyTicketNode* searchByByBusID(char* ,BuyTicketLinkedList &);
- int countBus(BuyTicketLinkedList &);
- void removeNodeBus(BuyTicketNode* ,BuyTicketLinkedList &);
- void releaseBus(BuyTicketNode*);
- void releaseBus(BuyTicketLinkedList &);
- char uiTravelMenu();
- void uiTravelMenuSwitch(char ,BuyTicketLinkedList &);
- void uiEditTravel(BuyTicketLinkedList &);
- void uiDeleteTravel(BuyTicketLinkedList &);
- void uiDisplayTravel(BuyTicketLinkedList &);
- void uiAddTravel(BuyTicketLinkedList &);
- void uiSearchByBusID(BuyTicketLinkedList &);
- Travel uiGetTravel();
- void AddTravel(Travel ,BuyTicketLinkedList &);
- void uiDisplay(Travel travel);
- BuyTicketNode* searchByByBusID(char* ,BuyTicketLinkedList &);
- int countTravel(BuyTicketLinkedList &);
- void removeNodeTravel(BuyTicketNode* ,BuyTicketLinkedList &);
- void releaseTravel(BuyTicketNode*);
- void releaseTravel(BuyTicketLinkedList &);
- char uiPassengerMenu();
- void uiPassengerMenuSwitch(char ,BuyTicketLinkedList &);
- void uiAddPassenger(BuyTicketLinkedList &);
- void uiDisplayPassenger(BuyTicketLinkedList &);
- void uiSearchByTellNumber(BuyTicketLinkedList &);
- Passenger uiGetPassenger();
- void AddPassenger(Passenger ,BuyTicketLinkedList &);
- void uiDisplay(Passenger passenger);
- BuyTicketNode* searchByByTellNumber(char* ,BuyTicketLinkedList &);
- int countPassenger(BuyTicketLinkedList &);
- /*char uiSearchMenu();
- void uiSearchMenuSwitch(char ,BuyTicketLinkedList &);
- void uiSearchTravelsByDates(BuyTicketLinkedList);
- void uiDisplayTravelsByDates(BuyTicketLinkedList);
- void uiSearchTravelsByPlaces(BuyTicketLinkedList);
- void uiDisplayTravelsByPlaces(BuyTicketLinkedList);*/
- //-----------------------------------------------------
- //-----------------------------------------------------
- int main()
- {
- BuyTicketLinkedList buyTicketLinkedList;
- buyTicketLinkedList.root=NULL;
- uiDoAction(buyTicketLinkedList);
- return 0;
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void uiDoAction(BuyTicketLinkedList &buyTicketLinkedList)
- {
- do
- {
- char mainmenu=uiMainMenu();
- uiMainMenuSwitch(mainmenu,buyTicketLinkedList);
- char busmenu=uiBusMenu();
- uiBusMenuSwitch(busmenu,buyTicketLinkedList);
- char travelmenu=uiTravelMenu();
- uiTravelMenuSwitch(travelmenu,buyTicketLinkedList);
- char passengermenu=uiPassengerMenu();
- uiPassengerMenuSwitch(passengermenu,buyTicketLinkedList);
- /* char searchmenu=uiSearchMenu();
- uiSearchMenuSwitch(searchmenu,buyTicketLinkedList);
- */
- }
- while(true);
- }
- //-----------------------------------------------------
- //-----main menu---------------------------------------
- char uiMainMenu()
- {
- cout << "\n\n================================================\n";
- cout << "Main Menu ======================================\n";
- cout << endl;
- cout << "1> Bus"<<endl;
- cout << "2> Travel"<<endl;
- cout << "3> Passenger"<<endl;
- cout << "4> Search"<<endl;
- cout << "5> Exit"<<endl;
- char mainmenu=getch();
- system("CLS");
- return mainmenu;
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void uiMainMenuSwitch(char selector,BuyTicketLinkedList &buyTicketLinkedList)
- {
- switch(selector)
- {
- case '1':
- uiBusMenu();
- break;
- case '2':
- uiTravelMenu();
- break;
- case '3':
- uiPassengerMenu();
- break;
- /* case '4':
- uiSearchMenu();
- break;*/
- case '5':
- releaseBus(buyTicketLinkedList);
- exit(0);
- break;
- default:
- break;
- }
- }
- //-----------------------------------------------------
- //----------bus menu-----------------------------------
- char uiBusMenu()
- {
- cout << "\n\n================================================\n";
- cout << "Bus Menu ======================================\n";
- cout << endl;
- cout << "1>Add"<<endl;
- cout << "2>Edit"<<endl;
- cout << "3>Delete"<<endl;
- cout << "4>Display"<<endl;
- cout << "5>Go back to main menu"<<endl;
- char busmenu=getch();
- system("CLS");
- return busmenu;
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void uiBusMenuSwitch(char selector,BuyTicketLinkedList &buyTicketLinkedList)
- {
- switch(selector)
- {
- case '1':
- uiAddBus(buyTicketLinkedList);
- break;
- case '2':
- uiEditBus(buyTicketLinkedList);
- break;
- case '3':
- uiDeleteBus(buyTicketLinkedList);
- break;
- case '4':
- uiDisplayBus(buyTicketLinkedList);
- break;
- case '5':
- uiMainMenu();
- break;
- default:
- break;
- }
- }
- //-----------------------------------------------------
- //----------travel menu--------------------------------
- char uiTravelMenu()
- {
- cout << "\n\n================================================\n";
- cout << "TravelMenu ======================================\n";
- cout << endl;
- cout << "1>Add"<<endl;
- cout << "2>Edit"<<endl;
- cout << "3>Delete"<<endl;
- cout << "4>Display"<<endl;
- cout << "5>Go back to main menu"<<endl;
- char travelmenu=getch();
- system("CLS");
- return travelmenu;
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void uiTravelMenuSwitch(char selector,BuyTicketLinkedList &buyTicketLinkedList)
- {
- switch(selector)
- {
- case '1':
- uiAddTravel(buyTicketLinkedList);
- break;
- case '2':
- uiEditTravel(buyTicketLinkedList);
- break;
- case '3':
- uiDeleteTravel(buyTicketLinkedList);
- break;
- case '4':
- uiDisplayTravel(buyTicketLinkedList);
- break;
- case '5':
- uiMainMenu();
- break;
- default:
- break;
- }
- }
- //-----------------------------------------------------
- //---------passenger menu------------------------------
- char uiPassengerMenu()
- {
- cout << "\n\n================================================\n";
- cout << "PassengerMenu ======================================\n";
- cout << endl;
- cout << "1>Add"<<endl;
- cout << "2>Display"<<endl;
- cout << "3>Go back to main menu"<<endl;
- char passengermenu=getch();
- system("CLS");
- return passengermenu;
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void uiPassengerMenuSwitch(char selector,BuyTicketLinkedList &buyTicketLinkedList)
- {
- switch(selector)
- {
- case '1':
- uiAddPassenger(buyTicketLinkedList);
- break;
- case '2':
- uiDisplayPassenger(buyTicketLinkedList);
- break;
- case '3':
- uiMainMenu();
- break;
- default:
- break;
- }
- }
- //-----------------------------------------------------
- //-------search menu-----------------------------------
- /*
- char uiSearchMenu()
- {
- cout << "\n\n================================================\n";
- cout << "PassengerMenu ======================================\n";
- cout << endl;
- cout << "1> Search travels between two dates"<<endl;
- cout << "2> Display travels between two dates"<<endl;
- cout << "3> Search travels with specified origin and destination in specified date"<<endl;
- cout << "4> Display travels with specified origin and destination in specified date"<<endl;
- cout << "5>Go back to main menu"<<endl;
- char searchmenu=getch();
- system("CLS");
- return searchmenu;
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void uiSearchMenuSwitch(char selector,BuyTicketLinkedList &buyTicketLinkedList)
- {
- switch(selector)
- {
- case '1':
- uiSearchTravelsByDates(buyTicketLinkedList);
- break;
- case '2':
- uiDisplayTravelsByDates(buyTicketLinkedList);
- break;
- case '3':
- uiSearchTravelsByPlaces(buyTicketLinkedList);
- break;
- case '4':
- uiDisplayTravelsByPlaces(buyTicketLinkedList);
- break;
- case '5':
- uiMainMenu();
- break;
- default:
- break;
- }
- }
- */
- //--------------------------------------------------------------------------------------------------------------
- //------bus-----------------------------------------------------------------------------------------------------
- //--------------------------------------------------------------------------------------------------------------
- void uiAddBus(BuyTicketLinkedList &buyTicketLinkedList)
- {
- Bus newBus=uiGetBus();
- AddBus(newBus,buyTicketLinkedList);
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void uiSearchByBusID(BuyTicketLinkedList &buyTicketLinkedList)
- {
- const int BusIDSize = 20;
- char searchKey[BusIDSize];
- cout << "Enter the ID of bus: " ;
- cin >> searchKey;
- BuyTicketNode* result = searchByByBusID(searchKey,buyTicketLinkedList);
- if( result == NULL )
- cout << "No such bus ID found!" << endl;
- else
- uiDisplay(result->bus);
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- int countBus(BuyTicketLinkedList &buyTicketLinkedList)
- {
- BuyTicketNode* temp = buyTicketLinkedList.root;
- int counter = 0;
- while(temp != NULL)
- {
- counter++;
- temp = temp->next;
- }
- return counter;
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void uiEditBus(BuyTicketLinkedList &buyTicketLinkedList)
- {
- const int BusIDSize = 20;
- char searchKey[BusIDSize];
- cout << "Enter the ID of bus that you want to edit: " ;
- cin >> searchKey;
- BuyTicketNode* result = searchByByBusID(searchKey,buyTicketLinkedList);
- if( result == NULL )
- cout << "No such bus ID found!" << endl;
- else
- {
- cout << "This bus ID is found: " << endl;
- uiDisplay(result->bus);
- cout << "\nEnter new ID: ";
- cin >> result->bus.BusID;
- }
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void uiDeleteBus(BuyTicketLinkedList &buyTicketLinkedList)
- {
- const int BusIDSize = 15;
- char searchKey[BusIDSize];
- cout << "Enter the ID of bus that you want to delete: " ;
- cin >> searchKey;
- BuyTicketNode* result = searchByByBusID(searchKey,buyTicketLinkedList);
- if( result == NULL )
- cout << "No such bus ID found!" << endl;
- else
- {
- cout << "This bus is found: " << endl;
- uiDisplay(result->bus);
- cout << "\nAre you sure to delete? (press y to accept or n to deny): ";
- cout.flush();
- if( getch() == 'y' )
- {
- removeNodeBus(result,buyTicketLinkedList);
- }
- }
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void removeNodeBus(BuyTicketNode* victim,BuyTicketLinkedList &buyTicketLinkedList)
- {
- BuyTicketNode* temp = buyTicketLinkedList.root;
- BuyTicketNode* temp2 = buyTicketLinkedList.root;
- if(temp != NULL)
- {
- if( temp == victim )
- {
- buyTicketLinkedList.root = victim->next;
- releaseBus(victim);
- }
- else
- while(temp != NULL)
- {
- if( temp == victim )
- {
- temp2->next = victim->next;
- releaseBus(victim);
- break;
- }
- temp2 = temp;
- temp = temp->next;
- }
- }
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void releaseBus(BuyTicketNode* victim)
- {
- delete[] victim->bus.BusID;
- delete[] victim->bus.Type;
- //delete[] victim->bus.SeatNumber;
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void releaseBus(BuyTicketLinkedList &buyTicketLinkedList)
- {
- BuyTicketNode* temp = buyTicketLinkedList.root;
- BuyTicketNode* temp2;
- while(temp != NULL)
- {
- temp2 = temp->next;
- releaseBus(temp);
- temp = temp2;
- }
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void uiDisplayBus(BuyTicketLinkedList &buyTicketLinkedList)
- {
- BuyTicketNode* temp = buyTicketLinkedList.root;
- if(temp == NULL)
- {
- cout << "The list is empty!" << endl;
- }
- else
- {
- cout << setw(25) << "Bus ID" << setw(25) << "Type" << setw(25) << "Seat Number" << endl;
- cout << setw(25) << "------" << setw(25) << "-----" << setw(25) << "------------" << endl;
- while(temp != NULL)
- {
- uiDisplay(temp->bus);
- temp = temp->next;
- }
- }
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- Bus uiGetBus()
- {
- const int BusIDSize=20;
- const int TypeSize=20;
- Bus bus;
- bus.BusID=new char[BusIDSize];
- bus.Type=new char[TypeSize];
- cout<<"Enter type of bus: ";
- cin>>bus.Type;
- cout<<"Enter seat number of bus: ";
- cin>>bus.SeatNumber;
- cout<<"Enter ID of bus: ";
- cin>>bus.BusID;
- return bus;
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void AddBus(Bus newBus,BuyTicketLinkedList &buyTicketLinkedList)
- {
- BuyTicketNode* buyTicketNode = new BuyTicketNode;
- buyTicketNode->bus = newBus;
- buyTicketNode->next = NULL;
- BuyTicketNode* temp = buyTicketLinkedList.root;
- if(temp == NULL)
- {
- buyTicketLinkedList.root = buyTicketNode;
- }
- else
- {
- while(temp->next != NULL)
- temp = temp->next;
- temp->next = buyTicketNode;
- }
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void uiDisplay(Bus bus)
- {
- cout << setw(25) << bus.BusID << setw(25) << bus.Type << setw(25) << bus.SeatNumber << endl;
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- BuyTicketNode* searchByByBusID(char* searchKey,BuyTicketLinkedList &buyTicketLinkedList)
- {
- BuyTicketNode* temp = buyTicketLinkedList.root;
- while(temp != NULL)
- {
- if( strcmp(searchKey,temp->bus.BusID) == 0 )
- return temp;
- temp = temp->next;
- }
- return NULL;
- }
- //---------------------------------------------------------------------------------------------------------------------
- //------------travel---------------------------------------------------------------------------------------------------
- //---------------------------------------------------------------------------------------------------------------------
- void uiAddTravel(BuyTicketLinkedList &buyTicketLinkedList)
- {
- Travel newTravel=uiGetTravel();
- AddTravel(newTravel,buyTicketLinkedList);
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- /*
- void uiSearchByBusID(BuyTicketLinkedList &buyTicketLinkedList)
- {
- const int BusIDSize = 20;
- char searchKey[BusIDSize];
- cout << "Enter the ID of bus: " ;
- cin >> searchKey;
- BuyTicketNode* result = searchByByBusID(searchKey,buyTicketLinkedList);
- if( result == NULL )
- cout << "No such bus ID found!" << endl;
- else
- uiDisplay(result->travel);
- }*/
- //-----------------------------------------------------
- //-----------------------------------------------------
- int countTravel(BuyTicketLinkedList &buyTicketLinkedList)
- {
- BuyTicketNode* temp = buyTicketLinkedList.root;
- int counter = 0;
- while(temp != NULL)
- {
- counter++;
- temp = temp->next;
- }
- return counter;
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void uiEditTravel(BuyTicketLinkedList &buyTicketLinkedList)
- {
- const int BusIDSize = 20;
- char searchKey[BusIDSize];
- cout << "Enter the ID of bus that you want to edit: " ;
- cin >> searchKey;
- BuyTicketNode* result = searchByByBusID(searchKey,buyTicketLinkedList);
- if( result == NULL )
- cout << "No such bus ID found!" << endl;
- else
- {
- cout << "This bus ID is found: " << endl;
- uiDisplay(result->travel);
- cout << "\nEnter new ID: ";
- cin >> result->travel.BusID;
- }
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void uiDeleteTravel(BuyTicketLinkedList &buyTicketLinkedList)
- {
- const int BusIDSize = 15;
- char searchKey[BusIDSize];
- cout << "Enter the ID of bus that you want to delete: " ;
- cin >> searchKey;
- BuyTicketNode* result = searchByByBusID(searchKey,buyTicketLinkedList);
- if( result == NULL )
- cout << "No such bus ID found!" << endl;
- else
- {
- cout << "This bus is found: " << endl;
- uiDisplay(result->travel);
- cout << "\nAre you sure to delete? (press y to accept or n to deny): ";
- cout.flush();
- if( getch() == 'y' )
- {
- removeNodeTravel(result,buyTicketLinkedList);
- }
- }
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void removeNodeTravel(BuyTicketNode* victim,BuyTicketLinkedList &buyTicketLinkedList)
- {
- BuyTicketNode* temp = buyTicketLinkedList.root;
- BuyTicketNode* temp2 = buyTicketLinkedList.root;
- if(temp != NULL)
- {
- if( temp == victim )
- {
- buyTicketLinkedList.root = victim->next;
- releaseTravel(victim);
- }
- else
- while(temp != NULL)
- {
- if( temp == victim )
- {
- temp2->next = victim->next;
- releaseBus(victim);
- break;
- }
- temp2 = temp;
- temp = temp->next;
- }
- }
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void releaseTravel(BuyTicketNode* victim)
- {
- delete[] victim->travel.Origin;
- delete[] victim->travel.Destination;
- delete[] victim->travel.BusID;
- //delete[] victim->travel.date;
- //delete[] victim->travel.Passengers;
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void releaseTravel(BuyTicketLinkedList &buyTicketLinkedList)
- {
- BuyTicketNode* temp = buyTicketLinkedList.root;
- BuyTicketNode* temp2;
- while(temp != NULL)
- {
- temp2 = temp->next;
- releaseTravel(temp);
- temp = temp2;
- }
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void uiDisplayTravel(BuyTicketLinkedList &buyTicketLinkedList)
- {
- BuyTicketNode* temp = buyTicketLinkedList.root;
- if(temp == NULL)
- {
- cout << "The list is empty!" << endl;
- }
- else
- {
- cout<<setw(20)<<"Bus ID"<< setw(10)<<"Origin"<<setw(10)<<"Destination"<< setw(10)<<"Date"<<setw(10)<<"Passenger"<< endl;
- cout<<setw(20)<<"------"<< setw(10)<<"------"<<setw(10)<<"------------"<<setw(10)<<"----"<<setw(10)<<"---------"<< endl;
- while(temp != NULL)
- {
- uiDisplay(temp->travel);
- temp = temp->next;
- }
- }
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- Travel uiGetTravel()
- {
- const int BusIDSize=20;
- const int OriginSize=20;
- const int DestinationSize=20;
- //int date;
- //int Passenger;
- Travel travel;
- travel.BusID=new char[BusIDSize];
- travel.Origin=new char[OriginSize];
- travel.Destination=new char[DestinationSize];
- cout<<"Enter origin of travel: ";
- cin>>travel.Origin;
- cout<<"Enter destination of travel: ";
- cin>>travel.Destination;
- cout<<"Enter ID of bus: ";
- cin>>travel.BusID;
- /*cout<<"Enter date of travel: ";
- cin>>travel.date;*/
- /*cout<<"Enter number of passengers in travel: ";
- cin>>travel.Passengers;*/
- return travel;
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void AddTravel(Travel newTravel,BuyTicketLinkedList &buyTicketLinkedList)
- {
- BuyTicketNode* buyTicketNode = new BuyTicketNode;
- buyTicketNode->travel = newTravel;
- buyTicketNode->next = NULL;
- BuyTicketNode* temp = buyTicketLinkedList.root;
- if(temp == NULL)
- {
- buyTicketLinkedList.root = buyTicketNode;
- }
- else
- {
- while(temp->next != NULL)
- temp = temp->next;
- temp->next = buyTicketNode;
- }
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void uiDisplay(Travel travel)
- {
- cout<<setw(10)<<travel.BusID<<setw(10)<<travel.Origin<<setw(10)<<travel.Destination/*<<setw(10)<<travel.date*/<<setw(10)<<travel.Passengers<< endl;
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- /*BuyTicketNode* searchByByBusID(int BusID,BuyTicketLinkedList &buyTicketLinkedList)
- {
- BuyTicketNode* temp = buyTicketLinkedList.root;
- while(temp != NULL)
- {
- if( strcmp(searchKey,temp->travel.BusID) == 0 )
- return temp;
- temp = temp->next;
- }
- return NULL;
- */
- //---------------------------------------------------------------------------------------------------------------------
- //--------------passenger----------------------------------------------------------------------------------------------
- //---------------------------------------------------------------------------------------------------------------------
- void uiAddPassenger(BuyTicketLinkedList &buyTicketLinkedList)
- {
- Passenger newPassenger=uiGetPassenger();
- AddPassenger(newPassenger,buyTicketLinkedList);
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void uiSearchByTellNumber(BuyTicketLinkedList &buyTicketLinkedList)
- {
- const int TellNumberSize = 20;
- char searchKey[TellNumberSize];
- cout << "Enter the tell number of passenger: " ;
- cin >> searchKey;
- BuyTicketNode* result = searchByByTellNumber(searchKey,buyTicketLinkedList);
- if( result == NULL )
- cout << "No such tell number found!" << endl;
- else
- uiDisplay(result->travel);
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- int countPassenger(BuyTicketLinkedList &buyTicketLinkedList)
- {
- BuyTicketNode* temp = buyTicketLinkedList.root;
- int counter = 0;
- while(temp != NULL)
- {
- counter++;
- temp = temp->next;
- }
- return counter;
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void uiDisplayPassenger(BuyTicketLinkedList &buyTicketLinkedList)
- {
- BuyTicketNode* temp = buyTicketLinkedList.root;
- if(temp == NULL)
- {
- cout << "The list is empty!" << endl;
- }
- else
- {
- cout << setw(25) << "Name" << setw(25) << "Family" << setw(25) << "Tell Number" <<setw(20)<<"Passenger ID"<<endl;
- cout << setw(25) << "----" << setw(25) << "------" << setw(25) << "----------" << setw(20)<<"------------"<<endl;
- while(temp != NULL)
- {
- uiDisplay(temp->bus);
- temp = temp->next;
- }
- }
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- Passenger uiGetPassenger()
- {
- const int NameSize=20;
- const int FamilySize=20;
- const int TellNumberSize=20;
- Passenger passenger;
- passenger.Name=new char[NameSize];
- passenger.Family=new char[FamilySize];
- passenger.TellNumber=new char[TellNumberSize];
- cout<<"Enter your first name: ";
- cin>>passenger.Name;
- cout<<"Enter your last name: ";
- cin>>passenger.Family;
- cout<<"Enter your tell number: ";
- cin>>passenger.TellNumber;
- cout<<"Enter your ID of passenger: ";
- cin>>passenger.PassengerID;
- return passenger;
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void AddPassenger(Passenger newPassenger,BuyTicketLinkedList &buyTicketLinkedList)
- {
- BuyTicketNode* buyTicketNode = new BuyTicketNode;
- buyTicketNode->passenger = newPassenger;
- buyTicketNode->next = NULL;
- BuyTicketNode* temp = buyTicketLinkedList.root;
- if(temp == NULL)
- {
- buyTicketLinkedList.root = buyTicketNode;
- }
- else
- {
- while(temp->next != NULL)
- temp = temp->next;
- temp->next = buyTicketNode;
- }
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- void uiDisplay(Passenger passenger)
- {
- cout << setw(25) << passenger.Name << setw(25) << passenger.Family << setw(25) << passenger.TellNumber<<setw(20)<<passenger.PassengerID<< endl;
- }
- //-----------------------------------------------------
- //-----------------------------------------------------
- BuyTicketNode* searchByByTellNumber(char* searchKey,BuyTicketLinkedList &buyTicketLinkedList)
- {
- BuyTicketNode* temp = buyTicketLinkedList.root;
- while(temp != NULL)
- {
- if( strcmp(searchKey,temp->passenger.TellNumber) == 0 )
- return temp;
- temp = temp->next;
- }
- return NULL;
- }