Tuesday, 27 January 2015

Solar System

#include<graphics.h>
#include<conio.h>
#include<iostream.h>
#include<dos.h>
#define RIGHT 77
#define LEFT 75
#include<stdlib.h>
#include<math.h>
# define pi M_PI
#define mx getmaxx()/2
#define my getmaxy()/2-30

void count(float &s,float &t,float &u,float i,float j,float r);

class Spr{
private :

float cosa,cosb,sina,sinb;

public :
void ini(float cos1,float cos2);
void plot(float x,float y,float z,int &x1,int &y1);
void plot1(float x,float y,float z,int xx,int yy,int &x1,int &y1);
void plot3d1(float x,float y,float z,int xx,int yy,int cl);
void plot3d(float s,float t,float u,int cl);
};



void Spr::ini(float cos1,float cos2)
{
 cosa=cos(cos1*pi/180);
 cosb=cos((cos2)*pi/180);
 sina=sin(cos1*pi/180);
 sinb=sin((cos2)*pi/180);
}
void Spr::plot(float x,float y,float z,int &x1,int &y1)
{
 x1=x*cosa-y*sina;
 y1=x*sina*sinb+y*cosa*sinb+z*cosb;
 x1=320+int(x1);
 y1=240-int(y1);
}
void Spr::plot1(float x,float y,float z,int xx,int yy,int &x1,int &y1)
{
float xx1,yy1;
 xx1=x*cosa-y*sina;
 yy1=x*sina*sinb+y*cosa*sinb+z*cosb;
 x1=xx+int(xx1);
 y1=yy+int(yy1);
}
void Spr::plot3d(float s,float t,float u,int cl)
{
int x1,y1;
plot(s,t,u,x1,y1);
putpixel(x1,y1,cl);
}
void Spr::plot3d1(float x,float y,float z,int xx,int yy,int cl)
{
float xx1,yy1;
int x1,y1;
 xx1=x*cosa-y*sina;
 yy1=x*sina*sinb+y*cosa*sinb+z*cosb;
 x1=xx+int(xx1);
 y1=yy+int(yy1);
 putpixel(x1,y1,cl);
}
void count(float &s,float &t,float &u,float j,float i,float r)
{
s=(r)*cos(i*pi/180.0)*sin(j*pi/180.0);
     t=(r)*sin(i*pi/180.0)*sin(j*pi/180.0);
     u=(r)*cos(j*pi/180.0);
     }



void main()
{
int gd=DETECT,gm;
  initgraph(&gd,&gm,"\\tc\\bgi");
  Spr a[10],b[10];
  float p[10],p1[10],df,s,t,u,rd[10],r1[10],d,i,j;
   int x[20],y[20];
   for(i=0;i<10;i++)
   {
  p[i]=0.0;
  p1[i]=0.0;
  }
  s=90.0;
  d=1.0;
  rd[0]=55.0;
  rd[1]=18.0;
  rd[2]=23.0;
  rd[3]=22.0;
  rd[4]=24.0;
  rd[5]=40.0;
  rd[6]=40.0;
  r1[1]=100.0;
  r1[2]=155.0;
  r1[3]=210.0;
  r1[4]=270.0;
  r1[5]=250.0;
  r1[6]=250.0;

while(1)
  {

   a[0].ini(p[0],45+90);
   a[1].ini(p[1],45+90);
   a[2].ini(p[2],45+90);
   a[3].ini(p[3],45+90);
   a[4].ini(p[4],45+90);
   a[5].ini(p[5],45+90);
   a[6].ini(p[6],45+90);
   b[1].ini(p1[1],40+90);
   b[2].ini(p1[2],40+90);
   b[3].ini(p1[3],40+90);
  /* b[4].ini(p1[4],p[4]+90);
   b[5].ini(p1[5],p[5]+90);*/
   b[4].ini(p1[4],40+90);
   b[5].ini(p1[5],40+90);
   b[6].ini(p1[6],40+90);
   b[1].plot(r1[1],0,0,x[1],y[1]);
   b[2].plot(r1[2],0,0,x[2],y[2]);
   b[3].plot(r1[3],0,0,x[3],y[3]);
   b[4].plot(r1[4],0,0,x[4],y[4]);
   b[5].plot(r1[5],0,0,x[5],y[5]);
   b[6].plot(r1[6],0,0,x[6],y[6]);
   for( i=0.0;i<360.0;i+=5.0)
    {
    b[1].plot3d(r1[1]*cos(i*pi/180.0),r1[1]*sin(i*pi/180.0),0,10);
    b[2].plot3d(r1[2]*cos(i*pi/180.0),r1[2]*sin(i*pi/180.0),0,7);
    b[3].plot3d(r1[3]*cos(i*pi/180.0),r1[3]*sin(i*pi/180.0),0,6);
    b[4].plot3d(r1[4]*cos(i*pi/180.0),r1[4]*sin(i*pi/180.0),0,7);
   // b[5].plot3d(r1[5]*cos(i*pi/180.0),r1[5]*sin(i*pi/180.0),0,4);
   // b[6].plot3d(r1[6]*cos(i*pi/180.0),r1[6]*sin(i*pi/180.0),0,3);
    }
  for( j=0.0;j<360.0;j+=15.0)
    {
    for( i=0.0;i<360.0;i+=13.0)
    {
    count(s,t,u,j,i,rd[0]);
     a[0].plot3d(s,t,u,14);
     count(s,t,u,j,i,rd[1]);
     a[1].plot3d1(s,t,u,x[1],y[1],12);
      count(s,t,u,j,i,rd[2]);
     a[2].plot3d1(s,t,u,x[2],y[2],10);
     count(s,t,u,j,i,rd[3]);
     a[3].plot3d1(s,t,u,x[3],y[3],11);
     count(s,t,u,j,i,rd[4]);
     a[4].plot3d1(s,t,u,x[4],y[4],7);
     /*count(s,t,u,j,i,rd[5]);
     a[5].plot3d1(s,t,u,x[5],y[5],5);
     count(s,t,u,j,i,rd[2]);
     a[6].plot3d1(s,t,u,x[6],y[6],6); */

}
    }
    //delay(1);
   cleardevice();
    p[0]+=2.0;
    p[1]+=0.8;
    p[2]+=0.7;
    p[3]+=0.8;
    p[4]+=0.6;
    p[5]+=0.5;
    p[6]+=0.2;
    p1[1]+=0.2;
     p1[2]-=0.1;
     p1[3]+=0.3;
     p1[4]-=0.4;
     p1[5]+=0.5;
     p1[6]+=0.5;
    // rd[0]+=d;
    if(0)
    {
    rd[0]+=d;
    if(rd[0]>10)
    {d=-1;}
    if(rd[0]<80)
    {
    d=1;
    }
    }
    if(kbhit())
    {
    closegraph();
    exit(1);
    }
  }

}


