Bahria University: D S A A # 01
Bahria University: D S A A # 01
Lahore Campus
Submission Requirements:
1. Screen short of working Demo will be shown along with viva voce in the respective Class.
2. No Late submissions will be accepted.
3. Assignment on the email or WhatsApp group will not be accepted.
Question No.1
Write a simple airline ticket reservation program. The program should display a menu with the
following operations: reserve a ticket, cancel a reservation, check whether a ticket is reserved
for person, and display the passengers. The information is maintained on an alphabetized linked
list of names. In a simper version of the program, assume that tickets are reserved for only one
flight. In a fuller version, place no limit on the number of flights. Create a linked list of flights
with each node including pointer to a linked list of passengers.
#include<iostream>
#include<string>
using namespace std;
struct reserve
{
string name;
int id;
reserve* next;
};
reserve* head = NULL;
reserve* tail = NULL;
void reticket(string na, int id)
{
reserve* temp = new reserve;
temp->name = na;
temp->id = id;
temp->next = NULL;
if (head == NULL)
{
head = temp;
tail = temp;
}
tail->next = temp;
tail = temp;
}
void cancelre()
{
reserve* temp = head;
reserve * temp1 = new reserve;
int i = 1;
int pos;
cout << "enter the id res u want to delect" << endl;
cin >> pos;
temp = head;
while (i != pos)
{
temp1 = temp;
temp = temp->next;
i++;
}
temp1->next = temp->next;
}
bool search()
{
int id;
cout << "enter the id you wawnt to search " << endl;
cin >> id;
reserve* temp = new reserve;
temp = head;
while (temp != NULL)
{
if (temp->id = id)
{
return true;
temp = temp->next;
cout << "passenger name is" << temp->name << "passenger id is " <<
temp->id << endl;
}
else
return false;
}
void sortd()
{
cout << "after sort the data" << endl;
reserve* temp = head;
reserve* temp1;
for (temp = head; temp->next != NULL; temp = temp->next)
{
for (temp1 = temp->next; temp1 != NULL; temp1 = temp1->next)
{
if (temp->id > temp1->id)
{
int i;
i = temp->id;
temp->id = temp1->id;
temp1->id = i;
}
}
}
}
void display()
{
reserve* temp = new reserve;
temp = head;
while (temp != NULL)
{
cout << temp->id << endl;
cout << temp->name << endl;
temp = temp->next;
}
}
void menu()
{
cout << "1:for reserve ticket" << endl;
cout << "2: for cancel the ticket" << endl;
cout << "3: for search the passenger" << endl;
cout << "4: for sorting the data passenger" << endl;
cout << "5:display" << endl;
cout << "enter the choice" << endl;
}
int main()
{
string na;
int id;
START:
menu();
int i;
cin >> i;
switch (i)
{
case 1:
cout << "enter the name of passenger" << endl;
cin >> na;
cout << "enter the id" << endl;
cin >> id;
reticket(na, id);
goto START;
case 2:
cancelre();
goto START;
case 3:
search() ? cout << "seat are reserve with this id" << endl : cout << "seat
are not reserve with thid id" << endl;
system("pause");
goto START;
case 4:
sortd();
display();
system("pause");
goto START;
case 5:
display();
system("pause");
goto START;
}
system("pause");
return 0;
}
For seat reservation and display option
For reserve seat and sorting option