answersLogoWhite

0


Best Answer

// Bus Reservation System

# include <stdio.h>

# include <conio.h>

void install();

void reservation();

void show();

void allbus();

void removebus();

void position(int);

struct bus

{

int bn; //Bus No.

float bt; //Arrival Time

char bd[20],from[10],to[10],seat[32][10]; //Driver Name,Journey From,Journey To

}b;

void install()

{

FILE *fp;

fp=fopen("abc.dat", "ab");

clrscr();

if(fp==NULL)

{

printf("File Creation Failed!");

}

else

{

printf("\n\t\tEnter Bus No.:= ");

scanf("%d",&b.bn);

printf("\n\t\tEnter Driver's Name:= ");

fflush(stdin);

scanf("%s",&b.bd);

printf("\n\t\tEnter Arrival Time:= ");

scanf("%f",&b.bt);

printf("\n\t\tEnter Journey From:= ");

fflush(stdin);

scanf("%s",&b.from);

printf("\n\t\tEnter Journey To:= ");

fflush(stdin);

scanf("%s",&b.to);

fwrite(&b, sizeof(b), 1, fp);

printf("\n\nBus Successfully Install");

}

printf("\n\nPress any key to Conti..");

getche();

fclose(fp);

}

void reservation()

{

int number,s;

int flag=0;

FILE *fp;

fp=fopen("abc.dat","rb+");

clrscr();

printf("\n\nEnter Bus No:= ");

scanf("%d",&number);

if(fp==NULL)

{

printf("\n\tFile doesn't exist!!!\TRY AGAIN");

}

else

{

while((fread(&b, sizeof(b), 1, fp))==1)

{

if(b.bn==number)

{

printf("\nEnter Seat Number:= ");

scanf("%d",&s);

flag=1;

if(s>32)

{

printf("\n\nThere are only 32 seats available in this bus");

break;

}

else

{

if(strcmp(&b.seat[s-1],NULL)==0)

{

printf("\nEnter Passenger's Name:= ");

fflush(stdin);

scanf("%s",&b.seat[s-1]);

fseek(fp,ftell(fp)-sizeof(b),0);

fwrite(&b,sizeof(b),1,fp);

printf("\n\nReservation is Success");

break;

}

else

{

printf("\n\nThe seat no %d is already resevered",s);

}

}

}

}

if(flag==0)

{

printf("\n\nBus Not Available");

}

}

printf("\n\nPress any key to Conti..");

getche();

fclose(fp);

}

void show()

{

int number;

int flag=0;

FILE *fp;

fp=fopen("abc.dat","rb");

clrscr();

printf("\n\nEnter Bus No:= ");

scanf("%d",&number);

if(fp==NULL)

{

printf("\n\tFile doesn't exist!!!\TRY AGAIN");

}

else

{

while((fread(&b, sizeof(b), 1, fp))==1)

{

if(b.bn==number)

{

printf("\nBus Number:= %d",b.bn);

printf("\nBus Driver's Name:= %s",b.bd);

printf("\nBus Arravial Time:= %.2f",b.bt);

printf("\nBus Journey From:= %s",b.from);

printf("\nBus Journey To:= %s",b.to);

flag=1;

position(b.bn);

}

}

if(flag==0)

{

printf("\n\nBus Not Available");

}

}

printf("\n\nPress any key to Conti..");

getche();

fclose(fp);

}

void position(int a)

{

int s=0,p=0;

int i;

printf("\n\n");

for(i=0;i<32;i++)

{

s++;

if(strcmp(&b.seat[i],NULL)==0)

{

printf("%d. Empty\t",s);

p++;

}

else

{

printf("%d. %s\t",s,b.seat[i]);

}

}

printf("\n\nThere are %d seats empty in bus no. %d",p,a);

}

void allbus()