Air ticket reservation

/*---------------------------------------------------------------------------
PROJECT AIR TICKET RESRVATION
 
PROJECT DESIGN BY : PRITAM BANIK
---------------------------------------------------------------------------
INCLUDED HEADER FILES
---------------------------------------------------------------------------*/

#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include <dos.h>


//---------------------------------------------------------------------------
//  THIS CLASS DRAW LINES, BOXES, ETC.
//---------------------------------------------------------------------------

class DRAW
{
public :
void LINE_HOR(int, int, int, char) ;
void LINE_VER(int, int, int, char) ;
void BOX(int,int,int,int,char) ;
} ;






//---------------------------------------------------------------------------
// THIS CLASS CONTROLS ALL THE FUNCTIONS RELATED TO TICKETS
//---------------------------------------------------------------------------

class TICKET
{
public :
void ADDITION(void) ;
void ENQUIRY(void) ;
char *FLIGHTNO(int) ;
private :
void ADD_RECORD(char[10], char[15], char[15], int, int) ;

protected :
char fltno[10], from[15], to[15] ;
int ecofair, exefair ;
} ;

//---------------------------------------------------------------------------
// THIS CLASS CONTROLS ALL THE FUNCTIONS RELATED TO PASSENGERS
//---------------------------------------------------------------------------

class PASSANGER
{
public :
void ADD_RECORD(int, int, char[26], char[36], int, char, char) ;
void DELETE_TICKET(int) ;
int DELETE_FLIGHT(int) ;
void LIST(void) ;
int LAST_TICKETNO(void) ;
int SEATS(int) ;
int FOUND(int) ;
char *NAME(int) ;
protected :
char Class, name[26], address[36], sex ;
int slno, age, ticketno ;
} ;

//---------------------------------------------------------------------------
// THIS IS DERIVED CLASS WHICH CONTROLS ALL THE FUNCTIONS
// RELATED TO RESERVATION, CANCELLATION, ETC.
//---------------------------------------------------------------------------

class RESERVE : public TICKET, public PASSANGER
{
public :
void RESERVATION(void) ;
void CANCELLATION(void) ;
void DISPLAY_TICKET(void) ;
void DELETE_ALL(void) ;
} ;

//---------------------------------------------------------------------------
// FUNCTION TO DRAW HORIZONTAL LINE
//---------------------------------------------------------------------------

void DRAW :: LINE_HOR(int coloumn1, int coloumn2, int row, char c)
{
for (coloumn1; coloumn1<=coloumn2; coloumn1++ )
{
gotoxy(coloumn1,row) ;
cout <<c ;
}
}

//---------------------------------------------------------------------------
// FUNCTION TO DRAW VERTICAL LINE
//---------------------------------------------------------------------------

void DRAW :: LINE_VER(int row1, int row2, int coloumn, char c)
{
for ( row1 ; row1<=row2; row1++ )
{
gotoxy(coloumn,row1) ;
cout <<c ;
}
}

//---------------------------------------------------------------------------
// FUNCION TO DRAW BOX
//---------------------------------------------------------------------------

void DRAW :: BOX(int column1, int row1, int column2, int row2, char c)
{
char ch=218 ;
char c1, c2, c3, c4 ;
char c11=196, c12 = 179 ;
if (c == ch)
{
c1=218 ;
c2=191 ;
c3=192 ;
c4=217 ;
c11 = 196 ;
c12 = 179 ;
}
else
{
c1=c ;
c2=c ;
c3=c ;
c4=c ;
c11 = c ;
c12 = c ;
}
gotoxy(column1,row1) ;
cout <<c1 ;
gotoxy(column2,row1) ;
cout <<c2 ;
gotoxy(column1,row2) ;
cout <<c3 ;
gotoxy(column2,row2) ;
cout <<c4 ;
column1++ ;
column2-- ;
LINE_HOR(column1,column2,row1,c11) ;
LINE_HOR(column1,column2,row2,c11) ;
column1-- ;
column2++ ;
row1++;
row2--;
LINE_VER(row1,row2,column1,c12) ;
LINE_VER(row1,row2,column2,c12) ;

}

//---------------------------------------------------------------------------
// FUNCTION TO ADD GIVEN DATA IN THE TICKET FILE(TICKET.DAT)
//---------------------------------------------------------------------------

void TICKET :: ADD_RECORD(char t_fltno[10], char t_from[15], char t_to[15], int t_ecofair, int t_exefair)
{
fstream file ;
file.open("TICKET.DAT", ios::app) ;
strcpy(fltno,t_fltno) ;
strcpy(from,t_from) ;
strcpy(to,t_to) ;
ecofair = t_ecofair ;
exefair = t_exefair ;
file.write((char *) this , sizeof(TICKET)) ;
file.close() ;
}

//---------------------------------------------------------------------------
// FUNCTION TO RETURN FLIGHT NO. FOR THE GIVEN S.NO
//---------------------------------------------------------------------------

char *TICKET :: FLIGHTNO(int sno)
{
fstream file ;
file.open("TICKET.DAT", ios ::in) ;
int count=1 ;
while (file.read((char *) this, sizeof(TICKET)))
{
if (sno == count)
break ;
count++ ;
}
file.close() ;
return fltno ;
}

//---------------------------------------------------------------------------
// FUNCTION TO GIVES DATA TO ADD RECORDS IN TICKET FILE
//---------------------------------------------------------------------------

