Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you add the option to delete a reservation to the schedule given below? (C programming language) PROGRAM /* A Simple Bus Reservation System */

Can you add the option to delete a reservation to the schedule given below? (C programming language)

PROGRAM

/*

A Simple Bus Reservation System

*/

/*include header files*/

#include

#include

/*Global variable holding bus index*/

int p = 0;

/*structure defining Bus*/

struct

{

char busn[5];

char driver[10];

char arrival[5];

char depart[5];

char from[10];

char to[10];

char seat[8][4][10];

}bus[10];

/*function prototype declarations*/

/*

function to install buses

Input: Bus details

Output: None

Return: None

Side Effects: Bus details will be updates in the bus structure

*/

void install();

/*

function to reserve seats

Input: seat details

Output: None

Return: None

Side Effects: Seat reserved will be updated in the bus structure

*/

void allotment();

/*

function to show the reservation details

Input: Bus details

Output: Reservation Details

Return: None

Side Effects: None

*/

void show();

/*

function to show the details of the available buses

Input: Nil

Output: Available bus Details

Return: None

Side Effects: None

*/

void avail();

/*

function to display seat positions

Input: Nil

Output: Display seat positions

Return: None

Side Effects: None

*/

void position(int i);

/*

function to display a line

Input: character to draw and number of characters

Output: The line

Return: None

Side Effects: None

*/

void vline(char ch, int size);

int main()

{

int w;

while(1)

{

vline('-',50);

printf(" ***SIMPLE BUS RESERVATION SYSTEM***");

vline('-',50);

printf(" 1.Install");

printf(" 2.Reservation");

printf(" 3.Show");

printf(" 4.Buses Available ");

printf(" 5.Exit");

vline('-',50);

printf(" Enter your choice:- ");

scanf("%d", &w);

switch(w)

{

case 1: install();

break;

case 2: allotment();

break;

case 3: show();

break;

case 4: avail();

break;

case 5: return 0;

}

}

return 0;

}

/*

function to display a line

Input: character to draw and number of characters

Output: The line

Return: None

Side Effects: None

*/

void vline(char ch, int size)

{

printf(" ");

for(int i=size;i>0;i--)

printf("%c",ch);

}

/*

function to install buses

Input: Bus details

Output: None

Return: None

Side Effects: Bus details will be updates in the bus structure

*/

void install()

{

printf("Enter bus no: ");

scanf(" %[^ ]",bus[p].busn);

printf("Enter Driver's name: ");

scanf(" %[^ ]",bus[p].driver);

printf("Arrival time: ");

scanf(" %[^ ]",bus[p].arrival);

printf("Departure: ");

scanf(" %[^ ]",bus[p].depart);

printf("From: ");

scanf(" %[^ ]",bus[p].from);

printf("To: ");

scanf(" %[^ ]",bus[p].to);

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

for(int j=0;j<4;j++)

strcpy(bus[p].seat[i][j], "Empty");

p++;

}

/*

function to reserve seats

Input: seat details

Output: None

Return: None

Side Effects: Seat reserved will be updated in the bus structure

*/

void allotment()

{

int seat;

char number[5];

top:

printf(" Bus no: ");

scanf(" %[^ ]",number);

int n;

for(n=0;n<=p;n++)

{

if(strcmp(bus[n].busn, number)==0)

break;

}

while(n<=p)

{

printf(" Seat Number: ");

scanf(" %d", &seat);

if(seat>32)

printf(" There are only 32 seats available in this bus.");

else

{

if (strcmp(bus[n].seat[seat/4][(seat%4)-1], "Empty")==0)

{

printf(" Enter passenger's name: ");

scanf(" %[^ ]", &bus[n].seat[seat/4][(seat%4)-1]);

break;

}

else

printf(" The seat no. is already reserved. ");

}

}

if(n>p)

{

printf(" Enter correct bus no. ");

goto top;

}

}

/*

function to show the reservation details

Input: Bus details

Output: Reservation Details

Return: None

Side Effects: None

*/

void show()

{

int n;

char number[5];

printf("Enter bus no: ");

scanf(" %[^ ]",number);

for(n=0;n<=p;n++)

{

if(strcmp(bus[n].busn, number)==0)

break;

}

while(n<=p)

{

vline('-',80);

printf(" Bus no: %s",bus[n].busn);

printf(" Driver: %s",bus[n].driver);

printf(" Arrival time: %s",bus[n].arrival);

printf(" Departure time: %s",bus[n].depart);

printf(" From: %s",bus[n].from);

printf(" To: %s",bus[n].to);

vline('-',80);

position(n);

int a=1;

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

{

for(int j=0;j<4;j++)

{

a++;

if(strcmp(bus[n].seat[i][j],"Empty")!=0)

printf(" The seat no %d is reserved for %s.",

a-1,bus[n].seat[i][j]);

}

}

break;

}

if(n>p)

printf(" Enter correct bus no: ");

}

/*

function to display seat positions

Input: Nil

Output: Display seat positions

Return: None

Side Effects: None

*/

void position(int l)

{

int s=0;p=0;

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

{

printf(" ");

for (int j = 0;j<4; j++)

{

s++;

if(strcmp(bus[l].seat[i][j], "Empty")==0)

{

printf("%5d. %-10s",s,bus[l].seat[i][j]);

p++;

}

else

{

printf("%5d. %-10s",s,bus[l].seat[i][j]);

}

}

}

printf(" There are %d seats empty in Bus No: %s",p,bus[l].busn);

}

/*

function to show the details of the available buses

Input: Nil

Output: Available bus Details

Return: None

Side Effects: None

*/

void avail()

{

for(int n=0;n

{

vline('-',60);

printf(" Bus no: %s",bus[n].busn);

printf(" Driver: %s",bus[n].driver);

printf(" Arrival time: %s",bus[n].arrival);

printf(" Departure Time: %s", bus[n].depart);

printf(" From: %s",bus[n].from);

printf(" To: %s", bus[n].to);

vline('-',60);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions

Question

Explain all the characteristics of a Trade Union in short?

Answered: 1 week ago

Question

Question Can I collect benefits if I become disabled?

Answered: 1 week ago