0% found this document useful (0 votes)
12 views4 pages

Lab 2

This document contains a C++ program for a train ticket reservation system. It allows users to book tickets, display booked tickets, and check seat availability. The program uses a structure to store passenger information and provides a menu-driven interface for user interaction.

Uploaded by

arifahassan0209
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

Lab 2

This document contains a C++ program for a train ticket reservation system. It allows users to book tickets, display booked tickets, and check seat availability. The program uses a structure to store passenger information and provides a menu-driven interface for user interaction.

Uploaded by

arifahassan0209
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Name: Arifa Hassan

Class: BSCS- 4C
SAP ID: 70145488

LAB TASKS
DSA LAB 02

TASK 01:
Sol:
#include <iostream>

#include <string>

using namespace std;

struct info

string name;

int age;

char gender;

int seatnum;

};

const int maxs= 50; //given condition

info ticket[maxs];

int seatcount=0;

void bookt()

if (seatcount<maxs)

cout<<"Enter Your Name: ";

cin>>ticket[seatcount].name;

cout<<"enter Your Age: ";

cin>>ticket[seatcount].age;
cout<<"What is your Gender: "<<endl;

cout<<"Enter M for male and F for female. ";

cin>>ticket[seatcount].gender;

ticket[seatcount].seatnum=seatcount+1;

seatcount++;

cout<<"Tickets Booked successfully!!!"<<endl;

else

cout<<"Sorry seats are full!!"<<endl;

void bookedt()

if (seatcount==0)

cout<<"No booked tickets! "<<endl;

else

cout << "Booked Tickets are:" << endl;

for (int i=0; i<seatcount; i++)

cout<<"Name: "<<ticket[i].name<<endl;

cout<<"Age: "<<ticket[i].age<<endl;

cout<<"Gender: "<<ticket[i].gender<<endl;

cout<<"Seat Number: "<<ticket[i].seatnum<<endl;

}
}

void availableseats()

if (seatcount<maxs)

cout<<"Seats left are: "<<maxs-seatcount<<endl;

else

cout<<"Sorry seats are full."<<endl;

int main()

cout<<"Train Ticket Reservation"<<endl;

int menu;

while (menu != 4)

cout<<"1. Book Ticket"<<endl;

cout<<"2. Display Booked Tickets"<<endl;

cout<<"3. Check Seat Availability"<<endl;

cout<<"4. Exit"<<endl;

cout<<"Enter the number you want to display information about: ";

cin>>menu;

switch(menu)

case 1:

bookt();

break;
case 2:

bookedt();

break;

case 3:

availableseats();

break;

case 4:

return 0;

break;

default:

cout<<"Invalid input! try again"<<endl;

return 0;

OUTPUT:

You might also like