Downlaod:Sourc code
Reference:http://www.codewithc.com/bus-reservation-system-project-in-c/
//----------about me------------------
//Author : Learning Pen
//MyBlog : learningpen.blogspot.com
//Language : C++
//Tool : Dev C++
//------------------------------------
#include <iostream>
#include <windows.h>
#include <conio.h> //for getch()
using std::cout;
using std::cin;
static int num= 0; //count buses number
//==== Declare Function===
void Menu( void );
void gotoxy( int x, int y );
void textcolor( int color );
int SeatNum( class Bus *p );
//====Class Bus===========
class Bus
{
private:
char busno[ 5 ]; //bus number
char driver[ 10 ];
char arrival[ 5 ]; // arrival time
char from[ 10 ]; // starting point
char to[ 10 ]; // destination
public:
char seat[ 32 ][20]; //....??
void install( void );
void allotment( void );
void empty( void );
void show( void );
}bus[ 10 ];
void Bus::install( void )
{
system( "cls" );
textcolor( 14 );
gotoxy( 16, 3 );
textcolor( 12 );
cout<< "★★★★BUS RESERVATION SYSTEM★★★★";
textcolor( 14 );
gotoxy( 20, 5 );
textcolor( 10 );
cout<< "Register-->";
textcolor( 14 );
gotoxy( 24, 6 );
cout<< "Enter bus no: ";
textcolor( 12 );
cin>> bus[ num ].busno;
textcolor( 14 );
gotoxy( 24, 7 );
cout<< "Enter driver`s name: ";
textcolor( 12 );
cin>> bus[ num ].driver;
textcolor( 14 );
gotoxy( 24, 8 );
cout<< "Arrival time: ";
textcolor( 12 );
cin>> bus[ num ].arrival;
textcolor( 14 );
gotoxy( 24, 9 );
cout<< "From: ";
textcolor( 12 );
cin>> bus[ num ].from;
textcolor( 14 );
gotoxy( 24, 10 );
cout<< "To: ";
textcolor( 12 );
cin>> bus[ num ].to;
textcolor( 14 );
//
bus[ num ].empty(); //Assignment bus[num]= "empty".
num++;
gotoxy( 24, 12 );
cout<< "Press any key to continue.";
getch();
}
void Bus::empty()
{
for( int i= 0; i< 32; i++ )
{
strcpy( bus[ num ].seat[ i ], "empty" );
}
// system( "cls" );
// for( int i =0; i< 32; i++ )
// {
// cout<< i<< bus[ num ].seat[ i ]<< std::endl;
// }
//
// getch();
return ;
}
void Bus::allotment( void )
{
char number[ 5 ]; //buses number
int seatnumber;
system( "cls" );
gotoxy( 16, 3 );
textcolor( 12 );
cout<< "★★★★BUS RESERVATION SYSTEM★★★★";
textcolor( 14 );
gotoxy( 20, 5 );
textcolor( 10 );
cout<< "Reservation--> ";
textcolor( 14 );
gotoxy( 24, 6 );
cout<< "Select a bus number: ";
textcolor( 12 );
cin>> number;
textcolor( 14 );
int i;
for( i= 0; i<= num; i++ )
{
if( strcmp( bus[ i ].busno, number )== 0 )
{
break;
}
}
if( i<= num )
{
gotoxy( 24, 8 );
cout<< "OK, Select seat number(0 - 31): ";
textcolor( 12 );
cin>> seatnumber;
textcolor( 14 );
if( strcmp( bus[ i ].seat[ seatnumber ], "empty" )== 0 )
{
gotoxy( 24, 9 );
cout<< "Enter your name: ";
textcolor( 12 );
cin>> bus[ i ].seat[ seatnumber ];
textcolor( 14 );
}
else
{
gotoxy( 24, 10 );
textcolor( 12 );
cout<< "The SeatNum no is already Reserved.!!";
textcolor( 14 );
}
}
else
{
gotoxy( 24, 9 );
textcolor( 13 );
cout<< "Please,Enter correct bus no.!!";
textcolor( 14 );
}
gotoxy( 24, 12 );
cout<< "Press any key to continue.";
getch();
return ;
}
void Bus::show( void )
{
char number[ 5 ];
system( "cls" );
gotoxy( 16, 3 );
textcolor( 12 );
cout<< "★★★★BUS RESERVATION SYSTEM★★★★";
textcolor( 14 );
gotoxy( 20, 5 );
textcolor( 10 );
cout<< "Showing--> ";
textcolor( 14 );
gotoxy( 24, 6 );
cout<< "Enter bus no: ";
textcolor( 12 );
cin>> number;
textcolor( 14 );
int i;
for( i= 0; i<= num; i++ )
{
if( strcmp( bus[ i ].busno, number)== 0 )
{
break;
}
}
if( i<= num )
{
gotoxy( 24, 7 );
cout<< "Bus no: ";
textcolor( 12 );
cout<< bus[ i ].busno;
textcolor( 14 );
gotoxy( 24, 8 );
cout<< "Driver: ";
textcolor( 12 );
cout<< bus[ i ].driver;
textcolor( 14 );
gotoxy( 24, 9 );
cout<< "Arrival time: ";
textcolor( 12 );
cout<< bus[ i ].arrival;
textcolor( 14 );
gotoxy( 24, 10 );
cout<< "From: ";
textcolor( 12 );
cout<< bus[ i ].from;
textcolor( 14 );
gotoxy( 24, 11 );
cout<< "To: ";
textcolor( 12 );
cout<< bus[ i ].to;
textcolor( 14 );
gotoxy( 24, 12 );
cout<< "Number of available seats: ";
textcolor( 12 );
cout<< SeatNum( &bus[ i ] ); //return number of available seats.
textcolor( 14 );
}
else
{
gotoxy( 24, 10 );
textcolor( 12 );
cout<< "Please Enter correct bus no!";
textcolor( 14 );
}
gotoxy(24, 14 );
cout<< "Press any key continue.";
getch();
return ;
}
//====Main Function=======
int main( void )
{
int choice;
do
{
Menu();
gotoxy( 24, 12 );
cout<<"Enter your choice(1- 4): ";
cin>> choice;
switch( choice )
{
case 1:
{
bus[ num ].install();
break;
}
case 2:
{
bus[ num ].allotment();
break;
}
case 3:
{
bus[ 0 ].show();
break;
}
case 4:
{
char exiting[]= "Exiting......";
gotoxy( 24, 15 );
textcolor( 12 );
cout<< "Thank you for using.";
textcolor( 14 );
gotoxy( 24, 18 );
for( int i= 0; i< strlen( exiting ); i++ )
{
cout<< exiting[ i ];
Sleep( 100 );
}
break;
}
}
}while( choice>= 1 && choice< 4 );
return 0;
}
//=====Function Define =====
void Menu( void )
{
system( "cls" );
textcolor( 14 );
gotoxy( 16, 3 );
textcolor( 12 );
cout<< "★★★★BUS RESERVATION SYSTEM★★★★";
textcolor( 14 );
gotoxy( 24, 6 );
cout<< "1.) Bus register";
gotoxy( 24, 7 );
cout<< "2.) Reservation seat";
gotoxy( 24, 8 );
cout<< "3.) Show";
gotoxy( 24, 9 );
cout<< "4.) Exit";
return ;
}
void gotoxy( int x, int y )
{
COORD pos= { 0, 0 };
HANDLE handle= GetStdHandle( STD_OUTPUT_HANDLE );
pos.X= x;
pos.Y= y;
SetConsoleCursorPosition( handle, pos );
return ;
}
void textcolor( int color )
{
HANDLE handle= GetStdHandle( STD_OUTPUT_HANDLE );
SetConsoleTextAttribute( handle, color );
return ;
}
int SeatNum( class Bus *p )
{
int count= 0;
for( int i= 0; i< 32; i++ )
{
if( strcmp( p->seat[ i], "empty" )== 0 )
{
count++;
}
}
return count;
}
ScreenShot;
Reference:http://www.codewithc.com/bus-reservation-system-project-in-c/
//----------about me------------------
//Author : Learning Pen
//MyBlog : learningpen.blogspot.com
//Language : C++
//Tool : Dev C++
//------------------------------------
#include <iostream>
#include <windows.h>
#include <conio.h> //for getch()
using std::cout;
using std::cin;
static int num= 0; //count buses number
//==== Declare Function===
void Menu( void );
void gotoxy( int x, int y );
void textcolor( int color );
int SeatNum( class Bus *p );
//====Class Bus===========
class Bus
{
private:
char busno[ 5 ]; //bus number
char driver[ 10 ];
char arrival[ 5 ]; // arrival time
char from[ 10 ]; // starting point
char to[ 10 ]; // destination
public:
char seat[ 32 ][20]; //....??
void install( void );
void allotment( void );
void empty( void );
void show( void );
}bus[ 10 ];
void Bus::install( void )
{
system( "cls" );
textcolor( 14 );
gotoxy( 16, 3 );
textcolor( 12 );
cout<< "★★★★BUS RESERVATION SYSTEM★★★★";
textcolor( 14 );
gotoxy( 20, 5 );
textcolor( 10 );
cout<< "Register-->";
textcolor( 14 );
gotoxy( 24, 6 );
cout<< "Enter bus no: ";
textcolor( 12 );
cin>> bus[ num ].busno;
textcolor( 14 );
gotoxy( 24, 7 );
cout<< "Enter driver`s name: ";
textcolor( 12 );
cin>> bus[ num ].driver;
textcolor( 14 );
gotoxy( 24, 8 );
cout<< "Arrival time: ";
textcolor( 12 );
cin>> bus[ num ].arrival;
textcolor( 14 );
gotoxy( 24, 9 );
cout<< "From: ";
textcolor( 12 );
cin>> bus[ num ].from;
textcolor( 14 );
gotoxy( 24, 10 );
cout<< "To: ";
textcolor( 12 );
cin>> bus[ num ].to;
textcolor( 14 );
//
bus[ num ].empty(); //Assignment bus[num]= "empty".
num++;
gotoxy( 24, 12 );
cout<< "Press any key to continue.";
getch();
}
void Bus::empty()
{
for( int i= 0; i< 32; i++ )
{
strcpy( bus[ num ].seat[ i ], "empty" );
}
// system( "cls" );
// for( int i =0; i< 32; i++ )
// {
// cout<< i<< bus[ num ].seat[ i ]<< std::endl;
// }
//
// getch();
return ;
}
void Bus::allotment( void )
{
char number[ 5 ]; //buses number
int seatnumber;
system( "cls" );
gotoxy( 16, 3 );
textcolor( 12 );
cout<< "★★★★BUS RESERVATION SYSTEM★★★★";
textcolor( 14 );
gotoxy( 20, 5 );
textcolor( 10 );
cout<< "Reservation--> ";
textcolor( 14 );
gotoxy( 24, 6 );
cout<< "Select a bus number: ";
textcolor( 12 );
cin>> number;
textcolor( 14 );
int i;
for( i= 0; i<= num; i++ )
{
if( strcmp( bus[ i ].busno, number )== 0 )
{
break;
}
}
if( i<= num )
{
gotoxy( 24, 8 );
cout<< "OK, Select seat number(0 - 31): ";
textcolor( 12 );
cin>> seatnumber;
textcolor( 14 );
if( strcmp( bus[ i ].seat[ seatnumber ], "empty" )== 0 )
{
gotoxy( 24, 9 );
cout<< "Enter your name: ";
textcolor( 12 );
cin>> bus[ i ].seat[ seatnumber ];
textcolor( 14 );
}
else
{
gotoxy( 24, 10 );
textcolor( 12 );
cout<< "The SeatNum no is already Reserved.!!";
textcolor( 14 );
}
}
else
{
gotoxy( 24, 9 );
textcolor( 13 );
cout<< "Please,Enter correct bus no.!!";
textcolor( 14 );
}
gotoxy( 24, 12 );
cout<< "Press any key to continue.";
getch();
return ;
}
void Bus::show( void )
{
char number[ 5 ];
system( "cls" );
gotoxy( 16, 3 );
textcolor( 12 );
cout<< "★★★★BUS RESERVATION SYSTEM★★★★";
textcolor( 14 );
gotoxy( 20, 5 );
textcolor( 10 );
cout<< "Showing--> ";
textcolor( 14 );
gotoxy( 24, 6 );
cout<< "Enter bus no: ";
textcolor( 12 );
cin>> number;
textcolor( 14 );
int i;
for( i= 0; i<= num; i++ )
{
if( strcmp( bus[ i ].busno, number)== 0 )
{
break;
}
}
if( i<= num )
{
gotoxy( 24, 7 );
cout<< "Bus no: ";
textcolor( 12 );
cout<< bus[ i ].busno;
textcolor( 14 );
gotoxy( 24, 8 );
cout<< "Driver: ";
textcolor( 12 );
cout<< bus[ i ].driver;
textcolor( 14 );
gotoxy( 24, 9 );
cout<< "Arrival time: ";
textcolor( 12 );
cout<< bus[ i ].arrival;
textcolor( 14 );
gotoxy( 24, 10 );
cout<< "From: ";
textcolor( 12 );
cout<< bus[ i ].from;
textcolor( 14 );
gotoxy( 24, 11 );
cout<< "To: ";
textcolor( 12 );
cout<< bus[ i ].to;
textcolor( 14 );
gotoxy( 24, 12 );
cout<< "Number of available seats: ";
textcolor( 12 );
cout<< SeatNum( &bus[ i ] ); //return number of available seats.
textcolor( 14 );
}
else
{
gotoxy( 24, 10 );
textcolor( 12 );
cout<< "Please Enter correct bus no!";
textcolor( 14 );
}
gotoxy(24, 14 );
cout<< "Press any key continue.";
getch();
return ;
}
//====Main Function=======
int main( void )
{
int choice;
do
{
Menu();
gotoxy( 24, 12 );
cout<<"Enter your choice(1- 4): ";
cin>> choice;
switch( choice )
{
case 1:
{
bus[ num ].install();
break;
}
case 2:
{
bus[ num ].allotment();
break;
}
case 3:
{
bus[ 0 ].show();
break;
}
case 4:
{
char exiting[]= "Exiting......";
gotoxy( 24, 15 );
textcolor( 12 );
cout<< "Thank you for using.";
textcolor( 14 );
gotoxy( 24, 18 );
for( int i= 0; i< strlen( exiting ); i++ )
{
cout<< exiting[ i ];
Sleep( 100 );
}
break;
}
}
}while( choice>= 1 && choice< 4 );
return 0;
}
//=====Function Define =====
void Menu( void )
{
system( "cls" );
textcolor( 14 );
gotoxy( 16, 3 );
textcolor( 12 );
cout<< "★★★★BUS RESERVATION SYSTEM★★★★";
textcolor( 14 );
gotoxy( 24, 6 );
cout<< "1.) Bus register";
gotoxy( 24, 7 );
cout<< "2.) Reservation seat";
gotoxy( 24, 8 );
cout<< "3.) Show";
gotoxy( 24, 9 );
cout<< "4.) Exit";
return ;
}
void gotoxy( int x, int y )
{
COORD pos= { 0, 0 };
HANDLE handle= GetStdHandle( STD_OUTPUT_HANDLE );
pos.X= x;
pos.Y= y;
SetConsoleCursorPosition( handle, pos );
return ;
}
void textcolor( int color )
{
HANDLE handle= GetStdHandle( STD_OUTPUT_HANDLE );
SetConsoleTextAttribute( handle, color );
return ;
}
int SeatNum( class Bus *p )
{
int count= 0;
for( int i= 0; i< 32; i++ )
{
if( strcmp( p->seat[ i], "empty" )== 0 )
{
count++;
}
}
return count;
}
ScreenShot;