Sep 29, 2014

Bus Reservation System Project in C++

9:17 PM Posted by Unknown , 1 comment
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;




Customer Biling System[Package Code]

1:14 AM Posted by Unknown , No comments
  Reference code:http://www.codewithc.com/customer-billing-system-project-in-c/ 
  
  if you need the package source code,Please see the end of article.

Source Code:

//Author   : LearningPen
//Date     : 2014/9/29
//Language : C++
//Tool     : Dev C++
//MyBlog   :http://learningpen.blogspot.com/

#include <iostream>
#include <windows.h>
#include <conio.h>
#include <string>

using namespace std;

void Input( void );
void WriteFile( void );
void Search( void );
void Output( void );
void gotoxy( int x, int y );
void textcolor( int color );
void Menu( void );

struct date
{
int month;
int day;
int year;
};

struct account
{
int   number;
char  name[ 100 ];
int   acct_no;  //account number
float mobile_no;
char  street[ 100 ];
char  city[ 100 ];
char  acct_type;
float oldbalance;
float newbalance;
float payment;
struct date lastpayment;
}customer; 


int main( void )
{
int choice;
//int num= 0;

system( "cls" );
textcolor( 14 );

Menu();

gotoxy( 24, 12 );
cout<< "Enter your choice(0- 2): ";
cin>> choice;


switch( choice )
{
case 1:
{

   Input();

if( customer.payment > 0 )
{
customer.acct_type= ( customer.payment< 
 0.1* customer.oldbalance ) ? 'O' : 'D';
}
else
{
customer.acct_type= ( customer.oldbalance> 0) ?
'D' : 'C';
}

customer.newbalance= customer.oldbalance- customer.payment;

WriteFile();

main();  //goto main()...
}
case 2:
{
Search();

main();  //goto main().........
}
case 0:
{
gotoxy( 24, 16 );
textcolor( 12 );
cout<< "Thank you for using.";
gotoxy( 24, 17 );
cout<< "Welcome to My Blog:http://learningpen.blogspot.com/";
textcolor( 14 );

Sleep( 1000 );  //wait a second

exit( 1 );
}
}

return 0;
}

//------------------function ------
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 ;
}

void Menu( void )
{
gotoxy( 18, 4 );
cout<< "★☆☆CUSTOMER BILLING SYSTEM☆☆★";

gotoxy( 18, 5 );
cout<< "-----------------------------------";

gotoxy( 24, 7 );
cout<< "1.) Add account on list ";

gotoxy( 24, 8 );
cout<< "2.) Search customer account ";

gotoxy( 24, 9 );
cout<< "0.) Exit ";

gotoxy( 18, 11 );
cout<< "-----------------------------------";

return ;
}

void Input( void )
{
int SizeLength, TotalSize, TotalLength;

FILE *fp= fopen( "Bill.dat", "rb" );
if( NULL== fp )
{
system( "cls" );

cout<< "Cannot open file!!";

exit( 1 );
}

fseek( fp, 0, SEEK_END );
SizeLength= ftell( fp );
TotalLength= sizeof( customer );
TotalSize= SizeLength/ TotalLength;

fseek( fp, ( TotalSize- 1)* SizeLength, SEEK_END );
fread( &customer, sizeof( customer ), 1, fp );

system( "cls" );
gotoxy( 18, 3 );
cout<< "★☆☆CUSTOMER BILLING SYSTEM☆☆★";
gotoxy( 24, 4 );
cout<< "Appending........";

gotoxy( 20, 7 );
customer.number++;
textcolor( 12 );
cout<< "Customer No: "<< customer.number;
textcolor( 14 );

gotoxy( 24, 9 );
cout<< "Account number: ";
textcolor( 12 );
cin>> customer.acct_no;
textcolor( 14 );

gotoxy( 24, 10 );
cout<< "Name: ";
textcolor( 12 );
cin>> customer.name;
textcolor( 14 );

gotoxy( 24, 11 );
cout<< "Mobile No: ";
textcolor( 12 );
    cin>> customer.mobile_no;
    textcolor( 14 );
    
    gotoxy( 24, 12 );
    cout<< "Street: ";
    textcolor( 12 );
    cin>> customer.street ;
    textcolor( 14 );
    
    gotoxy( 24, 13 );
    cout<< "City: ";
    textcolor( 12 );
    cin>>customer.city;
    textcolor( 14 );
    
    gotoxy( 24, 14 );
    cout<< "Precvious balance: ";
    textcolor( 12 );
    cin>> customer.oldbalance;
    textcolor( 14 );
    
    gotoxy( 24, 15 );
    cout<< "Current payment: ";
    textcolor( 12 );
    cin>> customer.payment;
    textcolor( 14 );
    
    gotoxy( 24, 16 );
    cout<< "Payment date( dd mm yy ): ";
    textcolor( 12 );
    cin>> customer.lastpayment.day>> customer.lastpayment.month>> customer.lastpayment.year;
    textcolor( 14 );
    
    return ;    
}