void TICKET :: ADDITION(void)
{
fstream file ;
file.open("TICKET.DAT", ios::in) ;
if (!file.fail())
return ;
file.close() ;
ADD_RECORD("KL146","DELHI","MUMBAI",1500,1700) ;
ADD_RECORD("KL146","MUMBAI","DELHI",1500,1700) ;
ADD_RECORD("KL156","DELHI","CALCUTTA",1700,1900) ;
ADD_RECORD("KL156","CALCUTTA","DELHI",1700,1900) ;
ADD_RECORD("KL166","DELHI","MADRAS",2100,2300) ;
ADD_RECORD("KL166","MADRAS","DELHI",2100,2300) ;
ADD_RECORD("KL176","MUMBAI","CALCUTTA",1900,2100) ;
ADD_RECORD("KL176","CALCUTTA","MUMBAI",1900,2100) ;
ADD_RECORD("KL186","MUMBAI","MADRAS",1800,2000) ;
ADD_RECORD("KL186","MADRAS","MUMBAI",1800,2000) ;
ADD_RECORD("KL196","CALCUTTA","MADRAS",1600,1800) ;
ADD_RECORD("KL196","MADRAS","CALCUTTA",1600,1800) ;
}

//---------------------------------------------------------------------------
// FUNCTION TO DISPLAY LIST OF FLIGHTS
//---------------------------------------------------------------------------

void TICKET :: ENQUIRY(void)
{
clrscr() ;
fstream file ;
file.open("TICKET.DAT", ios::in) ;
DRAW d ;
d.BOX(1,2,80,24,218) ;
d.LINE_HOR(2,79,4,196) ;
d.LINE_HOR(2,79,6,196) ;
d.LINE_HOR(2,79,22,196) ;
textcolor(GREEN+BLINK) ;
gotoxy(30,3) ;
cprintf ("LIST OF THE FLIGHTS") ;
textcolor(LIGHTGRAY) ;
textcolor(GREEN) ;
textbackground(WHITE) ;
for (int i=2; i<=79; i++)
{
gotoxy(i,5) ;
cprintf(" ") ;
}
gotoxy(2,5) ;
cprintf(" Sno. FLIGHT NO.   FROM         TO          ECONOMIC FAIR     EXECUTIVE FAIR") ;
textcolor(LIGHTGRAY) ;textbackground(BLACK) ;
int row=7, sno=1 ;
while (file.read((char *) this, sizeof(TICKET)))
{
gotoxy(4,row) ;
cout <<sno ;
gotoxy(9,row) ;
cout <<fltno ;
gotoxy(20,row) ;
cout <<from ;
gotoxy(34,row) ;
cout <<to ;
gotoxy(52,row) ;
cout <<ecofair ;
gotoxy(67,row) ;
cout <<exefair ;
row++ ;
sno++ ;
}
file.close() ;
}

//---------------------------------------------------------------------------
// FUNCTION TO RESERVE TICKET FOR THE PASSANGER
//---------------------------------------------------------------------------

void RESERVE :: RESERVATION(void)
{
clrscr() ;
ENQUIRY() ;
char t1[5], pclass, pname[26], paddress[36], psex, pfltno[10] ;
int t2, valid, page,tno,sno ;
PASSANGER p ;
tno = p.LAST_TICKETNO() + 1 ;
do
{
valid = 1 ;
gotoxy(3,23) ;
cout <<" " ;
gotoxy(3,23) ;
cout <<"PRESS <ENTER> TO EXIT" ;
gotoxy(3,20) ;
cout <<" ";
gotoxy(3,20) ;
cout <<"ENTER Sno. of the FLIGHT : " ;
gets(t1) ;
t2 = atoi(t1) ;
sno = t2 ;
if  (strlen(t1) == 0)
return ;
if (sno < 1 || sno >12)
{
valid = 0 ;
gotoxy(3,23) ;
cout <<" " ;
gotoxy(3,23) ;
cout <<"\7ENTER CORRECTLY" ;
getch() ;
}
} while (!valid) ;
int i=1 ;
fstream file ;
file.open ("TICKET.DAT",ios::in);
while (file.read((char *) this, sizeof(TICKET)))
{
if (sno == i)
break ;
i++ ;
}
file.close() ;
strcpy(pfltno,fltno) ;
if (p.SEATS(sno) >= 250)
{
gotoxy(5,21) ;
cout <<"\7Sorry! Seats are not available." ;
getch() ;
return ;
}
gotoxy(3,23) ;
cout <<" " ;
gotoxy(3,23) ;
cout <<"E=ECONOMIC, X=EXECUTIVE or PRESS <ENTER> TO EXIT" ;
do
{
gotoxy(3,21) ;
cout <<" " ;
gotoxy(3,21) ;
cout <<"By which Class you want to travel : " ;
pclass = getche() ;
pclass = toupper(pclass) ;
if (pclass == 13)
return ;
} while (pclass != 'E' && pclass !='X') ;
clrscr() ;
gotoxy(72,3) ;
cout <<"<0>=EXIT" ;
gotoxy(34,2) ;
cout <<"RESERVATION" ;
gotoxy(5,5) ;
cout <<"NAME :" ;
gotoxy(5,6) ;
cout <<"ADDRESS :" ;
gotoxy(5,7) ;
cout <<"SEX M/F :" ;
gotoxy(5,8) ;
cout <<"AGE :" ;
do
{
valid = 1 ;
gotoxy(5,25) ; clreol () ;
cout <<"ENTER NAME OFTHE PASSENGER" ;
gotoxy(15,5) ; clreol() ;
gets(pname) ;
if (pname[0] == '0')
return ;
if (strlen(pname) < 1 || strlen(pname) >25)
{
valid = 0 ;
gotoxy(5,25) ; clreol() ;
cout <<"\7Enter Correctly (Range: 1..25)" ;
getch() ;
}
} while (!valid) ;
do
{
valid = 1;
gotoxy(5,25) ; clreol() ;
cout <<"ENTER ADDRESS OF THE PASSENGER" ;
gotoxy(15,6) ; clreol() ;
gets(paddress) ;
if (paddress[0] == '0')
return ;
if (strlen(paddress) < 1 || strlen(paddress) >35)
{
valid = 0 ;
gotoxy(5,25) ; clreol() ;
cout <<"\7Enter Correctly (Range: 1..35)" ;
getch() ;
}
} while (!valid) ;
do
{
gotoxy(5,25) ; clreol() ;
cout <<"ENTER SEX OF THE PASSENGER" ;
gotoxy(15,7) ; clreol() ;
psex = getche() ;
psex = toupper(psex) ;
if (psex == '0')
return ;
} while (psex != 'M' && psex != 'F') ;
do
{
valid = 1 ;
gotoxy(5,25) ; clreol() ;
cout <<"ENTER AGE OF THE PASSENGER" ;
gotoxy(15,8) ; clreol() ;
gets(t1) ;
t2 = atoi(t1) ;
page = t2 ;
if (t1[0] == '0')
return ;
if (page <1 || page >150)
{
valid = 0 ;
gotoxy(5,25) ; clreol() ;
cout <<"\7ENTER CORRECTLY" ;
getch() ;
}
} while (!valid) ;
clrscr() ;
DRAW d ;
d.BOX(15,5,66,21,'*') ;
d.LINE_HOR(16,65,7,'*') ;
gotoxy(33,6) ;
cout <<"Ticket no. " <<tno ;
gotoxy(17,9) ;
cout <<from <<" to " <<to ;
gotoxy(45,9) ;
cout <<"Flight no. " <<pfltno ;
gotoxy(20,11) ;
cout <<"Passanger Name : " <<pname ;
gotoxy(20,13) ;
cout <<"Address : " <<paddress ;
gotoxy(20,15) ;
cout <<"Sex : " <<psex ;
gotoxy(20,17) ;
cout <<"Age : " <<page ;
gotoxy(45,19) ;
if (pclass == 'E')
cout <<"Total Fair: " <<ecofair ;
else
cout <<"Total Fair: " <<exefair ;
p.ADD_RECORD(tno,sno,pname,paddress,page,psex,pclass) ;
getch() ;
}