{

int no=0;

FILE *fp;

fp=fopen("abc.dat","rb");

clrscr();

if(fp==NULL)

{

printf("\n\tFile doesn't exist!!!\TRY AGAIN");

}

else

{

while((fread(&b, sizeof(b), 1, fp))==1)

{

printf("\n\n=============================================================================");

no++;

printf("\nBus Number:= %d",b.bn);

printf("\nBus Driver's Name:= %s",b.bd);

printf("\nBus Arravial Time:= %.2f",b.bt);

printf("\nBus Journey From:= %s",b.from);

printf("\nBus Journey To:= %s",b.to);

printf("\n\n=============================================================================");

printf("\n\nPress any key to Conti..");

getche();

}

printf("\n\nTotal number of Bus(es) present:= %d",no);

}

printf("\n\nPress any key to Conti..");

getche();

fclose(fp);

}

void removebus()

{

int number;

int flag=0;

char ch;

FILE *fp,*ft;

fp=fopen("abc.dat","rb");

ft=fopen("temp.dat","wb");

clrscr();

printf("\n\nEnter Bus No:= ");

scanf("%d",&number);

if(fp==NULL)

{

printf("\n\tFile doesn't exist!!!\TRY AGAIN");

}

else

{

while((fread(&b, sizeof(b), 1, fp))==1)

{

if(b.bn==number)

{

flag=1;

printf("\nAre you sure want to Remove Bus %d ??(Y/N)",b.bn);

fflush(stdin);

scanf("%c", &ch);

}

}

if(flag==0)

{

printf("\n\nBus Not Available");

}

else

{

if(ch=='y'ch=='Y')

{

rewind(fp);

while((fread(&b, sizeof(b), 1, fp))==1)

{

if(b.bn!=number)

{

fwrite(&b, sizeof(b), 1, ft);

}

}

remove("abc.dat");

rename("temp.dat", "abc.dat");

printf("\n\nBus Remove Success");

}

else

{

printf("\n\nBus Not Remove");

}

}

}

printf("\n\nPress any key to Conti..");

getche();

fclose(fp);

fclose(ft);

}

void main()

{

int c;

clrscr();

printf("\n=============================================================================");

printf("\n\nDevloped By:= Chhatrala Chirag A. && Samani Jeki J.");

printf("\n\nGuided By:= Jatin Sir");

printf("\n\n=============================================================================");

printf("\n\n\t\t\tBUS RESERVATION SYSTEM");

printf("\n\n=============================================================================");

while(1)

{

printf("\n\n\n");

printf("\t\t\t1.Install\n\t\t\t2.Reservation\n\t\t\t3.Show\n\t\t\t4.Bus(es) Available\n\t\t\t5.Remove Bus\n\t\t\t6.Exit");

printf("\n\n\t\t\tEnter Your Choice:=> ");

scanf("%d",&c);

switch(c)

{

case 1:

install();

break;

case 2:

reservation();

break;

case 3:

show();

break;

case 4:

allbus();

break;

case 5:

removebus();

break;

case 6:

printf("\n\nThank You!!!!");

printf("\n\nPress any key to Conti..");

getche();

exit(0);

break;

default:

printf("\n\t\t\tInvalid Choice\n\t\t\tTry Again....");

break;

}

}

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a C Program on Daewoo a Bus service Reservation System?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Give some example of visual basic program?

Billing System, Time Keeping System, Point of Sales System, Reservation System


What is reservation system?

Amadeus reservation system


What is the definition of reservation system?

MEANING OF RESERVATION SYSTEM


What is System Service Program?

A system service program is a configuration of technology and organizational networks designed to deliver services that satisfy the needs, wants, or aspirations of customers.


Dfd for airlines reservation system?

I have dfd for airlines reservation system. my email id is: nabanita.dumdum@gmail.com


What is the limitation of hotel reservation system?

scope limitation of hotel reservation system?


What is fidelio system?

system of reservation


How does a well - organized reservation system meet the needs of travelers?

a well organization reservation system


What is program service?

A system service program is a configuration of technology and organizational networks designed to deliver services that satisfy the needs, wants, or aspirations of customers.


What are the disadvantages of manual hotel reservation system?

the disadvantages of manual hotel reservation system....Slow process of reservation......less data integrity........low in security............difficulty of searching and retrieving records........manual reservation is a time consumable unlike when they have a computerized system..........


E R diagram for bus reservation system?

i want er diagram for bus reservation system you shw me


Apply waterfall model for railway reservation system?

i need water fall model of railway reservation system.