void WriteFile( void )
{
FILE *fp;

fp= fopen( "Bill.dat", "ab" );
fwrite( &customer, sizeof( customer ), 1, fp );

fclose( fp );

return ;

}


void Search( void )
{
FILE *fp;
int TotalSize, TotalLength, SizeLength;
int choice;
int num;
char name[ 100 ];
int n;
int flag= 0;

fp= fopen( "Bill.dat", "rb" );
if( NULL== fp )
{
system( "cls" );
textcolor( 14 );
gotoxy( 24, 11 );

exit( 1 );
}


system( "cls" );
gotoxy( 18, 2 );
cout<< "★☆☆CUSTOMER BILLING SYSTEM☆☆★";

gotoxy( 24, 4 );
cout<< "1.) Search by customer numuber ";

gotoxy( 24, 5 );
cout<< "2.) Search by customer name ";

gotoxy( 24, 7 );
cout<< "Enter your choice(1/ 2): ";
cin>>choice;

gotoxy( 24, 9 );
    cout<< "Searching...........";

switch( choice )
{
case 1:
{
fseek( fp, 0, SEEK_END );
TotalLength= ftell( fp );
SizeLength= sizeof( customer );

TotalLength= TotalLength/ SizeLength;

gotoxy( 24, 11 );
cout<< "Enter customer number: ";
cin>> num;

if( num<= 0 && num> TotalSize )
{
gotoxy( 24, 13 );
cout<< "Please,Enter correct!!!";
}
else
{
fseek( fp, ( num- 1 )* SizeLength, SEEK_SET );
fread( &customer, SizeLength, 1, fp );

Output();  // printing
}

break;
}
case 2:
{
fseek( fp, 0, SEEK_END );
TotalLength= ftell( fp );
SizeLength= sizeof( customer );

TotalSize= TotalLength/ SizeLength;

fseek( fp, ( TotalSize- 1 )* SizeLength, SEEK_SET );
fread( &customer, sizeof( customer), 1, fp );

n= customer.number;

gotoxy( 24, 11 );
cout<< "Enter the name: ";
textcolor( 12 );
cin>> name;
textcolor( 14 );

fseek( fp, 0, SEEK_SET );

for( int i= 0; i<= n; i++ )
{
fread( &customer, sizeof( customer), 1, fp );
if( strcmp( customer.name, name )== 0 )
{
Output();    // If found, the print
flag= 1;

break; 
}
}

if( flag== 0 )
{
gotoxy( 24, 13 );
textcolor( 14 );
cout<< "Not Found!!";
textcolor( 12 );

gotoxy( 24, 15 );
cout<< "Press any key to continue.";
}
}

   fclose( fp );
}

getch();

return ;
}

void Output( void )
{
system( "cls" );
gotoxy( 15, 2 );
cout<< "★☆☆CUSTOMER BILLING SYSTEM☆☆★";
textcolor( 14 );

gotoxy( 18, 4 );
cout<< "Showing...........";

gotoxy( 18, 6 );
textcolor( 12 );
cout<< "Customer No: ";
cout<< customer.number;
textcolor( 14 );

gotoxy( 24, 7 );
cout<< "Name:";
textcolor( 12 );
cout<< customer.name;
textcolor( 14 );

gotoxy( 24, 8 );
cout<< "Mobile No: ";
textcolor( 12 );
cout<< customer.mobile_no;
textcolor( 14 );

gotoxy( 24, 9 );
cout<< "Account number: ";
textcolor( 12 );
cout<< customer.acct_no;
textcolor( 14 );

gotoxy( 24, 10 );
cout<< "Street: ";
textcolor( 12 );
cout<< customer.street;
textcolor( 14 );

gotoxy( 24, 11 );
cout<<"City: ";
textcolor( 12 );
cout<< customer.city;
textcolor( 14 );

gotoxy( 24, 12 );
cout<< "Old balance: ";
textcolor( 12 );
cout<< customer.oldbalance ;
textcolor( 14 );

gotoxy( 24, 13 );
cout<< "Current Payment: ";
textcolor( 12 );
cout<< customer.payment;
textcolor( 14 );

gotoxy( 24, 14 );
cout<< "New balance: ";
textcolor( 12 );
cout<< customer.newbalance;
textcolor( 14 );

gotoxy( 24, 15 );
cout<< "Payment date: ";
textcolor( 12 );
cout<< customer.lastpayment.year
    << "/"<< customer.lastpayment.month<< "/"<<customer.lastpayment.day; 
textcolor( 14 );

gotoxy( 24, 16 );
cout<< "Account status: ";
textcolor( 12 );
switch( customer.acct_type )
{
case 'C':
{
cout<< "CURRENT";

   break;
}
case 'O':
{
cout<< "OVERDUE";

break;
}
case 'D':
{
cout<< "DELINQUENT";

break;
}
default:
{
cout<< "ERROR";

break;
}

}
textcolor( 14 );

gotoxy( 24, 20 );
cout<< "Press any key continue.";

getch();

return ;

}