//---------------------------------------------------------------------------
// FUNCTION TO ADD THE GIVEN DATA IN THE PASSANGER'S FILE
//---------------------------------------------------------------------------

void PASSANGER :: ADD_RECORD(int tno, int sno, char pname[26], char paddress[36], int page, char psex, char pclass)
{
fstream file ;
file.open("PASS.DAT", ios::app) ;
ticketno = tno ;
slno = sno ;
strcpy(name,pname) ;
strcpy(address,paddress) ;
age = page ;
sex = psex ;
Class = pclass ;
file.write((char *) this, sizeof(PASSANGER)) ;
file.close() ;
}

//---------------------------------------------------------------------------
// THIS FUNCTION RETURN THE LAST TICKETNO. IN THE PASSANGER FILE
//---------------------------------------------------------------------------

int PASSANGER :: LAST_TICKETNO(void)
{
fstream file ;
file.open("PASS.DAT", ios::in) ;
int count=0 ;
while (file.read((char *) this, sizeof(PASSANGER)))
count = ticketno ;
file.close() ;
return count ;
}

//---------------------------------------------------------------------------
// THIS FUNCTION RETURN TOTALNO. OF SEATS IN THE PASSAGER FILE
//---------------------------------------------------------------------------

int PASSANGER :: SEATS(int sno)
{
fstream file;
file.open("PASS.DAT", ios::in) ;
int count = 0 ;
while (file.read((char *) this, sizeof(PASSANGER)))
{
if (sno == slno)
count++ ;
}
file.close() ;
return count ;
}

//---------------------------------------------------------------------------
// THIS FUNCTION RETURN 0 IF THE TICKET NO. NOT FOUND IN PASSANGER'S FILE
//---------------------------------------------------------------------------

int PASSANGER :: FOUND(int tno)
{
fstream file ;
file.open("PASS.DAT", ios::in) ;
int found=0 ;
while (file.read((char *) this, sizeof(PASSANGER)))
{
if (tno == ticketno)
{
found = 1 ;
break ;
}
}file.close() ;
return found ;
}

//---------------------------------------------------------------------------
// THIS FUNCTION RETRNS PASSANGER'S NAME FOR THE GIVEN TICKET NO.
//---------------------------------------------------------------------------

char *PASSANGER :: NAME(int tno)
{
fstream file ;
file.open("PASS.DAT", ios::in) ;
while (file.read((char *) this, sizeof (PASSANGER)))
{
if (tno == ticketno)
break ;
}
file.close() ;
return name ;
}

//---------------------------------------------------------------------------
// THIS FUNCTION DISPLAY THE LIST OF THE PASSANGERS
//---------------------------------------------------------------------------

void PASSANGER :: LIST(void)
{
clrscr() ;
char t1[10] ;
int t2, sno, valid ;
TICKET ticket ;
ticket.ENQUIRY() ;
do
{
valid = 1 ;
gotoxy(3,23) ;
cout <<" " ;
gotoxy(3,23) ;
cout <<"PRESS <ENTER> TO EXIT" ;
gotoxy(3,20) ;
cout <<" " ;
gotoxy(3,20) ;
cout<<"Enter Sno. of the FLIGHT for which you want to see list of passanger";
gets(t1) ;
t2 = atoi(t1) ;
sno = t2 ;
if (strlen(t1) == 0)
return ;
if (sno < 1 || sno > 12)
{
valid = 0 ;
gotoxy(3,23) ;
cout <<" " ;
gotoxy(3,23) ;
cout <<"\7ENTER CORRECTLY" ;
getch() ;
}
} while (!valid) ;
clrscr() ;
int row=7, found=0, flag=0 ;
char ch ;
DRAW d;
d.BOX(1,2,80,24,218) ;
d.LINE_HOR(2,79,4,196) ;
d.LINE_HOR(2,79,6,196) ;
d.LINE_HOR(2,79,22,196) ;
gotoxy(3,3) ;
cout <<"Flight no. "<<ticket.FLIGHTNO(sno) ;
gotoxy(32,3) ;
cout<<"LIST OF PASSANGER" ;
textcolor(BLACK) ; textbackground(WHITE) ;
gotoxy(2,5) ;
cprintf(" TICKET NO.   NAME CLASS ") ;
textcolor(LIGHTGRAY) ; textbackground(BLACK) ;
fstream file ;
file.open("PASS.DAT", ios::in) ;
file.seekg(0,ios::beg) ;
while (file.read((char *) this, sizeof(PASSANGER)))
{
if (sno == slno)
{
flag = 0 ;
    //   delay(20) ;
found =1 ;
gotoxy(5,row) ;
cout <<ticketno ;
gotoxy(17,row) ;
cout <<name ;
gotoxy(49,row) ;
if (Class == 'X')
cout <<"Executive" ;
else
cout <<"Economic" ;
if ( row == 21 )
{
flag = 1 ;
row = 7 ;
gotoxy(5,23) ;
cout <<"Press any key to continue or Press <ESC> to exit";
ch = getch() ;
if (ch == 27)
break ;
clrscr() ;
d.BOX(1,2,80,24,218) ;
d.LINE_HOR(2,79,4,196) ;
d.LINE_HOR(2,79,6,196) ;
d.LINE_HOR(2,79,22,196) ;
gotoxy(2,5) ;
cprintf(" TICKET NO. NAME FLIGHT NO. CLASS ") ;
textcolor(LIGHTGRAY) ; textbackground(BLACK) ;
}
else
row++ ;
}
}
if (!found)
{
gotoxy(5,10) ;
cout <<"\7Records not found" ;
}
if (!flag)
{
gotoxy(5,23) ;
cout <<"Press any key to continue..." ;
getch() ;
}
file.close() ;
}

//---------------------------------------------------------------------------
// THIS FUNCTION DELETES PASSANGER RECORD FOR THE GIVEN TICKET NO.
//---------------------------------------------------------------------------

void PASSANGER :: DELETE_TICKET(int tno)
{
fstream file ;
file.open("PASS.DAT", ios::in) ;
fstream temp ;
temp.open("temp.dat", ios::out) ;
file.seekg(0,ios::beg) ;
while (!file.eof())
{
file.read((char *) this, sizeof(PASSANGER)) ;
if (file.eof())
break;
if (tno != ticketno)
temp.write((char *) this, sizeof(PASSANGER)) ;
}
file.close();
temp.close() ;
file.open("PASS.DAT", ios::out) ;
temp.open("temp.dat", ios::in) ;
temp.seekg(0,ios::beg) ;
while ( !temp.eof() )
{
temp.read((char *) this, sizeof(PASSANGER)) ;
if (temp.eof() )
break ;
file.write((char *) this, sizeof(PASSANGER)) ;
}
file.close() ;
temp.close() ;
}

//---------------------------------------------------------------------------
// THIS FUNCTION DELETES ALL PASSANGER RECORD FOR THE GIVEN FLIGHT NO.
//---------------------------------------------------------------------------

int PASSANGER :: DELETE_FLIGHT(int sno)
{
fstream file ;
file.open("PASS.DAT", ios::in) ;
fstream temp ;
temp.open("temp.dat", ios::out) ;
file.seekg(0,ios::beg) ;
int found = 0 ;
while (!file.eof())
{
file.read((char *) this, sizeof(PASSANGER)) ;
if (file.eof())
break;
if (sno != slno)
temp.write((char *) this, sizeof(PASSANGER)) ;
else
found = 1 ;
}
file.close();
temp.close() ;
file.open("PASS.DAT", ios::out) ;
temp.open("temp.dat", ios::in) ;
temp.seekg(0,ios::beg) ;
while ( !temp.eof() )
{
temp.read((char *) this, sizeof(PASSANGER)) ;
if (temp.eof() )
break ;
file.write((char *) this, sizeof(PASSANGER)) ;
}
file.close() ;
temp.close() ;
return found ;
}

//---------------------------------------------------------------------------
// THIS FUNCTION CANCELS PASSANGER'S TICKET
//---------------------------------------------------------------------------

void RESERVE :: CANCELLATION(void)
{
clrscr() ;
char t1[10], ch ;
int t2, tno, valid ;
do
{
valid =1 ;
gotoxy(3,23) ; clreol() ;
cout <<"PRESS <ENTER> TO SEE LIST or 0 TO EXIT" ;
gotoxy(3,20) ; clreol() ;
cout <<"Enter Ticket no. of the Passanger to cancel the Ticket" ;
gets(t1) ;
t2 = atoi(t1) ;
tno = t2 ;
if (t1[0] == '0')
{
valid = 0 ;
LIST() ;
clrscr() ;
}
} while (!valid) ;
clrscr() ;
fstream file ;
file.open("PASS.DAT", ios::in) ;
while (file.read((char *) this, sizeof(PASSANGER)))
if (ticketno == tno)
break ;
file.close() ;
int i = 1 ;
file.open("TICKET.DAT",ios::in) ;
while (file.read((char *) this, sizeof(TICKET)))
{
if (slno == i)
break ;
i++ ;
}
file.close() ;
PASSANGER p;
DRAW d;
d.BOX(15,5,66,21,'*') ;
d.LINE_HOR(16,65,7,'*') ;
gotoxy(33,6) ;
cout <<"Ticket no. " <<tno ;
gotoxy(17,9) ;
cout <<from <<" to " <<to ;
gotoxy(45,9) ;
cout <<"Flight no. "<<fltno ;
gotoxy(20,11) ;
cout <<"Passanger Name : " <<p.NAME(tno);
gotoxy(20,13) ;
cout <<"Address : " <<address ;
gotoxy(20,15) ;
cout <<"Sex : " <<sex ;
gotoxy(20,17) ;
cout <<"Age :" <<age ;
gotoxy(45,19) ;
if (Class == 'E')
cout <<"Total Fair: " <<ecofair ;
else
cout <<"Total Fair: " <<exefair ;
do
{
gotoxy(10,23) ; clreol() ;
cout <<"Cancel this ticket (y/n) : " ;
ch = getche() ;
ch = toupper(ch) ;
} while (ch != 'Y' && ch != 'N') ;
if (ch == 'N')
return ;
DELETE_TICKET(tno) ;
gotoxy(10,25) ;
cout <<"\7Ticket Cancelled" ;
getch() ;
}

//---------------------------------------------------------------------------
// THIS FUNCTION DISPLAY THE PASSANGER'S INFORMATION
//---------------------------------------------------------------------------

void RESERVE :: DISPLAY_TICKET(void)
{
clrscr() ;
char t1[10], ch ;
int t2, tno, valid ;
do
{
valid =1 ;
gotoxy(3,23) ; clreol() ;
cout <<"PRESS <ENTER> TO SEE LIST or 0 TO EXIT" ;
gotoxy(3,20) ; clreol() ;
cout <<"Enter Ticket no. of the Passanger " ;
gets(t1) ;
t2 = atoi(t1) ;
tno = t2 ;
if (t1[0] == '0')
return ;
if (strlen(t1) == 0)
{
valid = 0 ;
LIST() ;
clrscr() ;
}
if (!FOUND(tno) && valid)
{
valid = 0;
gotoxy(3,23) ; clreol() ;
cout <<"\7Record not found" ;
getch() ;
}
} while (!valid) ;
clrscr() ;
fstream file ;
file.open("PASS.DAT", ios::in) ;
while (file.read((char *) this, sizeof(PASSANGER)))
if (ticketno == tno)
break ;
file.close() ;
int i = 1 ;
file.open("TICKET.DAT",ios::in) ;
while (file.read((char *) this, sizeof(TICKET)))
{
if (slno == i)
break ;
i++ ;
}
file.close() ;
PASSANGER p;
DRAW d;
d.BOX(15,5,66,21,'*') ;
d.LINE_HOR(16,65,7,'*') ;
gotoxy(33,6) ;
cout <<"Ticket no. " <<tno ;
gotoxy(17,9) ;
cout <<from <<" to " <<to ;
gotoxy(45,9) ;
cout <<"Flight no. "<<fltno ;
gotoxy(20,11) ;
cout <<"Passanger Name : " <<p.NAME(tno);
gotoxy(20,13) ;
cout <<"Address : " <<address ;
gotoxy(20,15) ;
cout <<"Sex : " <<sex ;
gotoxy(20,17) ;
cout <<"Age :" <<age ;
gotoxy(45,19) ;
if (Class == 'E')
cout <<"Total Fair: " <<ecofair ;
else
cout <<"Total Fair: " <<exefair ;
gotoxy(10,25) ;
cout <<"Press any Key to continue..." ;
getch() ;
}

//---------------------------------------------------------------------------
// THIS FUNCTION GIVE FLIGHT NO. TO DELETE ALL PASANGER RECORDS
//---------------------------------------------------------------------------

void RESERVE :: DELETE_ALL(void)
{
clrscr() ;
ENQUIRY() ;
char t1[5] ;
int t2, valid, sno ;
do
{
valid = 1 ;
gotoxy(3,23) ;
cout <<" " ;
gotoxy(3,20) ;
cout <<" " ;
gotoxy(3,20) ;
cout <<"Enter Sno. of the FLIGHT for which all passanger records to be deleted : " ;
gets(t1) ;
t2 = atoi(t1) ;
sno = t2 ;
if (strlen(t1) == 0)
return ;
if (sno < 1 || sno > 12)
{
valid = 0 ;
gotoxy(3,23) ;
cout <<" " ;
gotoxy(3,23) ;
cout <<"\7ENTER CORRECTLY" ;
getch() ;
}
} while (!valid) ;
gotoxy(3,23) ;
if (!DELETE_FLIGHT(sno))
cout <<"\7Records not found. Press any key to continue..." ;
else
cout <<"\7Records deleted. Press any key to continue..." ;
getch() ;
}









//---------------------------------------------------------------------------
// THIS IS MAIN FUNCTION WHICH DISPLAY MENU AND CALLS ALL THE MAIN FUNCTION
//---------------------------------------------------------------------------

void main(void)
{
DRAW d ;
PASSANGER p ;
TICKET ticket ;
RESERVE r ;
ticket.ADDITION() ;
char ch ;
while (1)
{
clrscr() ;
d.BOX(19,6,62,20,218) ;
textcolor(BLACK) ;
textbackground(WHITE) ;
for (int i=7; i<=19; i++)
for (int j=20; j<=61; j++)
{
gotoxy(j,i) ;
cprintf(" ") ;
}
gotoxy(29,9) ;
cprintf("AIR TICKET RESERVATION") ;
gotoxy(29,10) ;
cprintf("~~~~~~~~~~~~~~~~~~~~~~") ;
gotoxy(30,11) ;
cprintf("1 : RESERVATION") ;
gotoxy(30,12) ;
cprintf("2 : CANCELLATION") ;
gotoxy(30,13) ;
cprintf("3 : PASSANGER RECORDS ->") ;
gotoxy(30,14) ;
cprintf("4 : ENQUIRY") ;
gotoxy(30,15) ;
cprintf("5 : LIST OF PASSANGERS") ;
gotoxy(30,16) ;
cprintf("6 : QUIT") ;
gotoxy(30,18) ;
cprintf("ENTER YOUR CHOICE ") ;
ch = getche() ;
textcolor(LIGHTGRAY) ;
textbackground(BLACK) ;
clrscr() ;
if (ch == 27 || ch == '6')
break ;
else
if (ch == '1')
r.RESERVATION() ;
if (ch == '2')
r.CANCELLATION() ;
if (ch == '4')
{
ticket.ENQUIRY() ;
gotoxy(2,23) ;
cout <<"Press any key to continue..." ;
getch() ;
}
else
if (ch == '5')
p.LIST() ;
else
if (ch == '3')
{
while(1)
{
clrscr() ;
d.BOX(19,6,62,20,218) ;
textcolor(BLACK) ;
textbackground(WHITE) ;
for (int i=7; i<=19; i++)
for (int j=20; j<=61; j++)
{
gotoxy(j,i) ;
cprintf(" ") ;
}
gotoxy(29,10) ;
cprintf("EDIT PASSANGER RECORD") ;
gotoxy(29,11) ;
cprintf("~~~~~~~~~~~~~~~~~~~~~") ;
gotoxy(33,12) ;
cprintf("1 : PASSANGER INFORMATION") ;
gotoxy(99933,13) ;
cprintf("2 : DELETE") ;
gotoxy(33,14) ;
cprintf("0 : EXIT") ;
gotoxy(31,16) ;
cprintf("ENTER YOUR CHOICE") ;
ch = getche() ;
textcolor(LIGHTGRAY) ;
textbackground(BLACK) ;
clrscr() ;
if (ch == 27 || ch == '0')
break ;
else
if (ch == '1')
r.DISPLAY_TICKET();
else
if (ch == '2')
r.DELETE_ALL() ;
}
}
}
}

Teachers Day

#include<graphics.h>
#include<conio.h>
#include<iostream.h>
#include<stdio.h>
#include<dos.h>
#include<stdlib.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\TC\\BGI");
settextstyle(0,0,7);
rectangle(40,10,600,90);
rectangle(40,120,600,200);
rectangle(40,230,600,310);
setfillstyle(7,4);
floodfill(55,15,15);
floodfill(55,125,15);
floodfill(55,235,15);
outtextxy(175,24,"happy");
outtextxy(100,130,"teachers");
outtextxy(220,240,"day");
setlinestyle(0,1,3);
setcolor(15);
settextstyle(4,0,7);
setcolor(4);
rectangle(0,0,639,478);
rectangle(5,5,634,473);
delay(1000);
while(!kbhit())
{
delay(40);
putpixel(random(640),random(640),random(15));
 }
getch();
}

Student database

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<dos.h>
#include<stdlib.h>
#include<ctype.h>
FILE *fp;
struct student
{
char snum[13];
char fname[20];
char sname[20];
char mi;
char ccode;
}record;
void Temp1(void);
void twolinebox(int x1,int y1,int x2,int y2)
{
int x,y;
gotoxy(x1,y1); printf("É");
gotoxy(x2,y1); printf("»");
for(y=y1+1;y<y2;y++)
{
gotoxy(x1,y); printf("º");
gotoxy(x2,y); printf("º");
}
gotoxy(x1,y2); printf("È");
gotoxy(x2,y2); printf("¼");
for(x=x1+1;x<x2;x++)
{
gotoxy(x,y1); printf("Í");
gotoxy(x,y2); printf("Í");
}
//gotoxy(x1+1,y1+1);
}
void printxy(int x,int y,char string[])
{
gotoxy(x,y); printf("%s",string);
}
void center(int y,char string[])
{
int x=(80-strlen(string)+1)/2;
gotoxy(x,y);printf("%s",string);
}
void Create(void)
{
char opt;
center(21,"WARNING!!!");
center(22,"You are about to create a new file");
center(23,"This will erase all records in the file...");
center(24,"Are you sure you want to proceed?[Y/N] ");
opt=getche(); opt=toupper(opt);
if(opt=='Y')
{
fp=fopen("Group4.txt","w");
center(24,"                                             ");
center(24,"File successfully created!");
}
getch();
fclose(fp);
}
void Add(void)
{
char opt;
fp=fopen("Group4.txt","a");
clrscr();
Temp1();
gotoxy(19,8);   gets(record.snum);
gotoxy(19,10);  gets(record.fname);
gotoxy(19,12);  gets(record.sname);
gotoxy(19,14); record.mi=getche();    record.mi=toupper(record.mi);
gotoxy(19,16); record.ccode=getche();record.ccode=toupper(record.ccode);
gotoxy(5,22); clreol(); printxy(79,22,"º");
fprintf(fp,"%s %s %s %c %c",record.snum,record.fname,record.sname,record.mi,record.ccode);
gotoxy(5,21); clreol(); center(21,"Record successfully added!");printxy(79,21,"º");
gotoxy(53,22);
delay(1000);
center(22,"Press any key to go to main menu...");
getch();
fclose(fp);
}
void Temp1(void)
{
// lines(box) for B choice
twolinebox(2,6,79,20);
twolinebox(2,20,79,24);
twolinebox(2,2,79,24);
center(4,"ADD RECORD");
printxy(6,8,"Student no: ");
printxy(6,10,"First Name: ");
printxy(6,12,"Last Name: ");
printxy(6,14,"Middle init:");
printxy(6,16,"Course code: ");
center(22,"Course code: [A]-B.C.A, [B]-B.B.A, [anykey]-B.TECH");
gotoxy(19,7);
}
void List(void)
{
int count=0,i,x=0,page=1,BCA=0,BBA=0,BTECH=0;
fp=fopen("Group4.txt","r");
clrscr();
center(2,"DR.VIRENDRA SWARUP GROUP OF INSTITUTIONS");
center(3,"AJAD MARG,UNNAO");
center(5,"COMPUTER SCIENCE DEPARTMENT");
printxy(10,7,"Record     Student #             Name               Course");
for(i=1;i<80;i++)
{
gotoxy(i,8); puts("Í");
}
while(fscanf(fp,"%s %s %s %c %c",&record.snum,&record.fname,&record.sname,&record.mi,&record.ccode)!=EOF)   //it will work without & sign
{
if(count!=0&&count%5==0)
{
printxy(5,23, "Press any key to continue..."); getch(); x=0;
for(i=10;i<=24;i++)
{
gotoxy(1,i); clreol();
}
page++;
}
gotoxy(70,4); printf("Page %d",page);
gotoxy(13,10+x); printf("%d",count+1);
gotoxy(19,10+x); printf("%s",record.snum);
gotoxy(37,10+x); printf("%s %c %s",record.fname,record.mi,record.sname);
gotoxy(62,10+x);
switch(record.ccode)
{
case 'A': printf("BCA"); BCA++; break;
case 'B': printf("BBA"); BBA++; break;
default : printf("B.TECH"); BTECH++; break;
}
x++;
count++;
}
printxy(25,17,"TOTAL");
gotoxy(15,18); printf("BCA   : %d",BCA);
gotoxy(15,19); printf("BBA   : %d",BBA);
gotoxy(15,20); printf("B.TECH: %d",BTECH);
printxy(5,23,"Press any key to go to main menu...");
getch();
fclose(fp);
}
void Quit(void)
{
clrscr();
twolinebox(2,2,79,24);
center(8,"PROGRAMMED");
center(9,"BY");
center(11," PRITAM BANIK");
center(13,"Microsoft Certified Professional");
delay(1000);
exit(1);
fclose(fp);
}
void Err_mess(void)
{
sound(1000);
center(22,"Invalid Input!");
delay(1000);
nosound();
}
void main()
{
char choice;
do
{
clrscr();
twolinebox(29,6,51,8);
twolinebox(20,5,60,18);
twolinebox(2,20,79,25);
twolinebox(2,2,79,25);
center(7,"MAIN MENU");
printxy(30,9,"Press:");
printxy(30,11,"[A]-Create File");
printxy(30,12,"[B]-Add Record");
printxy(30,13,"[C]-List Record");
printxy(30,14,"[D]-Quit Program");
printxy(30,16,"Enter your choice..."); gotoxy(50,16);
choice=getch(); choice=toupper(choice);
switch(choice)
{
case 'A': Create(); break;
case 'B': Add(); break;
case 'C': List(); break;
case 'D': Quit(); break;
default: Err_mess(); break;
}
}
while(choice!='D');
}

Head Tail

#include<conio.h>
#include<stdio.h>
#include<dos.h>
#include<stdlib.h>
#include<graphics.h>
int main(void)
{
int gd=DETECT,gm,errorcode;
int midx,midy;
//int stangle=0,endangle=360;
int xradius,yradius=60;
initgraph(&gd,&gm,"C:\\TC\\BGI");
errorcode=graphresult();
if(errorcode!=grOk)
{
printf("graphics error:%s \n",grapherrormsg(errorcode));
printf("press any key to halt:");
getch();
}
midx=getmaxx()/2;
midy=getmaxy()/2;
setcolor(getmaxcolor());
int k=1;
int b=0;
settextstyle(2,0,0);
while(!kbhit())
{                    //////////////1
for(int a=60;a>=0;a=a-1)
{                    //////////////2
cleardevice();
xradius=a;
if(a==0)
{                   /////////////3
k=k+1;
for(b=a;b<=60;b++)
{                   ////////////4
cleardevice();
xradius=b;
if(k%2==0)
{
outtextxy(midx-10,midy-90,"TAIL");
setfillstyle(4,1);
}
else
{
outtextxy(midx-10,midy-90,"HEAD");
setfillstyle(5,3);

}
if(b>0&&b<57)
{
int xradius1=b-3;
fillellipse(midx,midy,xradius1+1,yradius);
fillellipse(midx,midy,xradius1+2,yradius);
fillellipse(midx,midy,xradius1+3,yradius);
}
outtextxy(10,5,"PROGRAM: TO SHOW THE ROTATION OF A COIN ");
fillellipse(midx,midy,xradius,yradius);
delay(25);
}                 ////////////4
}                 ////////////3
if(a<57>0)
{
int xradius1=a+3;
fillellipse(midx,midy,xradius1-1,yradius);
fillellipse(midx,midy,xradius1-2,yradius);
fillellipse(midx,midy,xradius1-3,yradius);
}
if(k%2==0)
{
outtextxy(midx-10,midy-90,"TAIL");
setfillstyle(4,1);
}
else
{
outtextxy(midx-10,midy-90,"HEAD");
setfillstyle(5,3);
}
outtextxy(10,5,"PROGRAM: TO SHOW THE ROTATION OF A COIN");
fillellipse(midx,midy,xradius,yradius);
delay(25);
}           //////////////2
}           /////////////1
getch();
closegraph();
return 0;
}

Colors

#include<conio.h>
#include<stdio.h>
#include<iostream.h>
#include<graphics.h>
#include<stdlib.h>
#include<ctype.h>
void main()
{
clrscr();
int gd=DETECT,gm,errorcode;
initgraph(&gd,&gm,"C:\\TC\\BGI");
errorcode=graphresult();
if(errorcode!=grOk)
{
cout<<"graphics error occured:%s\n"<<grapherrormsg(errorcode)<<endl;
cout<<"press any key to stop:";
getch();
exit(1);
}
for(int x=0;x<=15;x++)
{
setbkcolor(x);
getch();
}
closegraph();
}

Moving car

#include<dos.h>
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#define PI 3.14159
void draw_wheel(int x,int y,int theta)
{
int incr=45;
setcolor(getmaxcolor());
setfillstyle(EMPTY_FILL,getmaxcolor());
for(double i=theta;i<theta+360.0;i+=2*incr)
{
sector(x,y,i,i+incr,20,20);
arc(x,y,i+incr,i+2*incr,20);
}
}
void draw_car(int ang)
{
int car_color=YELLOW;
draw_wheel(50,200,ang);
draw_wheel(200,200,ang);
setcolor(car_color);
line(0,80,639,80);
line(0,300,639,300);
line(25,200,0,200);
line(0,200,0,160);
line(0,160,40,160);
line(40,160,70,130);

line(70,130,170,130);
line(170,130,200,160);
line(200,160,260,160);
line(260,160,260,200);
line(260,200,225,200);
line(175,200,75,200);

arc(50,200,0,180,25);
arc(200,200,0,180,25);

setfillstyle(SOLID_FILL,car_color);
floodfill(150,170,car_color);
}
void main()
{
int gd,gm,i,j;
void *bitmap1,*bitmap2;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C:\\TC\\BGI");
draw_car(0);
bitmap1=malloc(imagesize(0,130,270,230));
getimage(0,130,270,230,bitmap1);
putimage(0,130,bitmap1,XOR_PUT);
draw_car(22);
bitmap2=malloc(imagesize(0,130,270,230));
getimage(0,130,270,230,bitmap2);
putimage(0,130,bitmap2,XOR_PUT);
for(i=0;!kbhit();i+=10)
{
if(i>500)i=0;
putimage(i,130,bitmap1,OR_PUT);
delay(100);
putimage(i,130,bitmap1,XOR_PUT);
putimage(i+5,130,bitmap2,OR_PUT);
delay(50);
putimage(i+5,130,bitmap2,XOR_PUT);
}
closegraph();
}