Package Source link:Here
ScreenShot:








Sep 28, 2014

Mathematical Operation

1:48 AM Posted by Unknown , No comments
//Author   :LearningPen
//Date     : 28/9/2014
//Language : C++
//Tool     : Dev C++

//Notice:Reference http://www.sourcecodester.com/cc/7937/c-functions-basic-mathematical-operation.html

#include <iostream>
#include <windows.h>  // for system...
#include <conio.h>    //getch()

using std::cout;
using std::cin;


class MathOp
{
public:
void addition( int num1, int num2 );
void subtraction( int num1, int num2 );
void multiplication( int num1, int num2 );
void division( int num1, int num2 );

};

void Menu( void );
void gotoxy( int x, int y );
void textcolor( int color );

//-------Main function ---------------------
int main(int argc, char** argv)
{
int choice;
int num1, num2;
MathOp algorithm;

do
{

Menu();

textcolor( 11 );
gotoxy( 22, 16 );
cout<< "Enter your choice : ";
cin>> choice;

if( choice>= 1 && choice< 5 )
{

   system( "cls" );
textcolor( 14 );
gotoxy( 18, 4);
cout<< "*******************************";
gotoxy( 18, 5 );
cout<< "*   Mathemactical Operation   *";
gotoxy( 18, 6 );
cout<< "*******************************";

gotoxy( 22, 8 );
cout<< "Please enter two numbers.";

gotoxy( 22, 10 );
cout<< "Num1: ";
cin>> num1;

gotoxy( 22, 11 );
cout<< "Num2: ";
cin>> num2;
  }

switch( choice )
{

case 1:
{
gotoxy( 22, 13 );
algorithm.addition( num1, num2 );

gotoxy( 22, 15 );
           cout<< "Press any key return Menu.";
         
break;
}
case 2:
{
gotoxy( 22, 13 );
algorithm.subtraction( num1, num2 );

gotoxy( 22, 15 );
           cout<< "Press any key return Menu.";
         
break;
}
case 3:
{
gotoxy( 22, 13 );
algorithm.multiplication( num1, num2 );

gotoxy( 22, 15 );
           cout<< "Press any key return Menu.";

break;
}
case 4:
{
gotoxy( 22, 13 );
algorithm.division( num1, num2 );

gotoxy( 22, 15 );
           cout<< "Press any key return Menu.";
         
break;
}
default:
{
gotoxy( 22, 18 );
           cout<< "Press any key return Menu.";
}
}


getch();

}while( choice!= 5);


return 0;
}

//---------Other function----------------------
void gotoxy( int x, int y )
{
COORD pos= { 0, 0 };

pos.X= x;
pos.Y= y;

HANDLE handle= GetStdHandle( STD_OUTPUT_HANDLE );

SetConsoleCursorPosition( handle, pos );

return ;
}

void textcolor( int color )
{
HANDLE handle= GetStdHandle( STD_OUTPUT_HANDLE );

SetConsoleTextAttribute( handle, color );

return ;
}
void Menu( void )
{
system( "cls" );
gotoxy( 18 , 4 );
textcolor( 14 );
     
cout<< "*******************************";
gotoxy( 18, 5 );
cout<< "*   Mathemactical Operation   *";
gotoxy( 18, 6 );
cout<< "*******************************";

gotoxy( 22, 8 );
cout<< " 1.) Addition ";

gotoxy( 22, 9 );
cout<< " 2.) Subtraction ";

gotoxy( 22, 10 );
cout<< " 3.) Multiplication ";

gotoxy( 22, 11 );
cout<< " 4.) Division ";

gotoxy( 22, 12 );
cout<< " 5.) Exit ";

gotoxy( 18, 14 );
cout<< "*******************************";

return ;
}

//--------Class function -----------
void MathOp::addition( int num1, int num2 )
{
cout<< num1<< " + "<< num2<< " = "<< num1+ num2;

return ;
}

void MathOp::subtraction( int num1, int num2 )
{          
cout<< num1<< " - "<< num2<< " = "<< num1- num2;

return ;
}

void MathOp::multiplication( int num1, int num2 )
{
cout<< num1<< " * "<< num2<< " = "<< num1* num2;

return ;
}

void MathOp::division( int num1, int num2 )
{
if( num2== 0 )
{
system( "cls" );

cout<< "Dividend cannot be zero!!";

Sleep( 1000 );

exit( 1 );
}

cout<< num1<< " / "<< num2<< " = "<< num1/ num2;

return ;
}


Screenshot: