Home » Ask & Discuss » Fun Zone » Games, Puzzles and Quizzes « Back to Discussion



Games, Puzzles and Quizzes

Selva Ganesh's Avatar
Hot goIITian

Joined: 21 Feb 2007
Post: 165
17 Feb 2008 20:12:40 IST
0 People liked this
102
7290 View Post
C++......
None

Hi friends i thought of creating a post for C and C++ program.....

if you need any program just post a request here and other GOIITans may help ( including ME )....

if you have any program just post em here and get rated by ME ( FOR SURE ) and other members....

to copy a c++ program there is a simple way tat many of us do not know
(i.e) Just go to the place where you have saved it and just right click and 'open with..' any text editter like notepad......

TO compile it also there is a simple way...
Just copy the program from the post and paste it in NOTEPAD and save as
' .cpp ' or '.c' file and then open it using the c++ editter....

I am saying the above 2 methods cauz many of us write the entire program and tat takes a long time.....

PLEASE GIVE YOUR BEST - THANKS....


Share this article on:

Comments (102)

Selva Ganesh's Avatar

Hot goIITian

Joined: 21 Feb 2007
Posts: 165
17 Feb 2008 20:14:10 IST
4 people liked this

Here i am gonna start the post with a c program....

Program : to find the factorial.....

Code :

#include<stdio.h>
#include<conio.h>
factorial(int);
void main()
{
    int a,i;
    long int ans;
    clrscr();
    //ans = 1;
    printf("Enter a number : ");
    scanf("%d",&a);
    ans = factorial (a);
    printf("\nThe Factorial of %d = %ld",a,ans);
    getch();
}
  factorial(int x)
{
  int i,a;
  a = 1;
  for (i = 1;i <= x;i++)
    a = a * i;
  //printf("The ans is = %d",a);
  return(a);
}
Antony Ajay's Avatar

Blazing goIITian

Joined: 4 Dec 2007
Posts: 356
17 Feb 2008 20:17:09 IST
4 people liked this

Hey guys,I am posting the project we did as a team of 2 in our school.I struggled very hard to produce this one for nearly a month.Hope it's useful.
This is a periodic table containing the details of only 20 elements......



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

void element(int,int);

void welcome_screen()
{
clrscr();
for(int x=50;x>=20;x--)
{
delay(160);
gotoxy(x,12);
cputs("  P R O J E C T   ");
gotoxy(x,14);
cputs("  D E V E L O P E D  B Y  :  ");
gotoxy(x,16);
cputs("                  Programmer 1 ");
gotoxy(x, 18);
cputs("                  Programmer 2 ");
}
gotoxy(x,24);
cputs("Press Any Key To Continue....");
getch();
}

int i,j,g;

void frame()
    {
    gotoxy(19,9);
    cout<<"É";
    for(i=20;i<=60;i++)
     {
     gotoxy(i,9);
     cout<<"Í";
     }
    cout<<"»";
    gotoxy(19,16);
    cout<<"È";
    for(i=20;i<=60;i++)
     {
     gotoxy(i,16);
     cout<<"Í";
     }
    cout<<"¼";
    for(i=10;i<=15;i++)
     {
     gotoxy(19,i);
     cout<<"º";
     }
    for(i=10;i<=15;i++)
     {
     gotoxy(61,i);
     cout<<"º";
     }
    gotoxy(5,24);
    cout<<"Press Esc to Exit";
    }

void display()
{
 gotoxy(33,2);
 cout<<"PERIODIC TABLE";
 gotoxy(1,1);
 cout<<"É";
 for(i=2;i<=79;i++)
  {
  gotoxy(i,1);
  cout<<"Í";
  }
 cout<<"»";
 for(i=2;i<=23;i++)
  {
  gotoxy(80,i);
  cout<<"º";
  }
 gotoxy(80,24);
 cout<<"¼";
 for(i=2;i<=11;i++)
  {
  gotoxy(i,24);
  cout<<"Í";
  }
 gotoxy(1,24);
 cout<<"È";
 for(i=2;i<=23;i++)
  {
  gotoxy(1,i);
  cout<<"º";
  }
 gotoxy(12,4);
 cout<<"Ú"<<"Ä"<<"Ä"<<"¿";
 gotoxy(63,4);
 cout<<"Ú"<<"Ä"<<"Ä"<<"¿";
 gotoxy(12,5);cout<<"³";
 gotoxy(15,5);cout<<"³";
 gotoxy(63,5);cout<<"³";
 gotoxy(66,5);cout<<"³";
 gotoxy(12,6);cout<<"Ã"<<"Ä"<<"Ä"<<"´";
 gotoxy(48,6);cout<<"Ú";
 for(i=51;i<=60;i++)
  if(i%3==0)
   {
   gotoxy(i,6);
   cout<<char(194);
   }
 for(i=48;i<=66;i++)
  if(i%3!=0)
   {
   gotoxy(i,6);
   cout<<"Ä";
   }
 gotoxy(63,6);
 cout<<"Å";
 for(i=48;i<=66;i++)
  if(i%3==0)
   {
   gotoxy(i,7);
   cout<<"³";
   }
 gotoxy(12,7);cout<<"³";
 gotoxy(12,8);cout<<"Ã"<<"Ä"<<"Ä"<<"´";
 gotoxy(12,9);cout<<"³";
 gotoxy(15,9);cout<<"³";
 gotoxy(15,6);cout<<"Å"<<"Ä"<<"Ä"<<"¿";
 gotoxy(15,8);cout<<"Å"<<"Ä"<<"Ä"<<"´";
 gotoxy(18,7);cout<<"³";
 gotoxy(18,9);cout<<"³";
 gotoxy(48,8);cout<<"Ã";
 for(i=51;i<=63;i++)
  if(i%3==0)
   {
   gotoxy(i,8);
   cout<<"Å";
   }
 for(i=48;i<=66;i++)
  if(i%3!=0)
   {
   gotoxy(i,8);
   cout<<"Ä";
   }
 for(i=48;i<=66;i++)
  if(i%3==0)
   {
   gotoxy(i,9);
   cout<<"³";
   }
 gotoxy(12,10);
 cout<<"Ã";gotoxy(15,10);
 cout<<"Å";
 for(i=13;i<=66;i++)
  if(i%3!=0)
     {     gotoxy(i,10);
    cout<<"Ä";
      }for(i=18;i<=45;i++)
  if(i%3==0)
     {     gotoxy(i,10);
    cout<<char(194);
      }for(i=46;i<=63;i++)
  if(i%3==0)
     {     gotoxy(i,10);
    cout<<"Å";
      }gotoxy(18,10);
cout<<"Å";
for(i=12;i<=66;i++)
 if(i%3==0)
  for(j=10;j<=16;j++)
   if(j%2!=0)
    {  gotoxy(i,j);
      cout<<"³";
     }for(i=15;i<=63;i++)
 if(i%3==0)
  for(j=12;j<=14;j++)
   if(j%2==0)
    { gotoxy(i,j);
      cout<<"Å";
     }for(i=15;i<=63;i++)
 if(i%3==0)
  for(j=12;j<=14;j++)
   if(j%2==0)
    { gotoxy(i,j);
      cout<<"Å";
     }for(i=12;i<=66;i++)
 if(i%3==0)
  for(j=12;j<=66;j++)
   if(j%2==0)
    { gotoxy(i,j);
      cout<<"Ä";
     }for(i=15;i<=42;i++)
 if(i%3==0)
  {gotoxy(i,16);
    cout<<"Å";
   }for(i=45;i<=63;i++)
 if(i%3==0)
  { gotoxy(i,16);
    cout<<"Á";
   }for(i=12;i<=42;i++)
 if(i%3==0)
  {  gotoxy(i,17);
    cout<<"³";
   } gotoxy(12,18);
cout<<"À";
for(i=12;i<=42;i++)
 if(i%3!=0)
  {  gotoxy(i,18);
   cout<<"Ä";
  }  cout<<"Ù";
for(i=15;i<=40;i++)
 if(i%3==0)
  {  gotoxy(i,18);
   cout<<"Á";
   } for(i=6;i<=16;i++)
 if(i%2==0)
  {   gotoxy(12,i);
   cout<<"Ã";
  } for(i=6;i<=14;i++)
 if(i%2==0)
  { gotoxy(66,i);
   cout<<"´";
   }gotoxy(66,16);
cout<<"Ù";
gotoxy(12,20);
cout<<"Ú";
for(i=13;i<=23;i++)
 {gotoxy(i,20);
   cout<<"Ä";
 }for(i=24;i<=63;i++)
 if(i%3==0)
  {gotoxy(i,20);
   cout<<char(194);
  }for(i=24;i<=66;i++)
 if(i%3!=0)
  { gotoxy(i,20);
   cout<<"Ä";
   cout<<"¿";
    gotoxy(12,21);
cout<<"³";
 }
 for(i=24;i<=66;i++)
{ if(i%3==0)
  { gotoxy(i,21);
  // cout<<char(194);
  cout<<"³";
   }
}
  for(i=24;i<=66;i++)
{ if(i%3==0)
  { gotoxy(i,20);
   cout<<"Ä";
  }cout<<"¿";
  gotoxy(i,21);
cout<<"³";
}
for(i=24;i<=66;i++)
{ if(i%3==0)
  {gotoxy(i,21);
   cout<<"³";
  }gotoxy(i,22);
cout<<"Ã";
}
for(i=13;i<=23;i++)
  { gotoxy(i,22);
   cout<<"Ä";
  }
  for(i=24;i<=63;i++)
{ if(i%3==0)
  { gotoxy(i,22);
   cout<<"Å";
  }
  }
  for(i=24;i<=66;i++)
{ if(i%3!=0)
  {  gotoxy(i,22);
   cout<<"Ä";
  }  cout<<"´";
      gotoxy(12,23);
cout<<"³";}
for(i=24;i<=66;i++)
  if(i%3==0)
   {  gotoxy(i,23);
     cout<<"³";
  }   gotoxy(12,24);
cout<<"À";
for(i=13;i<=23;i++)
  {    gotoxy(i,24);
    cout<<"À";
  }    for(i=24;i<=63;i++)
 if(i%3==0)
   {  gotoxy(i,24);
     cout<<"Á";
   } for(i=24;i<=66;i++)
  if(i%3!=0)
    { gotoxy(i,24);
      cout<<"Ä";
    }cout<<"Ù";
gotoxy(15,25);
cout<<"ARROWS TO SCROLL.ENTER TO SELECT.ESC TO EXIT.";
gotoxy(13,5);
cout<<"H";
gotoxy(13,7);
cout<<"Li";
gotoxy(13,9);
cout<<"Na";
gotoxy(13,11);
cout<<"K";

gotoxy(15,7); cout<<"³";
for (i=13;i<66;i++)
 {
 gotoxy(i,14);cout<<"Ä";
 gotoxy(i,12);cout<<"Ä";
 gotoxy(i,16);cout<<"Ä";
 if(i>42) {gotoxy(i,18);cout<<"  ";}
 if(i%3==0)
  {
  gotoxy(i,14);cout<<"Å";
  gotoxy(i,12);cout<<"Å";
  gotoxy(i,16);cout<<"Å";
  if(i>42) gotoxy(i,16);cout<<"Á";
  }
 }

for (i=23;i<66;i++)
 {
 gotoxy(i,20);cout<<"Ä";
 gotoxy(i,22);cout<<"Ä";
 gotoxy(i-11,24);cout<<"Ä";
 gotoxy(i,24);cout<<"Ä";
 if(i%3==0)
  {
  gotoxy(i,20);cout<<"Â";
  gotoxy(i,22);cout<<"Å";
  gotoxy(i,24);cout<<"Á";
  }
 }
 for (i=23;i<66;i++)
 {
 if(i%3==0)
  if(i>10)
   {
   gotoxy(i,24);
   cout<<"Á";
   }
 }

for(i=67;i<=80;i++) {gotoxy(i,24);cout<<"Í";}
for(i=0;i<=10;i++) {gotoxy(i,25);cout<<" ";}
for(i=19;i<=47;i++) {gotoxy(i,9);cout<<" ";}
for(i=2;i<=5;i++) {gotoxy(61,i);cout<<" ";}

gotoxy(12,22);cout<<"Ã";
gotoxy(66,20);cout<<"¿ ";
gotoxy(12,24);cout<<"ÀÄ";
gotoxy(80,24);cout<<"¼";
gotoxy(59,9);cout<<" ";
gotoxy(56,9);cout<<" ";


gotoxy(13,13);
cout<<"Rb";
gotoxy(13,15);
cout<<"Cs";
gotoxy(13,17);
cout<<"Fr";
gotoxy(16,7);
cout<<"Be";
gotoxy(16,9);
cout<<"Mg";
gotoxy(16,11);
cout<<"Ca";
gotoxy(16,13);
cout<<"Sr";
gotoxy(16,15);
cout<<"Ba";
gotoxy(16,17);
cout<<"Ra";
gotoxy(19,11);
cout<<"Sc";
gotoxy(19,13);
cout<<"Y";
gotoxy(19,15);
cout<<"La";
gotoxy(19,17);
cout<<"Ac";
gotoxy(22,11);
cout<<"Ti";
gotoxy(22,13);
cout<<"Zr";
gotoxy(22,15);
cout<<"Hf";
gotoxy(22,17);
cout<<"Rf";
gotoxy(25,11);
cout<<"V";
gotoxy(25,13);
cout<<"Nb";
gotoxy(25,15);
cout<<"Ta";
gotoxy(25,17);
cout<<"Ha";
gotoxy(28,11);
cout<<"Cr";
gotoxy(28,13);
cout<<"Mo";
gotoxy(28,15);
cout<<"W";
gotoxy(28,17);
cout<<"Un";
gotoxy(31,11);
cout<<"Mn";
gotoxy(31,13);
cout<<"Tc";
gotoxy(31,15);
cout<<"Re";
gotoxy(31,17);
cout<<"Ns";
gotoxy(34,11);
cout<<"Fe";
gotoxy(34,13);
cout<<"Ru";
gotoxy(34,15);
cout<<"Os";
gotoxy(34,17);
cout<<"Hs";
gotoxy(37,11);
cout<<"Co";
gotoxy(37,13);
cout<<"Rh";
gotoxy(37,15);
cout<<"Ir";
gotoxy(37,17);
cout<<"Mt";
gotoxy(40,11);
cout<<"Ni";
gotoxy(40,13);
cout<<"Pd";
gotoxy(40,15);
cout<<"Pt";
gotoxy(40,17);
cout<<"Uu";
gotoxy(43,11);
cout<<"Cu";
gotoxy(43,13);
cout<<"Ag";
gotoxy(43,15);
cout<<"Au";
gotoxy(46,11);
cout<<"Zn";
gotoxy(46,13);
cout<<"Cd";
gotoxy(46,15);
cout<<"Hg";
gotoxy(49,7);
cout<<"B";
gotoxy(49,9);
cout<<"Al";
gotoxy(49,11);
cout<<"Ga";
gotoxy(49,13);
cout<<"In";
gotoxy(49,15);
cout<<"Tl";
gotoxy(52,7);
cout<<"C";
gotoxy(52,9);
cout<<"Si";
gotoxy(52,11);
cout<<"Ge";
gotoxy(52,13);
cout<<"Sn";
gotoxy(52,15);
cout<<"Pb";
gotoxy(55,7);
cout<<"N";
gotoxy(55,9);
cout<<"P";
gotoxy(55,11);
cout<<"As";
gotoxy(55,13);
cout<<"Sb";
gotoxy(55,15);
cout<<"Bi";
gotoxy(58,7);
cout<<"O";
gotoxy(58,9);
cout<<"S";
gotoxy(58,11);
cout<<"Se";
gotoxy(58,13);
cout<<"Te";
gotoxy(58,15);
cout<<"Po";
gotoxy(61,7);
cout<<"F";
gotoxy(61,9);
cout<<"Cl";
gotoxy(61,11);
cout<<"Br";
gotoxy(61,13);
cout<<"I";
gotoxy(61,15);
cout<<"At";
gotoxy(64,5);
cout<<"He";
gotoxy(64,7);
cout<<"Ne";
gotoxy(64,9);
cout<<"Ar";
gotoxy(64,11);
cout<<"Kr";
gotoxy(64,13);
cout<<"Xe";
gotoxy(64,15);
cout<<"Rn";
gotoxy(13,21);
cout<<"Lanthanides";
gotoxy(25,21);
cout<<"Ce";
gotoxy(28,21);
cout<<"Pr";
gotoxy(31,21);
cout<<"Nd";
gotoxy(34,21);
cout<<"Pm";
gotoxy(37,21);
cout<<"Sm";
gotoxy(40,21);
cout<<"Eu";
gotoxy(43,21);
cout<<"Gd";
gotoxy(46,21);
cout<<"Tb";
gotoxy(49,21);
cout<<"Dy";
gotoxy(52,21);
cout<<"Ho";
gotoxy(55,21);
cout<<"Er";
gotoxy(58,21);
cout<<"Tm";
gotoxy(61,21);
cout<<"Yb";
gotoxy(64,21);
cout<<"Lu";
gotoxy(13,23);
cout<<"Actinides";
gotoxy(25,23);
cout<<"Th";
gotoxy(28,23);
cout<<"Pa";
gotoxy(31,23);
cout<<"U";
gotoxy(34,23);
cout<<"Np";
gotoxy(37,23);
cout<<"Pu";
gotoxy(40,23);
cout<<"Am";
gotoxy(43,23);
cout<<"Cm";
gotoxy(46,23);
cout<<"Bk";
gotoxy(49,23);
cout<<"Cf";
gotoxy(52,23);
cout<<"Ea";
gotoxy(55,23);
cout<<"Fm";
gotoxy(58,23);
cout<<"Md";
gotoxy(61,23);
cout<<"No";
gotoxy(64,23);
cout<<"Lr";
gotoxy(2,2);
i=2;j=2;
gotoxy(i,j);

 do
  {
  g=getch();
  if(g==80)
   {
   if(j==23) j=1;
   gotoxy(i,++j);
   }
  else if(g==77)
   {
   if(i==79) i=1;
   gotoxy(++i,j);
   }
  else if(g==75)
   {
   if(i==2) i=80;
   gotoxy(--i,j);
   }
  else if(g==72)
   {
   if(j==2)
   j=24;
   gotoxy(i,--j);
   }
  if(g==13)
   element(i,j);
  }while(g!=27);
}

void main()
 {
 clrscr();
 welcome_screen();
 int gdriver=DETECT,gmode,errorcode;
 initgraph(&gdriver,&gmode,"h: cin");
 errorcode=graphresult();
 if(errorcode!=grOk)
  {
  cout<<grapherrormsg(errorcode)<<endl;
  getch();
  }
 for (int i=0;i<7;i++)
  {
  delay(150);
  clrscr();
  settextstyle(5,0,i);
  outtextxy(110,75,"    WELCOME");
  outtextxy(155,150,"     TO");
  outtextxy(100,225," PERIODIC TABLE");
  }
 settextstyle(8,0,1);
 outtextxy(200,450,"Press Any Key To Continue ...");
 getch();
 closegraph();
 display();
 }

void element(int i,int j)
 {
 if(((i==13)||(i==14))&&(j==5))
     {
     clrscr();
      frame();
      gotoxy(21,10);
      cout<<"Atomic No                :1"<<" ";
      gotoxy(21,11);
      cout<<"Symbol                   :H"<<" ";
      gotoxy(21,12);
      cout<<"Name                     :Hydrogen"<<" ";
      gotoxy(21,13);
      cout<<"Atomic Radius            :0.37"<<" ";
      gotoxy(21,15);
      cout<<"Electronegetivity        :2.20"<<" ";
      gotoxy(30,20);
      cout<<"Press Any Key To Return.....";
     }
    
 else if(((i==64)||(i==65))&&(j==5))
    {
     clrscr();
     frame();
     gotoxy(21,10);
     cout<<"Atomic No:               :2"<<" ";
     gotoxy(21,11);
     cout<<"Symbol                   :He"<<" ";
     gotoxy(21,12);
     cout<<"Name                     :Helium"<<" ";
     gotoxy(21,13);
     cout<<"Atomic Radius            :1.2"<<" ";
     gotoxy(21,14);
     cout<<"1st Ionisation potential :24.58"<<" ";
     gotoxy(21,15);
     cout<<"Electronegativity        :------"<<" ";
     gotoxy(30,20);
     cout<<"Press Any Key To Return......";
    }

 else if(((i==13)||(i==14))&&(j==7))
       {
    clrscr();
    frame();
    gotoxy(21,10);
    cout<<"Atomic No:               :3"<<" ";
    gotoxy(21,11);
    cout<<"Symbol                   :Li"<<" ";
    gotoxy(21,12);
    cout<<"Name                     :Lithium"<<" ";
    gotoxy(21,13);
    cout<<"Atomic Radius            :1.23"<<" ";
    gotoxy(21,15);
    cout<<"Electronegativity        :0.97"<<" ";
    gotoxy(30,20);
    cout<<"Press Any Key To Return......";
    }
    
 else if(((i==16)||(i==17))&&(j==7))
       {
    clrscr();
    frame();
    gotoxy(21,10);
    cout<<"Atomic No:               :4"<<" ";
    gotoxy(21,11);
    cout<<"Symbol                   :Be"<<" ";
    gotoxy(21,12);
    cout<<"Name                     :Berryllium"<<" ";
    gotoxy(21,13);
    cout<<"Atomic Radius            :0.89"<<" ";
    gotoxy(21,15);
    cout<<"Electronegativity        :1.47"<<" ";
    gotoxy(30,20);
    cout<<"Press Any Key To Return......";
    }
    
 else if(((i==49)||(i==50))&&(j==7))
    {
     clrscr();
     frame();
     gotoxy(21,10);
     cout<<"Atomic No:               :5"<<" ";
     gotoxy(21,11);
     cout<<"Symbol                   :B"<<" ";
     gotoxy(21,12);
     cout<<"Name                     :Boron"<<" ";
     gotoxy(21,13);
     cout<<"Atomic Radius            :0.80"<<" ";
     gotoxy(21,14);
     cout<<"1st Ionisation potential :8.3"<<" ";
     gotoxy(21,15);
     cout<<"Electronegativity        :2.01"<<" ";
     gotoxy(30,20);
     cout<<"Press Any Key To Return......";
    }

 else if(((i==52)||(i==53))&&(j==7))
    {
     clrscr();
     frame();
     gotoxy(21,10);
     cout<<"Atomic No:               :6"<<" ";
     gotoxy(21,11);
     cout<<"Symbol                   :C"<<" ";
     gotoxy(21,12);
     cout<<"Name                     :Carbon"<<" ";
     gotoxy(21,13);
     cout<<"Atomic Radius            :0.77"<<" ";
     gotoxy(21,14);
     cout<<"1st Ionisation potential :11.26"<<" ";
     gotoxy(21,15);
     cout<<"Electronegativity        :2.50"<<" ";
     gotoxy(30,20);
     cout<<"Press Any Key To Return......";
    }

 else if(((i==55)||(i==56))&&(j==7))
    {
     clrscr();
     frame();
     gotoxy(21,10);
     cout<<"Atomic No:               :7"<<" ";
     gotoxy(21,11);
     cout<<"Symbol                   :N"<<" ";
     gotoxy(21,12);
     cout<<"Name                     :Nitrogen"<<" ";
     gotoxy(21,13);
     cout<<"Atomic Radius            :0.74"<<" ";
     gotoxy(21,14);
     cout<<"1st Ionisation potential :14.54"<<" ";
     gotoxy(21,15);
     cout<<"Electronegativity        :3.07"<<" ";
     gotoxy(30,20);
     cout<<"Press Any Key To Return......";
    }
 
 else if(((i==58)||(i==59))&&(j==7))
    {
     clrscr();
     frame();
     gotoxy(21,10);
     cout<<"Atomic No:               :8"<<" ";
     gotoxy(21,11);
     cout<<"Symbol                   :O"<<" ";
     gotoxy(21,12);
     cout<<"Name                     :Oxygen"<<" ";
     gotoxy(21,13);
     cout<<"Atomic Radius            :0.74"<<" ";
     gotoxy(21,14);
     cout<<"1st Ionisation potential :13.61"<<" ";
     gotoxy(21,15);
     cout<<"Electronegativity        :3.50"<<" ";
     gotoxy(30,20);
     cout<<"Press Any Key To Return......";
    }

 else if(((i==61)||(i==62))&&(j==7))
    {
     clrscr();
     frame();
     gotoxy(21,10);
     cout<<"Atomic No:               :9"<<" ";
     gotoxy(21,11);
     cout<<"Symbol                   :F"<<" ";
     gotoxy(21,12);
     cout<<"Name                     :Fluorine"<<" ";
     gotoxy(21,13);
     cout<<"Atomic Radius            :0.72"<<" ";
     gotoxy(21,14);
     cout<<"1st Ionisation potential :17.42"<<" ";
     gotoxy(21,15);
     cout<<"Electronegativity        :4.10"<<" ";
     gotoxy(30,20);
     cout<<"Press Any Key To Return......";
    }

 else if(((i==64)||(i==65))&&(j==7))
    {
     clrscr();
     frame();
     gotoxy(21,10);
     cout<<"Atomic No:               :10"<<" ";
     gotoxy(21,11);
     cout<<"Symbol                   :Ne"<<" ";
     gotoxy(21,12);
     cout<<"Name                     :Neon"<<" ";
     gotoxy(21,13);
     cout<<"Atomic Radius            :1.60"<<" ";
     gotoxy(21,14);
     cout<<"1st Ionisation potential :21.56"<<" ";
     gotoxy(21,15);
     cout<<"Electronegativity        :-"<<" ";
     gotoxy(30,20);
     cout<<"Press Any Key To Return......";
    }

 else if(((i==13)||(i==14))&&(j==9))
       {
    clrscr();
    frame();
    gotoxy(21,10);
    cout<<"Atomic No:               :11"<<" ";
    gotoxy(21,11);
    cout<<"Symbol                   :Na"<<" ";
    gotoxy(21,12);
    cout<<"Name                     :Sodium"<<" ";
    gotoxy(21,13);
    cout<<"Atomic Radius            :1.57"<<" ";
    gotoxy(21,15);
    cout<<"Electronegativity        :1.01"<<" ";
    gotoxy(30,20);
    cout<<"Press Any Key To Return......";
    }

 else if(((i==16)||(i==17))&&(j==9))
       {
    clrscr();
    frame();
    gotoxy(21,10);
    cout<<"Atomic No:               :12"<<" ";
    gotoxy(21,11);
    cout<<"Symbol                   :Mg"<<" ";
    gotoxy(21,12);
    cout<<"Name                   :Magnesium"<<" ";
    gotoxy(21,13);
    cout<<"Atomic Radius            :1.36"<<" ";
    gotoxy(21,15);
    cout<<"Electonegativity         :1.23"<<" ";
    gotoxy(30,20);
    cout<<"Press Any Key To Return.....   ";
     }

 else if(((i==49)||(i==50))&&(j==9))
    {
     clrscr();
     frame();
     gotoxy(21,10);
     cout<<"Atomic No:               :13"<<" ";
     gotoxy(21,11);
     cout<<"Symbol                   :Al"<<" ";
     gotoxy(21,12);
     cout<<"Name                     :Aluminium"<<" ";
     gotoxy(21,13);
     cout<<"Atomic Radius            :1.25"<<" ";
     gotoxy(21,14);
     cout<<"1st Ionisation potential :6.0"<<" ";
     gotoxy(21,15);
     cout<<"Electronegativity        :1.47"<<" ";
     gotoxy(30,20);
     cout<<"Press Any Key To Return......";
    }

 else if(((i==52)||(i==53))&&(j==9))
    {
     clrscr();
     frame();
     gotoxy(21,10);
     cout<<"Atomic No:               :14"<<" ";
     gotoxy(21,11);
     cout<<"Symbol                   :Si"<<" ";
     gotoxy(21,12);
     cout<<"Name                     :Silicon"<<" ";
     gotoxy(21,13);
     cout<<"Atomic Radius            :1.17"<<" ";
     gotoxy(21,14);
     cout<<"1st Ionisation potential :8.15"<<" ";
     gotoxy(21,15);
     cout<<"Electronegativity        :1.74"<<" ";
     gotoxy(30,20);
     cout<<"Press Any Key To Return......";
    }

 else if(((i==55)||(i==56))&&(j==9))
    {
     clrscr();
     frame();
     gotoxy(21,10);
     cout<<"Atomic No:               :15"<<" ";
     gotoxy(21,11);
     cout<<"Symbol                   :P"<<" ";
     gotoxy(21,12);
     cout<<"Name                     :Phosphorus"<<" ";
     gotoxy(21,13);
     cout<<"Atomic Radius            :1.10"<<" ";
     gotoxy(21,14);
     cout<<"1st Ionisation potential :11.0"<<" ";
     gotoxy(21,15);
     cout<<"Electronegativity        :2.06"<<" ";
     gotoxy(30,20);
     cout<<"Press Any Key To Return......";
    }

 else if(((i==58)||(i==59))&&(j==9))
    {
     clrscr();
     frame();
     gotoxy(21,10);
     cout<<"Atomic No:               :16"<<" ";
     gotoxy(21,11);
     cout<<"Symbol                   :S"<<" ";
     gotoxy(21,12);
     cout<<"Name                     :Sulphur"<<" ";
     gotoxy(21,13);
     cout<<"Atomic Radius            :1.04"<<" ";
     gotoxy(21,14);
     cout<<"1st Ionisation potential :10.36"<<" ";
     gotoxy(21,15);
     cout<<"Electronegativity        :2.44"<<" ";
     gotoxy(30,20);
     cout<<"Press Any Key To Return......";
    }



 else  if(((i==61)||(i==62))&&(j==9))
    {
     clrscr();
     frame();
     gotoxy(21,10);
     cout<<"Atomic No:               :17"<<" ";
     gotoxy(21,11);
     cout<<"Symbol                   :Cl"<<" ";
     gotoxy(21,12);
     cout<<"Name                     :Chlorine"<<" ";
     gotoxy(21,13);
     cout<<"Atomic Radius            :0.99"<<" ";
     gotoxy(21,14);
     cout<<"1st Ionisation potential :13.0"<<" ";
     gotoxy(21,15);
     cout<<"Electronegativity        :2.83"<<" ";
     gotoxy(30,20);
     cout<<"Press Any Key To Return......";
    }
    


 else if(((i==64)||(i==65))&&(j==9))
    {
     clrscr();
     frame();
     gotoxy(21,10);
     cout<<"Atomic No:               :18"<<" ";
     gotoxy(21,11);
     cout<<"Symbol                   :Ar"<<" ";
     gotoxy(21,12);
     cout<<"Name                     :Argon"<<" ";
     gotoxy(21,13);
     cout<<"Atomic Radius            :1.90"<<" ";
     gotoxy(21,14);
     cout<<"1st Ionisation potential :15.76"<<" ";
     gotoxy(21,15);
     cout<<"Electronegativity        :-"<<" ";
     gotoxy(30,20);
     cout<<"Press Any Key To Return......";
    }

 else if(((i==13)||(i==14))&&(j==11))
       {
    clrscr();
    frame();
    gotoxy(21,10);
    cout<<"Atomic No:               :19"<<" ";
    gotoxy(21,11);
    cout<<"Symbol                   :K"<<" ";
    gotoxy(21,12);
    cout<<"Name                     :Potassium"<<" ";
    gotoxy(21,13);
    cout<<"Atomic Radius            :2.03"<<" ";
    gotoxy(21,15);
    cout<<"Electronegativity        :0.91"<<" ";
    gotoxy(30,20);
    cout<<"Press Any Key To Return......";
    }

 else if(((i==16)||(i==17))&&(j==11))
    {
     clrscr();
     frame();
     gotoxy(21,10);
     cout<<"Atomic No               :20"<<" ";
     gotoxy(21,11);
     cout<<"Symbol                  :ca"<<" ";
     gotoxy(21,12);
     cout<<"Name                   :Calcium"<<" ";
     gotoxy(21,13);
     cout<<"Atomic Radius           :1.74"<<" ";
     gotoxy(21,15);
     cout<<"Electonegativity            :1.04"<<" ";
     gotoxy(30,20);
     cout<<"Press Any Key To Return.....   ";
    }

 else if(((i==13)||(i==14))&&(j==13))
       {
    clrscr();
    frame();
    gotoxy(21,10);
    cout<<"Atomic No:               :37"<<" ";
    gotoxy(21,11);
    cout<<"Symbol                   :Rb"<<" ";
    gotoxy(21,12);
    cout<<"Name                     :Rubidium"<<" ";
    gotoxy(21,13);
    cout<<"Atomic Radius            :2.16"<<" ";
    gotoxy(21,15);
    cout<<"Electronegativity        :0.89"<<" ";
    gotoxy(30,20);
    cout<<"Press Any Key To Return......";
    }

 else if(((i==13)||(i==14))&&(j==15))
       {
    clrscr();
    frame();
    gotoxy(21,10);
    cout<<"Atomic No:               :55"<<" ";
    gotoxy(21,11);
    cout<<"Symbol                   :Cs"<<" ";
    gotoxy(21,12);
    cout<<"Name                     :Cesium"<<" ";
    gotoxy(21,13);
    cout<<"Atomic Radius            :2.35"<<" ";
    gotoxy(21,15);
    cout<<"Electronegativity        :0.86"<<" ";
    gotoxy(30,20);
    cout<<"Press Any Key To Return......";
    }

 else if(((i==13)||(i==14))&&(j==17))
       {
    clrscr();
    frame();
    gotoxy(21,10);
    cout<<"Atomic No:               :87"<<" ";
    gotoxy(21,11);
    cout<<"Symbol                   :Fr"<<" ";
    gotoxy(21,12);
    cout<<"Name                     :Francium"<<" ";
    gotoxy(21,13);
    cout<<"Atomic Radius            :-"<<" ";
    gotoxy(21,15);
    cout<<"Electronegativity        :0.86"<<" ";
    gotoxy(30,20);
    cout<<"Press Any Key To Return......";
    }

 else if(((i==64)||(i==65))&&(j==23))
      {
       clrscr();
       frame();
       gotoxy(21,10);
       cout<<"Atomic No.              :103"<<" ";
       gotoxy(21,11);
       cout<<"Symbol                  :Lr"<<" ";
       gotoxy(21,12);
       cout<<"Name                    :Lawencium"<<" ";
       gotoxy(21,13);
       cout<<"Atomic Radius           :---"<<" ";
       gotoxy(21,14);
       cout<<"1st Ionisation Potential:---"<<" ";
       gotoxy(21,15);
       cout<<"Electonegativity        :1.2"<<" ";
       gotoxy(30,20);
       cout<<"Press Any Key To Return.....";
      }
char key;
key=getch();
if(key==27) exit(0);
else display();
}
Aatish Pandit's Avatar

Blazing goIITian

Joined: 3 Feb 2007
Posts: 1200
17 Feb 2008 20:26:53 IST
4 people liked this

   
TIC TAC TOE GAME.......


    #include<iostream.h>
    #include<conio.h>
    #include<stdio.h>

    void main()
    {
    begin:
    clrscr();
    void showgame(char,char,char,char,char,char,char,char,char);
    int choicex,choicey,flag=0,counter=1,finalchoice;
    char a1,a2,a3,a4,a5,a6,a7,a8,a9,ch,pl1[20],pl2[20];
    a1=' ';
    a2=' ';
    a3=' ';
    a4=' ';
    a5=' ';
    a6=' ';
    a7=' ';
    a8=' ';
    a9=' ';
    cout<<" WELCOME TO TIC-TAC-TOE THE OBJECTIVE OF THE GAME IS TO MAKE YOUR SYMBOL (EITHER 'X' OR 'O' TO TYPE IN A ROW EITHER VERTICALLY OR HORIZONTALLY OR DIAGONALLY AND ALSO TO PREVENT YOUR  OPPONENT FROM DOING SO SO I WISH BOTH THE PLAYERS BEST OF LUCK!!!";
    cin.get(ch);
    clrscr();


    cout<<"PLAYER1 ENTER YOUR NAME  :";

    cin.getline(pl1,20);

    cout<<" PLAYER2 ENTER YOUR NAME  :";

    cin.getline(pl2,20);
    clrscr();
cout<<"    HELLO "<<pl1<<" & "<<pl2;
    cin.get(ch);
    clrscr();



    rematch:
    counter=1;
    clrscr();
    a1=' ';
    a2=' ';
    a3=' ';
    a4=' ';
    a5=' ';
    a6=' ';
    a7=' ';
    a8=' ';
    a9=' ';


    do
    {
    xagain:
    clrscr();
    showgame(a1,a2,a3,a4,a5,a6,a7,a8,a9);
   
    cout<<" "<<pl1<<"  PLEASE ENTER YOUR MOVE";
   
    cin>>choicex;
    switch (choicex)
    {
    case 11:
    clrscr();
    if(a1!='Y')
    {
    counter++;
    a1='X';
    showgame(a1,a2,a3,a4,a5,a6,a7,a8,a9);
    }
    else if(a1=='Y')
    {
    cout<<" SORRY "<<pl2<<"  HAS ALREADY MADE THE MOVE HERE PRESS ENTER TO RE-ENTER YOUR MOVE";
    cin.get(ch);

    goto xagain;
    }
    break;

    case 12:
    clrscr();
    if(a2!='Y')
    { counter++;
    a2='X';
    showgame(a1,a2,a3,a4,a5,a6,a7,a8,a9);
    }
    else if(a2=='Y')
    {
    cout<<" SORRY "<<pl2<<"  HAS ALREADY MADE THE MOVE HERE";
    cin.get(ch);
    goto xagain;
    }
    break;

    case 13:
    clrscr();
    if(a3!='Y')
    { counter++;
    a3='X';
    showgame(a1,a2,a3,a4,a5,a6,a7,a8,a9);
    }
    else if(a3=='Y')
    {
    cout<<" SORRY "<<pl2<<"  HAS ALREADY MADE THE MOVE HERE";
    cin.get(ch);
    goto xagain;
    }
    break;

    case 21:
    clrscr();
    if(a4!='Y')
    { counter++;
    a4='X';
    showgame(a1,a2,a3,a4,a5,a6,a7,a8,a9);
    }
    else if(a4=='Y')
    {
    cout<<" SORRY "<<pl2<<"  HAS ALREADY MADE THE MOVE HERE";
    cin.get(ch);
    goto xagain;
    }
    break;
    case 22:
    clrscr();
    if(a5!='Y')
    { counter++;
    a5='X';
    showgame(a1,a2,a3,a4,a5,a6,a7,a8,a9);
    }
    else if(a5=='Y')
    {
    cout<<" SORRY "<<pl2<<"  HAS ALREADY MADE THE MOVE HERE";
    cin.get(ch);
    goto xagain;
    }
    break;

    case 23:
    clrscr();
    if(a6!='Y')
    { counter++;
    a6='X';
    showgame(a1,a2,a3,a4,a5,a6,a7,a8,a9);
    }
    else if(a6=='Y')
    {
    cout<<" SORRY "<<pl2<<"  HAS ALREADY MADE THE MOVE HERE";
    cin.get(ch);
    goto xagain;
    }
    break;

    case 31:
    clrscr();
    if(a7!='Y')
    { counter++;
    a7='X';
    showgame(a1,a2,a3,a4,a5,a6,a7,a8,a9);
    }
    else if(a7=='Y')
    {
    cout<<" SORRY "<<pl2<<"  HAS ALREADY MADE THE MOVE HERE";
    cin.get(ch);
    goto xagain;
    }
    break;

     case 32:
    clrscr();
    if(a8!='Y')
    { counter++;
    a8='X';
    showgame(a1,a2,a3,a4,a5,a6,a7,a8,a9);
    }
    else if(a8=='Y')
    {
    cout<<" SORRY "<<pl2<<"  HAS ALREADY MADE THE MOVE HERE";
    cin.get(ch);
    goto xagain;
    }
    break;

    case 33:
    clrscr();
    if(a9!='Y')
    { counter++;
    a9='X';
    showgame(a1,a2,a3,a4,a5,a6,a7,a8,a9);
    }

    else if(a9=='Y')
    {
    cout<<" SORRY "<<pl2<<"  HAS ALREADY MADE THE MOVE HERE";
    cin.get(ch);
    goto xagain;
    }
    break;

    default:
    cout<<"SORRY ILLEGAL MOVE";
    goto xagain;
    }


    if(  (a1=='X'&&a2=='X'&&a3=='X')  || (a4=='X' && a5=='X' && a6=='X')  ||  ( a7=='X' && a8=='X' && a9=='X') || (a1=='X'&&a4=='X'&&a7=='X')  || (a2=='X'&& a5=='X' && a8=='X') || (a3=='X' && a6=='X' && a9=='X') || (a1=='X' && a5=='X' && a9=='X') ||  (a3=='X'&& a5=='X' && a7=='X')  )
    {
   
    cout<<pl1<<"  WINS!!!";
    cin.get(ch);

    flag++;
    cin.get(ch);
   
    cout<<" THANK YOU FOR PLAYING TIC-TAC-TOE";
    cout<<" PRESS 1 FOR RE-MATCH BETWEEN THE SAME PLAYERS";
    cout<<" PRESS 2 FOR NEW GAME";
    cout<<" PRESS 3 TO QUIT THE GAME";
    cin>>finalchoice;
    if(finalchoice==1)
    goto rematch;
    else if (finalchoice==2)
    goto begin;
    else if(finalchoice==3)
    goto finish;
    else

    break;
    }

    yagain:
    clrscr();
    showgame(a1,a2,a3,a4,a5,a6,a7,a8,a9);
    cout<<" "<<pl2<<"  PLEASE ENTER YOUR MOVE";
   
    cin>>choicey;
    switch(choicey)
    {
    case 11:
    clrscr();
    if (a1!='X')
    { counter++;
    a1='Y';
    showgame(a1,a2,a3,a4,a5,a6,a7,a8,a9);
    }
    else if(a1=='X')
    {
    cout<<" SORRY "<<pl1<<"  HAS ALREADY MADE THE MOVE HERE";
    cin.get(ch);
    goto yagain;
    }
    break;

    case 12:
    clrscr();
    if (a2!='X')
    { counter++;
    a2='Y';
    showgame(a1,a2,a3,a4,a5,a6,a7,a8,a9);
    }
    else if(a2=='X')
    {
    cout<<" SORRY "<<pl1<<"  HAS ALREADY MADE THE MOVE HERE";
    cin.get(ch);
    goto yagain;
    }
    break;

    case 13:
    clrscr();
    if (a3!='X')
    { counter++;
    a3='Y';
    showgame(a1,a2,a3,a4,a5,a6,a7,a8,a9);
    }
    else if(a3=='X')
    {
    cout<<" SORRY "<<pl1<<"  HAS ALREADY MADE THE MOVE HERE";
    cin.get(ch);
    goto yagain;
    }
    break;

    case 21:
    clrscr();
    if (a4!='X')
    { counter++;
    a4='Y';
    showgame(a1,a2,a3,a4,a5,a6,a7,a8,a9);
    }
    else if(a4=='X')
    {
    cout<<" SORRY "<<pl1<<"  HAS ALREADY MADE THE MOVE HERE";
    cin.get(ch);
    goto yagain;
    }
    break;
    case 22:
    clrscr();
    if (a5!='X')
    { counter++;
    a5='Y';
    showgame(a1,a2,a3,a4,a5,a6,a7,a8,a9);
    }
    else if(a5=='X')
    {
    cout<<" SORRY "<<pl1<<"  HAS ALREADY MADE THE MOVE HERE";
    cin.get(ch);
    goto yagain;
    }
    break;

    case 23:
    clrscr();
    if (a6!='X')
    { counter++;
    a6='Y';
    showgame(a1,a2,a3,a4,a5,a6,a7,a8,a9);
    }

    else if(a6=='X')
    {
    cout<<" SORRY "<<pl1<<"  HAS ALREADY MADE THE MOVE HERE";
    cin.get(ch);
    goto yagain;
    }
    break;

    case 31:
    clrscr();
    if (a7!='X')
    { counter++;
    a7='Y';
    showgame(a1,a2,a3,a4,a5,a6,a7,a8,a9);
    }
    else if(a7=='X')
    {
    cout<<" SORRY "<<pl1<<"  HAS ALREADY MADE THE MOVE HERE";
    cin.get(ch);
    goto yagain;
    }
    break;

     case 32:
    clrscr();
    if (a8!='X')
    { counter++;
    a8='Y';
    showgame(a1,a2,a3,a4,a5,a6,a7,a8,a9);
    }
    else if(a8=='X')
    {
    cout<<" SORRY "<<pl1<<"  HAS ALREADY MADE THE MOVE HERE";
    cin.get(ch);
    goto yagain;
    }
    break;

    case 33:
    clrscr();
    if (a9!='X')
    { counter++;
    a9='Y';
    showgame(a1,a2,a3,a4,a5,a6,a7,a8,a9);
    }
    else if(a9=='X')
    {
    cout<<" SORRY "<<pl1<<"  HAS ALREADY MADE THE MOVE HERE";
    cin.get(ch);
    goto yagain;
    }
    break;

    default:
    cout<<"SORRY ILLEGAL MOVE";
    goto yagain;
    }

    if(  (a1=='Y'&&a2=='Y'&&a3=='Y')  || (a4=='Y' && a5=='Y' && a6=='Y')  ||  ( a7=='Y' && a8=='Y' && a9=='Y') || (a1=='Y'&&a4=='Y'&&a7=='Y')  || (a2=='Y'&& a5=='Y' && a8=='Y') || (a3=='Y' && a6=='Y' && a9=='Y') || (a1=='Y' && a5=='Y' && a9=='Y') ||  (a3=='Y'&& a5=='Y' && a7=='Y')  )
    {
   
    cout<<pl2<<"  WINS!!!";
    cin.get(ch);
   
    flag++;
    cin.get(ch);
    cout<<" THANK YOU FOR PLAYING TIC-TAC-TOE";
    cout<<" PRESS 1 FOR RE-MATCH BETWEEN THE SAME PLAYERS";
    cout<<" PRESS 2 FOR NEW GAME";
    cout<<" PRESS 3 TO QUIT THE GAME";
    cin>>finalchoice;
    if(finalchoice==1)
    goto rematch;
    else if (finalchoice==2)
    goto begin;
    else if(finalchoice==3)
    goto finish;
    else

    break;
    }


    }while(counter<=9 );

    if(flag==0)
    {
    cout<<"THE GAME ENDS IN A DRAW";
    cout<<" THANK YOU FOR PLAYING TIC-TAC-TOE";
    cout<<" PRESS 1 FOR RE-MATCH BETWEEN THE SAME PLAYERS";
    cout<<" PRESS 2 FOR NEW GAME";
    cout<<" PRESS 3 TO QUIT THE GAME";
    cin>>finalchoice;
    if(finalchoice==1)
    goto rematch;
    else if (finalchoice==2)
    goto begin;
    else if(finalchoice==3)
    goto finish;




    }

    getch();
    finish:
    }
    void showgame(char z1,char z2,char z3,char z4,char z5,char z6,char z7,char z8,char z9)
    {
    cout<<"          1       2       3   ";
    cout<<"             |         |       ";
    cout<<"             |         |       ";
    cout<<" 1     "<<z1<<"    |    "<<z2<<"    |    "<<z3<<"    ";
    cout<<"     ________|_________|________";
    cout<<"             |         |       ";
    cout<<"             |         |       ";
    cout<<" 2     "<<z4<<"    |    "<<z5<<"    |    "<<z6<<"    ";
    cout<<"     ________|_________|________";
    cout<<"             |         |       ";
    cout<<" 3    "<<z7<<"     |    "<<z8<<"    |    "<<z9<<"    ";
    cout<<"             |         |       ";

    }
Antony Ajay's Avatar

Blazing goIITian

Joined: 4 Dec 2007
Posts: 356
17 Feb 2008 20:27:34 IST
2 people liked this

I dont think this works properly.This was created by another team....



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

fstream file("shoot.txt",ios::binary|ios::ate|ios::in);

int d=0,no_arrow=30;
int score1=0,no_balloon=20;
char string1[20];

class shoot
{
   private: int p,q,l,m,bx,by;               //Private member of the class
        char ch;
   public:  shoot()                          //Constructor
        {q=60;p=140;m=430;bx=60;by=120;}
        void drawaman();                 //Member functions
        void movement();
        void movement_balloon();
        void arrow();
        void bullet();
        void end();
        void menu();
        void game();
        void score();
        void draw_burst(int,int);
}S;
/*-------------------------------------------------------------------------*/
void main()
{
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;

    /* initialize graphics, local variables */
    initgraph(&gdriver, &gmode, "c:\\tc");

    S.game();
    S.menu();
}
/*-------------------------------------------------------------------------*/
void shoot:: movement_balloon()
{

   setcolor(0);
   setfillstyle(SOLID_FILL,0);             //To move the balloon continously
   fillellipse(470,m+4,15,20);
   pieslice(470,m+24,310,220,5);
   line(470, m+24,467,m+84);
   if((m+40)>=10)
   {
      m-=4;
      setcolor(4);
      setfillstyle(SOLID_FILL,4);
      fillellipse(470,m+4,15,20);
      pieslice(470,m+24,310,220,5);
      line(470, m+24,467,m+84);
   }
   else
   {
      m=600;
      no_balloon-=1;
      if(no_balloon==0)                   //If no balloons left- game over
      {
       cleardevice();
       setcolor(BROWN);
       settextstyle(1,HORIZ_DIR, 4);
       outtextxy(130,160,"NO MORE BALLOONS LEFT");
       outtextxy(150,100,"YOUR SCORE IS :: ");
       itoa(score1,string1,10);
       settextstyle(4,0,4);
       outtextxy(440,100,string1);
       end();
      }

      setcolor(0);
      setfillstyle(SOLID_FILL,0);
      fillellipse(470,m+4,15,20);
      pieslice(470,m+24,310,220,5);
      line(470, m+24,467,m+84);

      }
   }
/*-------------------------------------------------------------------------*/

void shoot:: drawaman()
{
   circle(p+14,q-20,20);           //To draw the man
   line(p+12,q+70,p+12,q);
   line(p+14,q+70,p+14,q);
   line(p+10,q+70,p-12,q+80);
   line(p+15,q+70,p+37,q+80);
   line(p+15,q+20,p+25,q+15);
   line(p+15,q+20,p+25,q+25);
   circle(p+35,q-15,2);
   circle(p+23,q-22,2);
   arc(p+25,q-14,200,10,7);
}
/*-------------------------------------------------------------------------*/

void shoot:: movement()
{

    if (kbhit()!=0)                //To move the man
    ch=getch();

    if (ch==72)                    //To move the man up
    {
         setcolor(0);
         S.drawaman();
         delay(2);
         if((q-40)>=25)
              q-=10;
         setcolor(9);
         S.drawaman();

    }
    if (ch==80)                    //To move the man down
    {
        setcolor(0);
        S.drawaman();
        delay(2);
        if((q+40)<=410)
             q+=10;
        setcolor(9);
        S.drawaman();
    }

}
/*-------------------------------------------------------------------------*/

void shoot:: bullet()
{
  line(bx+40,by,bx+75,by);
  line(bx+75,by,bx+70,by+10);
  line(bx+75,by,bx+70,by-10);
}

void shoot:: arrow()
{

    if (kbhit()!=0)                //To move the man
    ch=getch();

    if (ch==' '&&no_arrow>0)                    //To move the man up
    {
         setcolor(0);
         S.bullet();
         if((bx+25)<=600)
              bx+=25;
         setcolor(9);
         S.bullet();

    }

    if(no_arrow==0)                     //If no arrows left- game over
    {
       cleardevice();
       setcolor(BROWN);
       settextstyle(1,HORIZ_DIR, 4);
       outtextxy(130,160,"NO MORE ARROWS LEFT");
       outtextxy(150,100,"YOUR SCORE IS :: ");
       file.write((char*)&S,sizeof(shoot));
       itoa(score1,string1,10);
       settextstyle(4,0,4);
       outtextxy(425,100,string1);
       end();
    }
    if(score1==120)                     //If score is 80- next level
    {
       cleardevice();
       setcolor(BROWN);
       settextstyle(1,HORIZ_DIR, 4);
       outtextxy(150,160," YOU WON THE GAME");
       outtextxy(150,100,"YOUR SCORE IS :: ");
       itoa(score1,string1,10);
       settextstyle(4,0,4);
       outtextxy(425,100,string1);
       end();
    }

}
/*-------------------------------------------------------------------------*/

void shoot:: menu()
{

   int a,s;
   getch();
   cleardevice();
   setcolor(6);
   rectangle(4, 4, 635, 475);
   rectangle(0, 0, 639, 479);
   rectangle(6, 6, 633, 473);
   setcolor(4);
   outtextxy ( 100,50 ," ENTER THE OPTION");      //Menu
   outtextxy ( 100,150," 1.INSTRUCTION ");
   outtextxy ( 100,250," 2.PLAY GAME ");
   outtextxy ( 100,350," 3.QUIT");
   a=getch();                                     //If option is 1
   if(a==49)                                      //Instructions
   {
     cleardevice();
     setcolor(6);
     rectangle(4, 4, 635, 475);
     rectangle(0, 0, 639, 479);
     rectangle(6, 6, 633, 473);
     setcolor(4);
     settextstyle(1,HORIZ_DIR, 5);
     outtextxy(170,10,"INSTRUCTIONS");
     setusercharsize(40,70,20,20);
     outtextxy(10,70,"1. You can play three levels.");
     outtextxy(10,110,"2. You can move the man UP and DOWN with the help of arrow keys.");
     outtextxy(10,150,"3. Press Space Bar to shoot the arrow.");
     outtextxy(10,190,"4. You score 10 points every time you shoot the balloon.");
     outtextxy(10,230,"5. First level has 16 arrows and 10 balloons.");
     outtextxy(10,270,"6. You require to score 80 points to enter the second level.");
     outtextxy(10,310,"7. Second level has 16 arrows and 13 balloons.");
     outtextxy(10,350,"8. You require to score 120 points to enter the third level.");
     outtextxy(10,390,"9. Third level has 16 arrows and 15 balloons.");
     setcolor(6);
     outtextxy(200,430,"Press any key to continue");
     settextstyle(1,HORIZ_DIR, 5);
     S.menu();
     getch();
   }

   if(a==51)                               //If option is 3
   {                                       //Exit
     exit(1);
   }
   if(a==50)                               //If option is 2
   {                                       //To play the game
    cleardevice();
    setcolor(9);                       //To draw the man
    S.drawaman();
    while(1)
    {
           setcolor(BROWN);
           rectangle(114, 4, 635, 475);
           rectangle(110, 0, 639, 479);
           rectangle(116, 6, 633, 473);

           S.movement();               //To move the man and balloon
           S.movement_balloon();
           if (ch==' ')                //Space- to shoot the arrow
           {
            bx=p;by=q;
            s=1;

        }
        if (s==1)
        {
            if(getpixel(bx,by)!=BROWN)         //To move the arrow till the end
            {
                S.arrow();
                S.draw_burst(bx,by);
             }
            else
            {

                no_arrow-=1;  //Reduce the number of arrows
                s=0;
                bx=p;by=q;
                d=0;
            }
        }
        if(ch=='q'||ch=='Q')          //To quit
        {
          cleardevice();
          S.end();
        }
       S.score();
    }
    }
 }
/*-------------------------------------------------------------------------*/

void shoot:: game()
{
    /* set fill style and draw a pie slice */
    enum coord { o=7,x1=630, y = 10,y1 = 460, s = 0, e = 360, r = 7 };
    while (!kbhit())
    {
       for(int i=0;i<617;i+=17)
       {
         int a = rand() % 14 + 1;
         pieslice(o+i, y, s, e,r);
         setcolor(a);
         setfillstyle(SOLID_FILL,a);
         a = rand() % 14 + 1;
         setcolor(a);
         setfillstyle(SOLID_FILL,a);
         pieslice(x1-i,y1, s, e,r);
        }

        for(i=0;i<450;i+=17)
        {
         pieslice(o, y+i, s, e,r);
         int a = rand() % 14 + 1;
         setfillstyle(SOLID_FILL,a);
         setcolor(a);
         pieslice(x1, y1-i, s, e,r);
        }
    settextstyle(1,HORIZ_DIR, 5);
    outtextxy(130,200,"SHOOT THEM DOWN");

      }
}
/*-------------------------------------------------------------------------*/

void shoot:: draw_burst ( int x, int y )
{
     if(getpixel(x,y)==RED)                  //To check if the arrow
     {                                       //touches the balloon
    sound(500);
    delay(3);
    m=430;                               //To start the movement of
    nosound();                           //balloon again
    setcolor(0);
    setfillstyle(SOLID_FILL,0);
    bar(450,470,497,10);
                         //To draw the brust
    setcolor(8);
    setlinestyle(0,0,1);
    line (x-16, y-12, x-10, y-2);
    line (x-10, y-2, x-16, y);
    line (x-16, y, x-10, y+2);
    line (x-10, y+2, x-16, y+12);

    line ( x-16, y+12, x-6, y+2);
    line ( x-6, y+2, x, y+12);
    line ( x, y+12, x+6, y+2);
    line ( x+6, y+2, x+16, y+12);

    line ( x-16, y-12, x-6, y-2 );
    line ( x-6, y-2, x, y-12 );
    line ( x, y-12, x+6, y-2 );
    line ( x+6, y-2, x+16, y-12);

    line ( x+16, y-12, x+10, y-2);
    line ( x+10, y-2, x+16, y);
    line ( x+16, y, x+10, y+2);
    line ( x+10, y+2, x+16, y+12);
    no_balloon-=1;                      //Reduce the number of balloon
    if(no_balloon==0)                   //If no balloons left- game over
    {
       cleardevice();
       setcolor(BROWN);
       settextstyle(1,HORIZ_DIR, 4);
       outtextxy(130,160,"NO MORE BALLOONS LEFT");
       outtextxy(150,100,"YOUR SCORE IS :: ");
       itoa(score1,string1,10);
       settextstyle(4,0,4);
       outtextxy(440,100,string1);
       end();
    }
    score1+=10;                           //To increase the score
    delay(100);
    setfillstyle(SOLID_FILL,0);
    bar(x-30, y-34,x+30,y+74);            //To make the brust black
     }

}
/*-------------------------------------------------------------------------*/

void shoot:: score()
{
    char string[10],s[10],str[10];
    setcolor(4);
    itoa(no_arrow,string,10);
    settextstyle(4,0,4);
    outtextxy(50,400,string);     //To display number of arrows
    delay(5);
    setcolor(0);
    setfillstyle(1,0);
    bar(50,400,90,450);           //To draw at the side
    setcolor(9);
    line(10,420,40,420);
    line(40,420,35,410);
    line(40,420,35,430);
    setcolor(4);                  //To draw balloon at the side
    setfillstyle(SOLID_FILL,4);
    fillellipse(25,320,10,15);
    line(25,335,27,365);
    setcolor(4);
    itoa(no_balloon,str,10);     //To display number of balloons
    settextstyle(4,0,4);
    outtextxy(50,320,str);
    delay(5);
    setcolor(0);
    setfillstyle(1,0);
    bar(50,320,90,450);
    setcolor(4);                 //For level and quit
    settextstyle(7,0,3);
    outtextxy(10,130,"LEVEL");
    outtextxy(10,160,"  1");
    outtextxy(10,230,"Q: QUIT");
    outtextxy(10,30,"SCORE");    //To display score
    itoa(score1,s,10);
    settextstyle(4,0,4);
    outtextxy(30,70,s);
    delay(5);
    setcolor(0);
    setfillstyle(1,0);
    bar(25,70,90,110);

}
/*-------------------------------------------------------------------------*/

void shoot:: end()
{
      setcolor(4);
      rectangle(4, 4, 635, 475);
      rectangle(0, 0, 639, 479);
      rectangle(6, 6, 633, 473);
      setcolor(12);
      settextstyle(1,HORIZ_DIR, 5);
      outtextxy(200,205,"GAME OVER");
      delay(2000);
      exit(1);
}
/*-------------------------------------------------------------------------*/
Aatish Pandit's Avatar

Blazing goIITian

Joined: 3 Feb 2007
Posts: 1200
17 Feb 2008 20:28:21 IST
2 people liked this

Cricket score card.....


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


class batsman
{
private:
    char f_name[20],l_name[20];
    int run,four,six;
public:
    batsman();
    void update(int);
    void display();
}

batsman::batsman()
{
cout<<"Enter the first name of batsman : ";
cin.getline(f_name,20);
cout<<"Enter the last name of batsman  : ";
cin.getline(l_name,20);
run=0;
four=0;
six=0;
}
void batsman :: update(int r)
{
    if((r>=1&&r<=4)||r==6)
    {
        if(r==4)
        four++;
        else if(r==6)
        six++;

    run+=r;
    }
else
{
cout<<" wrong entry";
getch();
}
}

void batsman::display()
{
clrscr();
cout<<" Batsman's Name is : "<<f_name<<l_name;
cout<<"  Runs scored by him: "<<run;
cout<<"  No. of fours....  : "<<four;
cout<<"  No. of sixes....  : "<<six;
getch();
}


void main()
{

batsman A[10];
int R;

int i=1;

aatish:
clrscr();
cout<<" Batsamn playing cuurently........: "<<i;
cout<<" press '1' '2' '3' '4' or '6' for appropriate runs scored by the batsman:  ";
cout<<" press '9' if batsman is out...";
cout<<" press '0' if you want to exit";
cout<<" press '8' to display the info abt current batsman ";
cin>>R;

if(R==9)
{

cout<<" the batsman is out....";
i++;
getch();
goto aatish;
}

else if (R==0)
 goto khatam;

else if (R==8)
{
int j;
cout<<" enter the batsman no. to view info abt....";
cin>>j;
A[j-1].display();
goto aatish;
}
else
{
A[i-1].update(R);
goto aatish;
}

khatam:
}
Aatish Pandit's Avatar

Blazing goIITian

Joined: 3 Feb 2007
Posts: 1200
17 Feb 2008 20:29:21 IST
1 people liked this

SUDOKU GENERATOR...........

# include <stdlib.h>
# include <stdio.h>
# include <conio.h>
 int A[9][9],a[3][3];
void StepDown(int x)
{
 int i,j,k,I,J,K;
 int b[3][3];
 for(I=x,i=0;I<3;I++,i++)for(J=0,j=0;J<3;J++,j++) b[I][J]=a[i][j];
 for(I=0;I<x;I++,i++) for(J=0,j=0;J<3;J++,j++) b[I][J]=a[i][j];
 for(i=0;i<3;i++) for(j=0;j<3;j++) a[i][j]=b[i][j];
}
void main()
{
 int i,j,k,I,J,K,M,N,P[9],r1;
 randomize();
 clrscr();
 for(i=0,k=1;i<9;k++,i++) P[i]=k;
 /*Randomize the values of array a 3 x 3 [LATER]*/
for(j=0;j<20;j++)
 for(i=0;i<9;i++)
 {
    r1=rand()%9;
    P[i]=(P[i]+P[r1])-(P[r1]=P[i]);
 }

    for(M=0,N=0;M<3;M++,N+=3)
    {
      for(i=0,I=0;i<3;i++) for(j=0;j<3;j++,I++) a[i][j]=P[I];
      StepDown(M);
      for(i=0;i<3;i++) for(j=0;j<3;j++) A[i][j+N]=a[i][j];
    }
    for(M=0,N=0;M<3;M++,N+=3)
    {
      for(i=0,I=-1;i<3;i++) for(j=0;j<3;j++,I++) a[i][j]=P[I];
      a[0][0]=P[8];
      StepDown(M);
      for(i=0;i<3;i++) for(j=0;j<3;j++) A[i+3][j+N]=a[i][j];
    }

    for(M=0,N=0;M<3;M++,N+=3)
    {
      for(i=0,I=-2;i<3;i++) for(j=0;j<3;j++,I++) a[i][j]=P[I];
      a[0][0]=P[7];a[0][1]=P[8];
      StepDown(M);
      for(i=0;i<3;i++) for(j=0;j<3;j++) A[i+6][j+N]=a[i][j];
    }
 int cl=2,clr=cl;
 for(i=0;i<9;i++)
 {
  for(clr=cl,j=0;j<9;j++)
  {
   textcolor(clr); cprintf("%4d",A[i][j]);
    if((j+1)%3==0) {clr++; printf("  "); }
  }
    if((i+1)%3==0) {cl+=9; printf("\n\n");}
    printf("\n\n");
 }
 getch();
}

Antony Ajay's Avatar

Blazing goIITian

Joined: 4 Dec 2007
Posts: 356
17 Feb 2008 20:31:20 IST
2 people liked this

File handeling...


#ifndef __IOSTREAM_H
#include <iostream.h>
#endif

#ifndef __IOMANIP_H
#include <iomanip.h>
#endif

#ifndef __DIR_H
#include <dir.h>
#define __DIR_H
#endif

#ifndef __FILEDATA_H
#include "filedata.h"
#endif

FileData::FileData( ffblk& blk ) :
    fileName( blk.ff_name ),
    fileDate( (blk.ff_fdate >> 5) & 0x000F,
              blk.ff_fdate & 0x0001F,
              (blk.ff_fdate >> 9) + 1980 ),
    fileSize( blk.ff_fsize ),
    fileTime( blk.ff_ftime >> 11,
              (blk.ff_ftime >> 5) & 0x3F,
              blk.ff_ftime & 0x1F )
{
}

void FileData::printOn( ostream& outputStream ) const
{
    outputStream << setw( 14 ) << setiosflags( ios::left )   << fileName
                 << setw( 18 ) << fileDate
                 << setw( 17 ) << resetiosflags( ios::left ) << fileTime
                 << setw( 10 ) << fileSize << " bytes";
}

int FilesByName::isEqual( const Object& testFile ) const
{
    return fileName == ( (FilesByName&)testFile ).fileName;
}

int FilesByName::isLessThan( const Object& testFile ) const
{
    return fileName < ( (FilesByName&)testFile ).fileName;
}

int FilesByDate::isEqual( const Object& testFile ) const
{
    return fileDate == ( (FilesByDate&)testFile ).fileDate &&
           fileTime == ( (FilesByDate&)testFile ).fileTime;
}

int FilesByDate::isLessThan( const Object& testFile ) const
{
    if( fileDate == ( (FilesByDate&)testFile ).fileDate )
        return fileTime < ( (FilesByDate&)testFile ).fileTime;
    else
        return fileDate < ( (FilesByDate&)testFile ).fileDate;
}

int FilesBySize::isEqual( const Object& testFile ) const
{
    return fileSize == ( (FilesBySize&)testFile ).fileSize;
}

int FilesBySize::isLessThan( const Object& testFile ) const
{
    return fileSize < ( (FilesBySize&)testFile ).fileSize;
}

Antony Ajay's Avatar

Blazing goIITian

Joined: 4 Dec 2007
Posts: 356
17 Feb 2008 20:33:51 IST
2 people liked this

#include<fstream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<process.h>

fstream file;

class telephone
{
    char name[20];
    long int phone;
    char address[50];
    public: void getdata();
            void add();
            void display();
            void search(long int);
}A;
void telephone :: getdata()        //To get the data
{
   cout<<"\n\nENTERING DATA";        //Ask for name, address, number
   cout<<"\n------------";
   cout<<"\n\nEnter name:: ";
   gets(name);
   cout<<"\nEnter address:: ";
   gets(address);
   cout<<"\nEnter phone number:: ";
   cin>>phone;
}
void telephone :: display()        //To the display the records
{
    file.seekg(0,ios::end);
    int bytes=file.tellg();        //To calculate the size of file
    int count=0;
    count=bytes/sizeof(telephone); //To calculate the number of records

    cout<<"\n\nDISPLAYING DATA";
    cout<<"\n--------------";
    cout<<"\n\n\tName";
    cout<<"\t\tPhone number";
    cout<<"\t\tAddress";
    cout<<"\n\t----";
    cout<<"\t\t------------";
    cout<<"\t\t-------";

    for(int i=0;i<count;i++)
    {
       file.seekg(i*sizeof(telephone),ios::beg); //Points at the particular record
       file.read((char*)&A,sizeof(telephone));   //To read from the file
       cout<<"\n\t"<<name;
       cout<<"\t\t"<<phone;
       cout<<"\t\t\t"<<address;
    }
}
void telephone :: search(long int ph)
{
    file.seekg(0,ios::end);
    int bytes=file.tellg();         //To calculate the size of file
    int count=0;
    count=bytes/sizeof(telephone);  //To count the number of records
    for(int i=0;i<count;i++)
    {

       file.seekg(i*sizeof(telephone),ios::beg); //Points at the particular record
       file.read((char*)&A,sizeof(telephone)); //Read from the file
       if(A.phone==ph)                         //To check if the phone number matches
       {
         cout<<"\nName:: "<<A.name;
         cout<<"\n\nAddress:: "<<A.address;
         cout<<"\n\nPhone number:: "<<A.phone;
         break;
       }
        else
       {
         cout<<"\n\nNO MATCH";
         break;
       }
    }
}
void main()
{
   clrscr();   //Clears the screen
   char n;
   int ch;
   file.open("tele.dat",ios::in|ios::out|ios::binary|ios::app);//To open the file
   do
   {
      cout<<"\n\nMENU";
      cout<<"\n----";
      cout<<"\n\n1.ADD RECORD";
      cout<<"\n\n2.DISPLAY RECORD";
      cout<<"\n\n3.SEARCH";
      cout<<"\n\n4.EXIT";
      cout<<"\n\nENTER YOUR CHOICE:: ";
      cin>>ch;                           //To take in the choice
      if(ch==1)
      {
         A.getdata();
         file.write((char*)&A,sizeof(telephone));//Writes into the file
      }
      if(ch==2)                  //When choice is dispaly
      {
         A.display();
      }
      if(ch==3)
      {
         long int ph;             //Ask for the phone number to search
         cout<<"\n\nEnter the phone number to search:: ";
         cin>>ph;
         A.search(ph);            //Pass the number and search
      }
      if(ch==4)
      {
        file.close();             //Close the file
        exit(0);                  //Exit
      }
   }while(ch!=4);                 //To check if user wants to come out
   getch();
}

Aatish Pandit's Avatar

Blazing goIITian

Joined: 3 Feb 2007
Posts: 1200
17 Feb 2008 20:53:17 IST
1 people liked this

Binary Search.......

#include <iostream.h>
#include <conio.h>
int binary(int P[10], int data ,int n)
{
    int i, flag = 0, first = 0, last, pos = 1, mid;
    last = n - 1;
    while ((first <= last) && (flag == 0))
    {
        mid = (first + last) / 2;
        if (P[mid] == data)
        {
            pos = pos + mid;
            flag = 1;
        }   
        else
        {
            if (P[mid] < data)
                first = mid +1;
            else
                last = mid - 1;
        }
        if (flag == 1)
             return(1);
        else
             return(-1);
    }
}

void main()
{
    clrscr();
    int a[10];
    int i, j, dt, flg = 0;
    cout << "Enter sorted elements into an array \n";
    for (i=0; i<10; i++)
        cin >> a[i];
    cout << "Enter the elemnt to search : ";
    cin >> dt;
    flg = binary(a, dt, 10);
    if (flg == 1)
        cout << "The element found in the array :";
    else
        cout << "The element does not found in the array :";
}




Aatish Pandit's Avatar

Blazing goIITian

Joined: 3 Feb 2007
Posts: 1200
17 Feb 2008 20:54:45 IST
2 people liked this

Insertion Sort.........


#include <iostream.h>
#include <conio.h>
// Function to implement the insertion short
void Insert_sort(int arr[ ], int N)
{
    int x, i, j, T;
    for (i = 1; i < N; i++)
    {
        T = arr[i];  // Extracts the first element of the unsorted part
        j = i - 1;
        while ((T < arr[j]) && (j >= 0))
        {
            arr[j+1] = arr[j];
            j = j - 1;
        }
        arr[j+1] = T;
        // Displays the output after every insertion
        for (x = 0; x < N; x++)                            
            cout << arr[x] << "  ";
        cout << "\n";
    }
    cout << "\nThe sorted list is ... \n";
    for (i = 0; i < N; i++)  cout << arr[i] << endl;
}
void main()
{
    clrscr();
    int A[10];
    cout << "Enter the array elements : ";
    for (int i=0; i<10; i++)
        cin >> A[i];
    Insert_sort(A, 10);
}

Aatish Pandit's Avatar

Blazing goIITian

Joined: 3 Feb 2007
Posts: 1200
17 Feb 2008 21:15:41 IST
2 people liked this

//Program to sort the array using bubble sort and search an element using binary search.
#include<iostream.h>
#include<conio.h>
#include<process.h>
//CLASS DECLARATION
class sort
{
      int i, j, a[10], temp, flag;
      public:
        void get();
        void bubble();
        void binary();
};
void sort::get()    //FUNCTION TO GET THE ARRAY
{
    clrscr();
    cout<< "\n\tEnter the array \n";
    for(i=0;i<10;i++)
      {
        cout<<"\t";
        cin>>a[i];
    }
}
void sort::bubble()    //FUNCTION FOR BUBBLE SORT
{
    clrscr();
    flag='y';
    while(flag=='y')
    {
        flag='n';
        for(i=0;i<9;i++)
        {
            if(a[i]>a[i+1])
            {
                temp=a[i];
                a[i]=a[i+1];
                a[i+1]=temp;
                flag='y';
            }
        }
    }
    cout<<"\n\tSorted array is ";
    for(i=0;i<10;i++)
        cout<<","<<a[i];
}
void sort::binary()        //FUNCTION FOR BINARY SEARCH
{
    int first=0,x, last=9,mid;
    char flag='f';
    cout<< "\n\n\tEnter the element to be searched ";
    cin>>x;
    while((first<=last)&&(flag=='f'))
    {
        mid=(first+last)/2;
        if(a[mid]==x)
        {
            i=mid;
              flag='t';
        }
        if(a[mid]<x)
            first=mid+1;
        if(a[mid]>x)
            last=mid-1;
    }
    if(flag=='t')
        cout<< "\n\tThe element "<<x<<" was found at the position number "<<i+1;
    if(flag=='f')
        cout<< "\n\tSorry! element not found ";
}
//M A I N   P R O G R A M
void main()
{
    sort x;
    x.get();
    x.bubble();
    x.binary();
    cout<< "\n\n\n\n\tPress any key to continue.....";
    getch();
    cout<< "\n\tBye!";
    getch();
} //E N D   O F   M A I N
Aatish Pandit's Avatar

Blazing goIITian

Joined: 3 Feb 2007
Posts: 1200
17 Feb 2008 21:16:15 IST
2 people liked this

#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include<iomanip.h>
#include<string.h>
// Function to arrange 10 elements using selection sort
void SelectionSort()
{
    int range[10], loc, lowest, T, N, i, j, x;
    N = 10;
    cout << "Enter the array elements : \n";
    for (i = 0; i < N; i++)
    {
        cout << "Location " << i + 1 << ". Value :  ";
        cin >> range[i];
    }
    for (i = 0; i < N - 1; i++)
    {
        lowest = range[i];
        loc = i;
        for (j = i + 1; j < N; j++)
        {
            if (lowest > range[j])
            {
                loc = j;
                lowest = range[j];
            }
        }
        T = range[i];
        range[i] = range[loc];
        range[loc] = T;
    }
    cout << "\nThe sorted list is ... \n";
    for (i = 0; i < N; i++)
        cout << range[i] << endl;
}
void main()
{
    clrscr();
    SelectionSort();
}

Aatish Pandit's Avatar

Blazing goIITian

Joined: 3 Feb 2007
Posts: 1200
17 Feb 2008 21:17:59 IST
3 people liked this

//**********************************************************
//      PROJECT COMPUTER QUIZ
//**********************************************************

//**********************************************************
//    INCLUDED HEADER FILES
//**********************************************************
#include <iostream.h>
#include <conio.h>
#include <dos.h>
#include <string.h>
#include <fstream.h>
#include <process.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>

//**********************************************************
//    CLASS NAME : lines
//    DETAILS    : IT CONTROLS FUNCTIONS RELATED TO DRAW
//                   LINES, BOXES, ETC.
//**********************************************************
class lines
{
public :
        void line_hor (int, int, int, char) ;
        void line_ver (int, int, int, char) ;
        void box (int,int,int,int,char) ;
} ;

//***************************************************************
//    CLASS NAME : menu
//    DETAILS    : IT CONTROLS OVER ALL FUNCTIONING OF PROJECT
//***************************************************************

class menu
{
public :
        void main_menu(void) ;
        char *sub_menu(void) ;
        void start(void) ;
private :
        void edit_menu(void) ;
} ;

//**********************************************************
//    CLASS NAME : quiz
//    DETAILS    : IT CONTROLS OVER ALL THE FUNCTIONS
//                   RELATED TO QUIZ
//**********************************************************

class quiz
{
public :
        void play(char filename[13]) ;
        void add(char filename[13]) ;
        void deletion(char filename[13]) ;
        void modify(char filename[13]) ;
private :
        void delete_record(char filename[13], int) ;
        void modify_record(char filename[13], int) ;
        void display_score(char name[20], int, int) ;
        int  recordno(char filename[13], int) ;
        int  record_count(char filename[13]) ;
        int  found_record(char filename[13], int) ;
        void display_record(char filename[13], int) ;
        int  ques_no ;
        char ques[60] ;
        char ans1[50] ;
        char ans2[50] ;
        char ans3[50] ;
        char sol ;
} ;

//**********************************************************
//    CLASS NAME    : lines
//    FUNCTION NAME : line_hor
//    DETAILS       : IT ACCEPTS THE ROWS AND COLUMNS AND
//                 DRAW THE HORIZONTAL LINE
//**********************************************************

void lines :: line_hor(int column1, int column2, int row, char c)
{
   for ( column1; column1<=column2; column1++ )
   {
      gotoxy(column1,row) ;
      cout <<c ;
   }
}

//**********************************************************
//    CLASS NAME    : lines
//    FUNCTION NAME : line_ver
//    DETAILS       : IT ACCEPTS THE ROWS AND COLUMNS AND
//                 DRAW THE VERTICAL LINE
//**********************************************************

void lines :: line_ver(int row1, int row2, int column, char c)
{
   for ( row1; row1<=row2; row1++ )
   {
      gotoxy(column,row1) ;
      cout <<c ;
   }
}

//**********************************************************
//    CLASS NAME    : lines
//    FUNCTION NAME : box
//    DETAILS       : IT ACCEPTS THE ROWS AND COLUMNS AND
//                 DRAW THE BOX
//**********************************************************

void lines :: box(int column1, int row1, int column2, int row2, char c)
{
   char ch=218 ;
   char c1, c2, c3, c4 ;
   char l1=196, l2=179 ;
   if (c == ch)
   {
    c1 = 218 ;
    c2 = 191 ;
    c3 = 192 ;
    c4 = 217 ;
    l1 = 196 ;
    l2 = 179 ;
   }
   else
   {
    c1 = c ;
    c2 = c ;
    c3 = c ;
    c4 = c ;
    l1 = c ;
    l2 = 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,l1) ;
   line_hor(column1,column2,row2,l1) ;
   column1-- ;
   column2++ ;
   row1++ ;
   row2-- ;
   line_ver(row1,row2,column1,l2) ;
   line_ver(row1,row2,column2,l2) ;
}

//**********************************************************
//    CLASS NAME    : menu
//    FUNCTION NAME : start
//    DETAILS       : IT CREATES THE OPENING SCREEN
//**********************************************************
void menu :: start(void)
{
   lines line ;
   textmode(C40) ;
   clrscr() ;
   textbackground(LIGHTCYAN);
   textcolor(BLACK) ;
   clrscr() ;
   gotoxy(12,12) ;
   cout <<"RAILWAY TIME TABLE" ;
   line.box(4,10,36,14,219) ;
   gotoxy(5,20);
   cout<<"MADE BY :";
   gotoxy(5,21);
   cout<<"Aatish Pandit\n    Nitant Singh Chouhan";


   line.box(2,19,40,24,219);
   gotoxy(4,10);
   getch() ;
   textbackground(BLACK) ;
   textcolor(LIGHTGRAY) ;
   clrscr() ;
}

//**********************************************************
//    CLASS NAME    : menu
//    FUNCTION NAME : main_menu
//    DETAILS       : IT CREATES THE MAIN MENU TO CONTROL
//                   ALL THE FUNCTIONS
//**********************************************************

void menu :: main_menu(void)
{
   lines line ;
   textmode(C40) ;
   clrscr ;
   int valid ;
   int n = 4 ;
   int x = 14 ;
   char ch1, ch2 ;
   char chr1=219, chr=175 ;
   do
   {
    line.box (1,1,39,25,219) ;
    line.line_hor(9,31,6,196) ;
    line.box (8,3,32,20,218) ;
    char c1=24, c2=25 ;
    gotoxy(3,24) ;
    cout <<c1 ;
    cout <<c2 ;
    cout <<"=Move <ENTER>=Select <ESC>=Exit" ;
    gotoxy(13,5) ;
    cout <<chr1 ;
    textbackground(WHITE) ;
    textcolor(BLACK) ;
    gotoxy(14,5) ;
    cprintf("Q U I Z ") ;
    textbackground(BLACK) ;
    textcolor(LIGHTGRAY) ;
    gotoxy(14,8) ;
    cout <<"OPTIONS" ;
    gotoxy(14,9) ;
    cout <<"-------" ;
    gotoxy(14,11) ;
    cout <<"PLAY" ;
    gotoxy(14,12) ;
    cout <<"ADD QUESTIONS" ;
    gotoxy(14,13) ;
    cout <<"EDIT" ;
    gotoxy(14,14) ;
    cout <<"QUIT" ;
    gotoxy(10,x) ;
    cout <<chr ;
    gotoxy(13,5) ;
    do
    {
      do
       {
        do
         {
        ch1 = getch() ;
        if ( ch1 == 27 )
            {
             textmode(C80) ;
             clrscr() ;
             exit(0) ;
             }
            } while (( ch1 != 0 ) && ( ch1 != 13 )) ;
            if ( ch1 != 13 )
            {
             do
              {
               ch2 = getch() ;
               if ( ch2 == 27 )
                    {
                        textmode(C80) ;
                        clrscr() ;
                        exit(0) ;
                    }
                } while (( ch2 != 72 ) && ( ch2 != 80 )    && ( ch2 != 13 )) ;
            }
        } while ((( ch1 != 0 ) || (( ch2 != 72 ) && ( ch2 != 80 ))) && (( ch1 != 13 ) && ( ch2 != 13 ))) ;
        if (( ch1 == 0 ) && ( ch2 == 80 ))
        {
            gotoxy(10,x) ;
            cout <<" " ;
            if (n == 4)
            {
                n = 1 ;
                x = x - 3 ;
            }
            else
            {
                n = n + 1 ;
                x = x + 1 ;
            }
            gotoxy(10,x) ;
            cout <<chr ;
            gotoxy(13,5) ;
            sound(200) ;
            delay(30) ;
            nosound() ;
        }
        if (( ch1 == 0 ) && ( ch2 == 72 ))
        {
            gotoxy(10,x) ;
            cout <<" " ;
            if ( n == 1 )
            {
                n = 4 ;
                x = x + 3 ;
            }
            else
            {
                n = n - 1 ;
                x = x - 1 ;
            }
            gotoxy(10,x) ;
            cout <<chr ;
            gotoxy(13,5) ;
            sound(200) ;
            delay(30) ;
            nosound() ;
        }
    } while (( ch1 != 13 ) && ( ch2 != 13 )) ;
    if (n == 1)
    {
        char filename[13] ;
        strcpy(filename,sub_menu()) ;
        if (strcmp(filename,"null"))
        {
            quiz q ;
            q.play(filename) ;
            clrscr() ;
        }
    }
    if (n == 2)
    {
        char filename[13] ;
        strcpy(filename,sub_menu()) ;
        if (strcmp(filename,"null"))
        {
            textmode(C80) ;
            clrscr() ;
            quiz q ;
            q.add(filename) ;
            textmode(C40) ;
            clrscr() ;
        }
    }
    if (n == 3)
        edit_menu() ;
   } while ( n != 4 ) ;
   textmode(C80) ;
   clrscr() ;
}

//**********************************************************
//    CLASS NAME    : menu
//    FUNCTION NAME : edit_menu
//    DETAILS       : IT CREATES THE EDIT MAIN MENU
//**********************************************************

void menu :: edit_menu(void)
{
   lines line ;
   int valid ;
   static int n = 3 ;
   static int x = 19 ;
   char ch1, ch2 ;
   char chr1=219, chr=175 ;
   do
   {
    line.box(19,14,31,20,218) ;
    gotoxy(21,15) ;
    cout <<chr1 ;
    textbackground(WHITE) ;
    textcolor(BLACK) ;
    gotoxy(22,15) ;
    cprintf("E D I T ") ;
    textbackground(BLACK) ;
    textcolor(LIGHTGRAY) ;
    gotoxy(23,17) ;
    cout <<"DELETE" ;
    gotoxy(23,18) ;
    cout <<"MODIFY" ;
    gotoxy(23,19) ;
    cout <<"RETURN" ;
    gotoxy(20,x) ;
    cout <<chr ;
    gotoxy(21,15) ;
    do
    {
        do
        {
            do
            {
                ch1 = getch() ;
                if ( ch1 == 27 )
                {
                    gotoxy(1,15) ; clreol() ;
                    gotoxy(1,17) ; clreol() ;
                    gotoxy(1,18) ; clreol() ;
                    gotoxy(1,19) ; clreol() ;
                    gotoxy(1,20) ; clreol() ;
                    gotoxy(19,14) ; clreol() ;
                    return ;
                }
            } while (( ch1 != 0 ) && ( ch1 != 13 )) ;
            if ( ch1 != 13 )
            {
                do
                {
                    ch2 = getch() ;
                    if ( ch2 == 27 )
                    {
                        gotoxy(1,15) ; clreol() ;
                        gotoxy(1,17) ; clreol() ;
                        gotoxy(1,18) ; clreol() ;
                        gotoxy(1,19) ; clreol() ;
                        gotoxy(1,20) ; clreol() ;
                        gotoxy(19,14) ; clreol() ;
                        return ;
                    }
                } while (( ch2 != 72 ) && ( ch2 != 80 )    && ( ch2 != 13 )) ;
            }
        } while ((( ch1 != 0 ) || (( ch2 != 72 ) && ( ch2 != 80 ))) && (( ch1 != 13 ) && ( ch2 != 13 ))) ;
        if (( ch1 == 0 ) && ( ch2 == 80 ))
        {
            gotoxy(20,x) ;
            cout <<" " ;
            if (n == 3)
            {
                n = 1 ;
                x = x - 2 ;
            }
            else
            {
                n = n + 1 ;
                x = x + 1 ;
            }
            gotoxy(20,x) ;
            cout <<chr ;
            gotoxy(21,15) ;
            sound(200) ;
            delay(30) ;
            nosound() ;
        }
        if (( ch1 == 0 ) && ( ch2 == 72 ))
        {
            gotoxy(20,x) ;
            cout <<" " ;
            if ( n == 1 )
            {
                n = 3 ;
                x = x + 2 ;
            }
            else
            {
                n = n - 1 ;
                x = x - 1 ;
            }
            gotoxy(20,x) ;
            cout <<chr ;
            gotoxy(21,15) ;
            sound(200) ;
            delay(30) ;
            nosound() ;
        }
    } while (( ch1 != 13 ) && ( ch2 != 13 )) ;
    if (n == 1)
    {
        char filename[13] ;
        strcpy(filename,sub_menu()) ;
        if (strcmp(filename,"null"))
        {
            textmode(C80) ;
            clrscr() ;
            quiz q ;
            q.deletion(filename) ;
            textmode(C40) ;
            clrscr() ;
            return ;
        }
        clrscr() ;
        return ;
    }
    else
    if (n == 2)
    {
        char filename[13] ;
        strcpy(filename,sub_menu()) ;
        if (strcmp(filename,"null"))
        {
            textmode(C80) ;
            clrscr() ;
            quiz q ;
            q.modify(filename) ;
            textmode(C40) ;
            clrscr() ;
            return ;
        }
        clrscr() ;
        return ;
    }
   } while ( n != 3 ) ;
   gotoxy(1,15) ; clreol() ;
   gotoxy(1,17) ; clreol() ;
   gotoxy(1,18) ; clreol() ;
   gotoxy(1,19) ; clreol() ;
   gotoxy(1,20) ; clreol() ;
   gotoxy(19,14) ; clreol() ;
}

//**********************************************************
//    CLASS NAME    : menu
//    FUNCTION NAME : sub_menu
//    DETAILS       : IT CREATES THE SUB MAIN MENU AND
//                   RETURN FILE NAME
//**********************************************************

char *menu :: sub_menu(void)
{
   lines line ;
   clrscr() ;
   int valid ;
   static int n = 1 ;
   static int x = 10 ;
   char ch1, ch2 ;
   char chr1=219, chr=175 ;
   line.box(1,1,39,25,219) ;
   line.line_hor(2,38,23,196) ;
   char c1=24, c2=25 ;
   gotoxy(3,24) ;
   cout <<c1 ;
   cout <<c2 ;
   cout <<"=Move <ENTER>=Select <ESC>=Exit" ;
   gotoxy(13,6) ;
   cout <<chr1 ;
   textbackground(WHITE) ;
   textcolor(BLACK) ;
   gotoxy(14,6) ;
   cprintf("S U B - M E N U ") ;
   textbackground(BLACK) ;
   textcolor(LIGHTGRAY) ;
   line.box(11,5,31,7,218) ;
   gotoxy(14,10) ;
   cout <<"COMPUTERS" ;
   gotoxy(14,12) ;
   cout <<"MATHEMATICS" ;
   gotoxy(14,14) ;
   cout <<"SCIENCE" ;
   gotoxy(14,16) ;
   cout <<"GENERAL" ;
   gotoxy(14,18) ;
   cout <<"RETURN" ;
   gotoxy(12,x) ;
   cout <<chr ;
   gotoxy(13,6) ;
   do
   {
    do
    {
        do
        {
            ch1 = getch() ;
            if ( ch1 == 27 )
            {
                clrscr() ;
                return("null") ;
            }
        } while (( ch1 != 0 ) && ( ch1 != 13 )) ;
        if ( ch1 != 13 )
        {
            do
            {
                ch2 = getch() ;
                if ( ch2 == 27 )
                {
                    clrscr() ;
                    return("null") ;
                }
            } while (( ch2 != 72 ) && ( ch2 != 80 )    && ( ch2 != 13 )) ;
        }
    } while ((( ch1 != 0 ) || (( ch2 != 72 ) && ( ch2 != 80 ))) && (( ch1 != 13 ) && ( ch2 != 13 ))) ;
    if (( ch1 == 0 ) && ( ch2 == 80 ))
    {
        gotoxy(12,x) ;
        cout <<" " ;
        if (n == 5)
        {
            n = 1 ;
            x = x - 8 ;
        }
        else
        {
            n = n + 1 ;
            x = x + 2 ;
        }
        gotoxy(12,x) ;
        cout <<chr ;
        gotoxy(13,6) ;
        sound(200) ;
        delay(30) ;
        nosound() ;
    }
    if (( ch1 == 0 ) && ( ch2 == 72 ))
    {
        gotoxy(12,x) ;
        cout <<" " ;
        if ( n == 1 )
        {
            n = 5 ;
            x = x + 8 ;
        }
        else
        {
            n = n - 1 ;
            x = x - 2 ;
        }
        gotoxy(12,x) ;
        cout <<chr ;
        gotoxy(13,6) ;
        sound(200) ;
        delay(30) ;
        nosound() ;
    }
   } while (( ch1 != 13 ) && ( ch2 != 13 )) ;
   clrscr() ;
   if (n == 1)
    return("computer.dat") ;
   else
   if (n == 2)
    return("maths.dat") ;
   else
   if (n == 3)
    return("science.dat") ;
   else
   if (n == 4)
    return("general.dat") ;
   return("null") ;
}

//**********************************************************
//    CLASS NAME    : quiz
//    FUNCTION NAME : record_count
//    DETAILS       : IT RETURNS THE NO. OF RECORD IN THE
//                   GIVEN FILE
//**********************************************************

int  quiz :: record_count(char filename[13])
{
   fstream file ;
   file.open(filename, ios::in) ;
   file.seekg(0,ios::beg) ;
   int t=0 ;
   while (file.read((char *) this, sizeof(quiz)))
    t++ ;
   file.close() ;
   return t ;
}

//**********************************************************
//    CLASS NAME    : quiz
//    FUNCTION NAME : add
//    DETAILS       : IT ADDS THE RECORDS IN THE GIVEN FILE
//**********************************************************

void quiz :: add(char filename[13])
{
   lines line ;
   int valid ;
   int t_ques_no ;
   t_ques_no = record_count(filename) ;
   t_ques_no++ ;
   if (t_ques_no == 1)
   {
    ques_no = t_ques_no ;
    strcpy(ques,"abc") ;
    strcpy(ans1,"-") ;
    strcpy(ans2,"-") ;
    strcpy(ans3,"-") ;
    sol = '0' ;
    fstream file ;
    file.open(filename, ios::out | ios::app ) ;
    file.write((char *) this, sizeof(quiz)) ;
    file.close() ;
    delete_record(filename,t_ques_no) ;
   }
   char ch ;
   do
   {
    clrscr() ;
    line.box(1,1,79,23,218) ;
    gotoxy(3,5) ;
    cout <<"question # " <<t_ques_no ;
    gotoxy(3,8) ;
    cout <<"question : " ;
    gotoxy(3,10) ;
    cout <<"answer 1 : " ;
    gotoxy(3,12) ;
    cout <<"answer 2 : " ;
    gotoxy(3,14) ;
    cout <<"answer 3 : " ;
    gotoxy(3,16) ;
    cout <<"solution : " ;
    do
    {
        line.box(1,1,79,23,218) ;
        valid = 1 ;
        gotoxy(1,25) ;    clreol() ;
        gotoxy(72,25) ;
        cout <<"<0>=EXIT" ;
        gotoxy(3,25) ;
        cout <<"ENTER QUESTION" ;
        gotoxy(14,8) ;
        gets(ques) ;
        strupr(ques) ;
        if (ques[0] == '0')
            return ;
        if (strlen(ques) > 159 || strlen(ques) == 0)
        {
            valid = 0 ;
            sound(500) ;
            delay(100) ;
            nosound() ;
            gotoxy(1,25) ;    clreol() ;
            gotoxy(1,24) ;
            cout <<"LENGTH SHOULD NOT BE BLANK OR GREATER THAN 159" ;
            gotoxy(1,25) ;
            cout <<"Press any key to continue..." ;
            getch() ;
            gotoxy(1,24) ;    clreol() ;
            gotoxy(1,25) ;    clreol() ;
            gotoxy(14,8) ; clreol() ;
        }
    } while ( !valid ) ;
    do
    {
        line.box(1,1,79,23,218) ;
        valid = 1 ;
        gotoxy(1,25) ;    clreol() ;
        gotoxy(72,25) ;
        cout <<"<0>=EXIT" ;
        gotoxy(3,25) ;
        cout <<"ENTER ANSWER FOR THE QUESTION" ;
        gotoxy(14,10) ;
        gets(ans1) ;
        strupr(ans1) ;
        if (ans1[0] == '0')
            return ;
        if (strlen(ans1) > 49)
        {
            valid = 0 ;
            sound(500) ;
            delay(100) ;
            nosound() ;
            gotoxy(1,25) ;    clreol() ;
            gotoxy(1,24) ;
            cout <<"LENGTH SHOULD NOT GREATER THAN 49" ;
            gotoxy(1,25) ;
            cout <<"Press any key to continue..." ;
            getch() ;
            gotoxy(1,24) ;    clreol() ;
            gotoxy(1,25) ;    clreol() ;
            gotoxy(14,10) ; clreol() ;
        }
    } while ( !valid ) ;
    do
    {
        line.box(1,1,79,23,218) ;
        valid = 1 ;
        gotoxy(1,25) ;    clreol() ;
        gotoxy(72,25) ;
        cout <<"<0>=EXIT" ;
        gotoxy(3,25) ;
        cout <<"ENTER ANSWER FOR THE QUESTION" ;
        gotoxy(14,12) ;
        gets(ans2) ;
        strupr(ans2) ;
        if (ans2[0] == '0')
            return ;
        if (strlen(ans2) > 49)
        {
            valid = 0 ;
            sound(500) ;
            delay(100) ;
            nosound() ;
            gotoxy(1,25) ;    clreol() ;
            gotoxy(1,24) ;
            cout <<"LENGTH SHOULD NOT GREATER THAN 49" ;
            gotoxy(1,25) ;
            cout <<"Press any key to continue..." ;
            getch() ;
            gotoxy(1,24) ;    clreol() ;
            gotoxy(1,25) ;    clreol() ;
            gotoxy(14,12) ; clreol() ;
        }
    } while ( !valid ) ;
    do
    {
        line.box(1,1,79,23,218) ;
        valid = 1 ;
        gotoxy(1,25) ;    clreol() ;
        gotoxy(72,25) ;
        cout <<"<0>=EXIT" ;
        gotoxy(3,25) ;
        cout <<"ENTER ANSWER FOR THE QUESTION" ;
        gotoxy(14,14) ;
        gets(ans3) ;
        strupr(ans3) ;
        if (ans3[0] == '0')
            return ;
        if (strlen(ans3) > 49)
        {
            valid = 0 ;
            sound(500) ;
            delay(100) ;
            nosound() ;
            gotoxy(1,25) ;    clreol() ;
            gotoxy(1,24) ;
            cout <<"LENGTH SHOULD NOT GREATER THAN 49" ;
            gotoxy(1,25) ;
            cout <<"Press any key to continue..." ;
            getch() ;
            gotoxy(1,24) ;    clreol() ;
            gotoxy(1,25) ;    clreol() ;
            gotoxy(14,14) ; clreol() ;
        }
    } while ( !valid ) ;
    do
    {
        line.box(1,1,79,23,218) ;
        valid = 1 ;
        gotoxy(1,25) ;    clreol() ;
        gotoxy(72,25) ;
        cout <<"<0>=EXIT" ;
        gotoxy(3,25) ;
        cout <<"ENTER CORRECT SOLUTION FOR THE QUESTION (1/2/3)" ;
        gotoxy(14,16) ;
        sol = getche() ;
        if (sol == '0')
            return ;
        if (sol != '1' && sol != '2' && sol != '3')
        {
            valid = 0 ;
            sound(500) ;
            delay(100) ;
            nosound() ;
            gotoxy(14,16) ; clreol() ;
        }
    } while ( !valid ) ;
    gotoxy(1,25) ;    clreol() ;
    gotoxy(1,24) ;  clreol() ;
    gotoxy(72,25) ;
    cout <<"<0>=EXIT" ;
    gotoxy(3,19) ;
    cout <<"Do you want to save the record (y/n) : " ;
    do
    {
        line.box(1,1,79,23,218) ;
        valid = 1 ;
        gotoxy(42,19) ;
        ch = getche() ;
        ch = toupper(ch) ;
        if (ch == '0')
            return ;
        if (ch != 'Y' && ch != 'N')
        {
            valid = 0 ;
            sound(500) ;
            delay(100) ;
            nosound() ;
            gotoxy(42,19) ; clreol() ;
        }
    } while ( !valid ) ;
    if (ch == 'Y')
    {
        ques_no = t_ques_no ;
        fstream file ;
        file.open(filename, ios::app ) ;
        file.write((char *) this, sizeof(quiz)) ;
        file.close() ;
        t_ques_no++ ;
    }
    gotoxy(72,25) ;
    cout <<"<0>=EXIT" ;
    gotoxy(3,21) ;
    cout <<"Do you want to add more questions (y/n) : " ;
    do
    {
        line.box(1,1,79,23,218) ;
        valid = 1 ;
        gotoxy(45,21) ;
        ch = getche() ;
        ch = toupper(ch) ;
        if (ch == '0')
            return ;
        if (ch != 'Y' && ch != 'N')
        {
            valid = 0 ;
            sound(500) ;
            delay(100) ;
            nosound() ;
            gotoxy(45,21) ; clreol() ;
        }
    } while ( !valid ) ;
   } while (ch == 'Y') ;
}

//**********************************************************
//    CLASS NAME    : quiz
//    FUNCTION NAME : found_record
//    DETAILS       : IT SEARCH THE GIVEN RECORDS IN THE
//                   GIVEN FILE AND RETURN 0 IF NOT FOUND
//**********************************************************

int  quiz :: found_record(char filename[13], int t_ques_no)
{
   fstream file ;
   file.open(filename, ios::in) ;
   file.seekg(0,ios::beg) ;
   int found=0 ;
   while (file.read((char *) this, sizeof(quiz)))
   {
    if (t_ques_no == ques_no)
    {
        found++ ;
        break ;
    }
   }
   file.close() ;
   return found ;
}
//**********************************************************
//    CLASS NAME    : quiz
//    FUNCTION NAME : display_record
//    DETAILS       : IT DISPLAY THE RECORD FOR THE GIVEN
//                   QUESTION NO. FROM THE GIVEN FILE
//**********************************************************

void quiz :: display_record(char filename[13], int t_ques_no)
{
   fstream file ;
   file.open(filename, ios::in) ;
   file.seekg(0,ios::beg) ;
   while (file.read((char *) this, sizeof(quiz)))
   {
    if (t_ques_no == ques_no)
    {
        gotoxy(3,3) ;
        cout <<"question # " <<t_ques_no ;
        gotoxy(3,7) ;
        cout <<"question : " <<ques ;
        gotoxy(3,8) ;
        cout <<"answer 1 : " <<ans1 ;
        gotoxy(3,9) ;
        cout <<"answer 2 : " <<ans2 ;
        gotoxy(3,10) ;
        cout <<"answer 3 : " <<ans3 ;
        break ;
    }
   }
   file.close() ;
}

//**********************************************************
//    CLASS NAME    : quiz
//    FUNCTION NAME : delete_record
//    DETAILS       : IT DELETE THE RECORD FOR THE GIVEN
//                      QUESTION NO. FROM THE GIVEN FILE
//**********************************************************

void quiz :: delete_record(char filename[13], int t_ques_no)
{
   fstream file ;
   file.open(filename, ios::in) ;
   fstream temp ;
   temp.open("temp.dat", ios::out) ;
   file.seekg(0,ios::beg) ;
   while (!file.eof())
   {
    file.read((char *) this, sizeof(quiz)) ;
    if ( file.eof() )
        break ;
    if (ques_no != t_ques_no)
        temp.write((char *) this, sizeof(quiz)) ;
   }
   file.close() ;
   temp.close() ;
   file.open(filename, ios::out) ;
   temp.open("temp.dat", ios::in) ;
   temp.seekg(0,ios::beg) ;
   t_ques_no = 1 ;
   while (!temp.eof())
   {
    temp.read((char *) this, sizeof(quiz)) ;
    ques_no = t_ques_no ;
    if (temp.eof())
        break ;
    file.write((char *) this, sizeof(quiz)) ;
    t_ques_no++ ;
   }
   file.close() ;
   temp.close() ;
}

//**********************************************************
//    CLASS NAME    : quiz
//    FUNCTION NAME : deletion
//    DETAILS       : IT GIVE THE QUESTION NO. TO DELETE
//                   RECORD FROM THE GIVEN FILE
//**********************************************************
void quiz :: deletion(char filename[13])
{
   lines line ;
   clrscr() ;
   int valid ;
   int t_ques_no=0, t;
   char t1_ques_no[5] ;
   char ch ;
   line.box(1,1,79,23,218) ;
   gotoxy(72,25) ;
   cout <<"<0>=EXIT" ;
   gotoxy(3,3) ;
   cout <<"Enter question no. to be deleted : " ;
   do
   {
    gotoxy(38,3) ;
    gets(t1_ques_no) ;
   } while (strlen(t1_ques_no) == 0) ;
   t = atoi(t1_ques_no) ;
   t_ques_no = t ;
   if (t1_ques_no[0] == '0')
    return ;
   if (!found_record(filename,t_ques_no))
   {
    sound(500) ;
    delay(100) ;
    nosound() ;
    gotoxy(3,15) ;
    cout <<"question not found" ;
    line.line_hor(1,79,24,196) ;
    gotoxy(1,25) ;
    cout <<"Press any key to continue..." ;
    getch() ;
    return ;
   }
   clrscr() ;
   line.box(1,1,79,23,218) ;
   display_record(filename,t_ques_no) ;
   gotoxy(3,12) ;
   cout <<"Do you want to delete this Record (y/n) : " ;
   do
   {
    valid = 1 ;
    gotoxy(45,12) ;
    ch = getche() ;
    ch = toupper(ch) ;
    if (ch != 'Y' && ch != 'N')
    {
        valid = 0 ;
        sound(500) ;
        delay(100) ;
        nosound() ;
        gotoxy(45,10) ; clreol() ;
    }
   } while (!valid ) ;
   if (ch == 'N')
    return ;
   gotoxy(1,25) ;
   cout <<"Wait..." ;
   delete_record(filename,t_ques_no) ;
   clrscr() ;
   sound(500) ;
   delay(100) ;
   nosound() ;
   gotoxy(3,14) ;
   cout <<"Record Deleted" ;
   line.line_hor(1,79,24,196) ;
   gotoxy(1,25) ;
   cout <<"Press any key to continue...." ;
   getch() ;
}
//**********************************************************
//    CLASS NAME    : quiz
//    FUNCTION NAME : modify_record
//    DETAILS       : IT MODIFY THE RECORD FOR THE GIVEN
//                      QUESTION NO. FROM THE GIVEN FILE
//**********************************************************

void quiz :: modify_record(char filename[13], int t_ques_no)
{
   lines line ;
   int valid, modified=0 ;
   char ch ;
   line.line_hor(2,78,12,196) ;
   line.box(1,1,79,23,218) ;
   gotoxy(3,14) ;
   cout <<"QUESTION # " <<t_ques_no ;
   gotoxy(3,16) ;
   cout <<"QUESTION : " ;
   gotoxy(3,17) ;
   cout <<"ANSWER 1 : " ;
   gotoxy(3,18) ;
   cout <<"ANSWER 2 : " ;
   gotoxy(3,19) ;
   cout <<"ANSWER 3 : " ;
   gotoxy(3,20) ;
   cout <<"SOLUTION : " ;
   gotoxy(1,25) ;    clreol() ;
   line.line_hor(1,79,23,196) ;
   gotoxy(14,16) ;
   cout <<"Change (y/n)  " ;
   do
   {
    line.box(1,1,79,23,218) ;
    valid = 1 ;
    gotoxy(28,16) ;
    ch = getche() ;
    ch = toupper(ch) ;
    if (ch != 'Y' && ch != 'N')
    {
        valid = 0 ;
        sound(500) ;
        delay(100) ;
        nosound() ;
        gotoxy(28,16) ; clreol() ;
    }
   } while (!valid) ;
   valid = 0 ;
   while (!valid && ch == 'Y')
   {
    line.box(1,1,79,23,218) ;
    modified = 1 ;
    valid = 1 ;
    gotoxy(14,16) ; clreol() ;
    gotoxy(72,25) ;
    cout <<"<0>=EXIT" ;
    gotoxy(3,25) ;
    cout <<"ENTER QUESTION" ;
    gotoxy(14,16) ;
    gets(ques) ;
    strupr(ques) ;
    if (ques[0] == '0')
        return ;
    if (strlen(ques) >159 || strlen(ques) == 0)
    {
        valid = 0 ;
        sound(500) ;
        delay(100) ;
        nosound() ;
        gotoxy(1,25) ;    clreol() ;
        gotoxy(1,24) ;
        cout <<"LENGTH SHOULD NOT BLANK OR GREATER THAN 159" ;
        gotoxy(1,25) ;
        cout <<"Press any key to continue..." ;
        getch() ;
        gotoxy(1,24) ;    clreol() ;
        gotoxy(1,25) ;    clreol() ;
        gotoxy(14,16) ; clreol() ;
    }
   }
   gotoxy(1,25) ;    clreol() ;
   gotoxy(14,17) ;
   cout <<"Change (y/n)  " ;
   do
   {
    line.box(1,1,79,23,218) ;
    valid = 1 ;
    gotoxy(28,17) ;
    ch = getche() ;
    ch = toupper(ch) ;
    if (ch != 'Y' && ch != 'N')
    {
        valid = 0 ;
        sound(500) ;
        delay(100) ;
        nosound() ;
        gotoxy(28,17) ; clreol() ;
    }
   } while (!valid) ;
   valid = 0 ;
   while (!valid && ch == 'Y')
   {
    line.box(1,1,79,23,218) ;
    modified = 1 ;
    valid = 1 ;
    gotoxy(13,17) ; clreol() ;
    gotoxy(72,25) ;
    cout <<"<0>=EXIT" ;
    gotoxy(3,25) ;
    cout <<"ENTER ANSWER FOR THE QUESTION" ;
    gotoxy(14,17) ;
    gets(ans1) ;
    strupr(ans1) ;
    if (ans1[0] == '0')
        return ;
    if (strlen(ans1) > 49)
    {
        valid = 0 ;
        sound(500) ;
        delay(100) ;
        nosound() ;
        gotoxy(1,25) ;    clreol() ;
        gotoxy(1,24) ;
        cout <<"LENGTH SHOULD NOT GREATER THAN 49" ;
        gotoxy(1,25) ;
        cout <<"Press any key to continue..." ;
        getch() ;
        gotoxy(1,24) ;    clreol() ;
        gotoxy(1,25) ;    clreol() ;
        gotoxy(14,17) ; clreol() ;
    }
   }
   gotoxy(1,25) ;    clreol() ;
   gotoxy(14,18) ;
   cout <<"Change (y/n)  " ;
   do
   {
    line.box(1,1,79,23,218) ;
    valid = 1 ;
    gotoxy(28,18) ;
    ch = getche() ;
    ch = toupper(ch) ;
    if (ch != 'Y' && ch != 'N')
    {
        valid = 0 ;
        sound(500) ;
        delay(100) ;
        nosound() ;
        gotoxy(28,18) ; clreol() ;
    }
   } while (!valid) ;
   valid = 0 ;
   while (!valid && ch == 'Y')
   {
    line.box(1,1,79,23,218) ;
    modified = 1 ;
    valid = 1 ;
    gotoxy(14,18) ; clreol() ;
    gotoxy(72,25) ;
    cout <<"<0>=EXIT" ;
    gotoxy(3,25) ;
    cout <<"ENTER ANSWER FOR THE QUESTION" ;
    gotoxy(14,18) ;
    gets(ans2) ;
    strupr(ans2) ;
    if (ans2[0] == '0')
        return ;
    if (strlen(ans2) > 49)
    {
        valid = 0 ;
        sound(500) ;
        delay(100) ;
        nosound() ;
        gotoxy(1,25) ;    clreol() ;
        gotoxy(1,24) ;
        cout <<"LENGTH SHOULD NOT GREATER THAN 49" ;
        gotoxy(1,25) ;
        cout <<"Press any key to continue..." ;
        getch() ;
        gotoxy(1,24) ;    clreol() ;
        gotoxy(1,25) ;    clreol() ;
        gotoxy(14,18) ; clreol() ;
    }
   }
   gotoxy(1,25) ;    clreol() ;
   gotoxy(14,19) ;
   cout <<"Change (y/n)  " ;
   do
   {
    line.box(1,1,79,23,218) ;
    valid = 1 ;
    gotoxy(28,19) ;
    ch = getche() ;
    ch = toupper(ch) ;
    if (ch != 'Y' && ch != 'N')
    {
        valid = 0 ;
        sound(500) ;
        delay(100) ;
        nosound() ;
        gotoxy(28,19) ; clreol() ;
    }
   } while (!valid) ;
   valid = 0 ;
   while (!valid && ch == 'Y')
   {
    line.box(1,1,79,23,218) ;
    modified = 1 ;
    valid = 1 ;
    gotoxy(14,19) ; clreol() ;
    gotoxy(72,25) ;
    cout <<"<0>=EXIT" ;
    gotoxy(3,25) ;
    cout <<"ENTER ANSWER FOR THE QUESTION" ;
    gotoxy(14,19) ;
    gets(ans3) ;
    strupr(ans3) ;
    if (ans3[0] == '0')
        return ;
    if (strlen(ans3) > 49)
    {
        valid = 0 ;
        sound(500) ;
        delay(100) ;
        nosound() ;
        gotoxy(1,25) ;    clreol() ;
        gotoxy(1,24) ;
        cout <<"LENGTH SHOULD NOT GREATER THAN 49" ;
        gotoxy(1,25) ;
        cout <<"Press any key to continue..." ;
        getch() ;
        gotoxy(1,24) ;    clreol() ;
        gotoxy(1,25) ;    clreol() ;
        gotoxy(14,19) ; clreol() ;
    }
   }
   if (!modified)
    return ;
   do
   {
    line.box(1,1,79,23,218) ;
    gotoxy(1,25) ;    clreol() ;
    valid = 1 ;
    gotoxy(72,25) ;
    cout <<"<0>=EXIT" ;
    gotoxy(3,25) ;
    cout <<"ENTER CORRECT SOLUTION FOR THE QUESTION (1/2/3)" ;
    gotoxy(14,20) ;
    sol = getche() ;
    if (sol == '0')
        return ;
    if (sol != '1' && sol != '2' && sol != '3')
    {
        valid = 0 ;
        sound(500) ;
        delay(100) ;
        nosound() ;
        gotoxy(14,20) ; clreol() ;
    }
   } while (!valid) ;
   gotoxy(1,25) ; clreol() ;
   gotoxy(1,24) ; clreol() ;
   gotoxy(1,22) ;
   cout <<"Do you want to save the record (y/n)  : " ;
   do
   {
    line.box(1,1,79,23,218) ;
    valid = 1 ;
    gotoxy(41,22) ;
    ch = getche() ;
    ch = toupper(ch) ;
    if (ch != 'Y' && ch != 'N')
    {
        valid = 0 ;
        sound(500) ;
        delay(100) ;
        nosound() ;
        gotoxy(41,22) ; clreol() ;
    }
   } while ( !valid ) ;
   if (ch == 'N')
    return ;
   fstream file ;
   file.open(filename, ios::out | ios::ate) ;
   int recno ;
   recno = t_ques_no ;
   int location ;
   location = (recno-1) * sizeof(quiz) ;
   file.seekp(location) ;
   file.write((char *) this, sizeof(quiz)) ;
   file.close() ;
   clrscr() ;
   sound(500) ;
   delay(100) ;
   nosound() ;
   gotoxy(1,14) ;
   cout <<"Record Modified" ;
   line.line_hor(1,79,24,196) ;
   gotoxy(1,25) ;
   cout <<"Press any key to continue..." ;
   getch() ;
}

//**********************************************************
//    CLASS NAME    : quiz
//    FUNCTION NAME : modify
//    DETAILS       : IT GIVE THE QUESTION NO. TO MODIFY
//                      RECORD FROM THE GIVEN FILE
//**********************************************************

void quiz :: modify(char filename[13])
{
   lines line ;
   clrscr() ;
   int valid ;
   int t_ques_no=0, t;
   char t1_ques_no[5] ;
   char ch ;
   line.box(1,1,79,23,218) ;
   gotoxy(72,25) ;
   cout <<"<0>=EXIT" ;
   gotoxy(3,3) ;
   cout <<"Enter question no. to be modify  : " ;
   do
   {
    gotoxy(38,3) ;
    gets(t1_ques_no) ;
   } while (strlen(t1_ques_no) == 0) ;
   t = atoi(t1_ques_no) ;
   t_ques_no = t ;
   if (t1_ques_no[0] == '0')
    return ;
   if (!found_record(filename,t_ques_no))
   {
    sound(500) ;
    delay(100) ;
    nosound() ;
    gotoxy(3,15) ;
    cout <<"question not found" ;
    line.line_hor(2,78,24,196) ;
    gotoxy(1,25) ;
    cout <<"Press any key to continue..." ;
    getch() ;
    return ;
   }
   clrscr() ;
   display_record(filename,t_ques_no) ;
   gotoxy(3,12) ;
   cout <<"Do you want to modify this Record (y/n) : " ;
   do
   {
    valid = 1 ;
    gotoxy(45,12) ;
    ch = getche() ;
    ch = toupper(ch) ;
    if (ch != 'Y' && ch != 'N')
    {
        valid = 0 ;
        sound(500) ;
        delay(100) ;
        nosound() ;
        gotoxy(45,10) ; clreol() ;
    }
   } while (!valid ) ;
   if (ch == 'N')
    return ;
   modify_record(filename,t_ques_no) ;
}

//**********************************************************
//    CLASS NAME    : quiz
//    FUNCTION NAME : display_score
//    DETAILS       : IT DISPLAY THE SCORE FOR THE GIVEN
//                      PLAYER'S NAME
//**********************************************************

void quiz :: display_score(char name[20], int played, int correct)
{
   clrscr() ;
   lines line ;
   line.box(1,1,39,25,218) ;
   line.box(2,2,38,24,219) ;
   textbackground(WHITE) ;
   textcolor(BLACK+BLINK) ;
   gotoxy(5,4) ;
   cprintf("                               ") ;
   gotoxy(9,4) ;
   cprintf("S C O R E   B O A R D") ;
   textbackground(BLACK) ;
   textcolor(LIGHTGRAY) ;
   gotoxy(5,7) ;
   cout <<"Player's Name : " <<name ;
   gotoxy(5,9) ;
   cout <<"questions Attempted : " <<played ;
   gotoxy(5,11) ;
   cout <<"Correct answer      : " <<correct ;
   gotoxy(5,13) ;
   cout <<"Wrong answer        : " <<played-correct ;
   int score ;
   score = correct * 10 ;
   gotoxy(5,16) ;
   cout <<"Score  : " <<score ;
   int tplayed ;
   tplayed = played * 10 ;
   float percentage ;
   percentage = ((score*100)/tplayed) ;
   gotoxy(5,18) ;
   cout <<"Percentage : " <<percentage ;
   getch() ;
}

//**********************************************************
//    CLASS NAME    : quiz
//    FUNCTION NAME : play
//    DETAILS       : IT CREATES SCREEN FOR PLAYING QUIZ
//                      TO THE PLAYER FOR THE GIVEN FILE NAME
//                      AND KEEP SCORE.
//**********************************************************

void quiz :: play(char filename[13])
{
   clrscr() ;
   int valid ;
   lines line ;
   char name[20] ;
   gotoxy(3,3) ;
   cout <<"Enter your name : " ;
   do
   {
    line.box(1,1,39,25,219) ;
    valid = 1 ;
    gotoxy(30,24) ;
    cout <<"<0>=EXIT" ;
    gotoxy(21,3) ;
    gets(name) ;
    strupr(name) ;
    if (name[0] == '0')
        return ;
    if (strlen(name) > 18)
    {
        valid = 0 ;
        sound(500) ;
        delay(100) ;
        nosound() ;
        gotoxy(30,24) ;
        cout <<"        " ;
        gotoxy(3,23) ;
        cout <<"LENGTH SHOULD NOT GREATER THAN 18" ;
        gotoxy(3,24) ;
        cout <<"Press any key to continue..." ;
        getch() ;
        gotoxy(3,23) ;
        cout <<"                                  " ;
        gotoxy(3,24) ;
        cout <<"                             " ;
        gotoxy(21,3) ;
        cout <<"                  " ;
    }
   } while ( !valid ) ;
   char t_sol, ch ;
   int  correct=0, played=0 ;
   fstream file ;
   file.open(filename,ios::in) ;
   file.seekg(0,ios::beg) ;
   while (file.read((char *) this, sizeof(quiz)))
   {
    clrscr() ;
    line.box(1,1,39,25,219) ;
    gotoxy(25,3) ;
    cout <<"SCORE:" <<correct*10 ;
    valid = 1 ;
    gotoxy(28,24) ;
    cout <<"<ESC>=Exit" ;
    gotoxy(3,4) ;
    cout <<"question # " <<ques_no ;
    gotoxy(3,6) ;
    cout <<"question : " <<ques ;
    gotoxy(3,10) ;
    cout <<"answer 1 : " <<ans1 ;
    gotoxy(3,11) ;
    cout <<"answer 2 : " <<ans2 ;
    gotoxy(3,12) ;
    cout <<"answer 3 : " <<ans3 ;
    gotoxy(3,14) ;
    cout <<"Enter correct solution : " ;
    int i=0, j=0, time=10 ;
    do
    {
        valid = 1 ;
        gotoxy(3,21) ;
        cout <<"Time : " <<time ;
        gotoxy(28,12) ;
        do
        {
            delay(1) ;
            i++ ;
            j++ ;
            if (j == 600)
            {
                j = 0 ;
                time-- ;
                gotoxy(11,21) ;
                cout <<" " ;
                gotoxy(10,21) ;
                cout <<time ;
                gotoxy(28,14) ;
            }
        } while (!kbhit() && i<6000) ;
        if (i >= 6000)
        {
            played++ ;
            sound(500) ;
            delay(100) ;
            nosound() ;
            gotoxy(13,16) ;
            cout <<"Sorry Time up!" ;
            gotoxy(1,1) ;
            getch() ;
            if (played)
                display_score(name,played,correct) ;
            return ;
        }
        gotoxy(3,21) ;
        cout <<"             " ;
        gotoxy(28,12) ;
        t_sol = getche() ;
        if (t_sol == 27)
        {
            if (played)
                display_score(name,played,correct) ;
            return ;
        }
        if (t_sol != '1' && t_sol != '2' && t_sol != '3')
        {
            valid = 0 ;
            sound(500) ;
            delay(100) ;
            nosound() ;
            gotoxy(28,12) ;
            cout <<"  " ;
        }
    } while (!valid) ;
    played++ ;
    if (t_sol != sol)
    {
        sound(500) ;
        delay(100) ;
        nosound() ;
        gotoxy(14,16) ;
        cout <<"wrong answer" ;
        gotoxy(13,17) ;
        cout <<"Correct answer : " <<sol ;
        gotoxy(1,1) ;
        ch = getch() ;
        gotoxy(14,15) ;
        cout <<"            " ;
        gotoxy(13,16) ;
        cout <<"                    " ;
        gotoxy(3,24) ;
        cout <<"                                    " ;
    }
    else
    {
        correct++ ;
        sound(500) ;
        delay(100) ;
        nosound() ;
        gotoxy(16,16) ;
        cout <<"GOOD ! CORRECT ANSWER" ;
        gotoxy(25,3) ;
        cout <<"SCORE:" <<correct*10 ;
        gotoxy(1,1) ;
        ch = getch() ;
    }
    if (ch == 27)
    {
        display_score(name,played,correct) ;
        return ;
    }
   }
   gotoxy(3,22) ;
   cout <<"No more questions available" ;
   getch() ;
   if (!played)
    return ;
   display_score(name,played,correct) ;
}

//**********************************************************
//    FUNCTION NAME : main
//    DETAILS       : IT CALLS THE START FUNCTION AND
//                   MENU FUNCTION.
//**********************************************************

void main(void)
{
   menu m ;
   m.start() ;
   m.main_menu() ;
}



Antony Ajay's Avatar

Blazing goIITian

Joined: 4 Dec 2007
Posts: 356
18 Feb 2008 13:18:14 IST
3 people liked this

/*Program to print the output A
                      AA
                      AAA
                      AAAA*/
#include<iostream.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<=4;i++)
{
    cout<<"\n";
    for(j=1;j<=i;j++)
    cout<<"A";
}
getch();
}
Antony Ajay's Avatar

Blazing goIITian

Joined: 4 Dec 2007
Posts: 356
18 Feb 2008 13:18:38 IST
1 people liked this

    /*Program to search for a given character*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
char sent[100],ch;
int flag=0;
cout<<"Enter any sentence\n";
gets(sent);
cout<<"Enter the character to be searched\n";
ch=getchar();
for(int i=0;sent[i]!='\0';i++)
{
    if(sent[i]==ch)
    flag=1;
    break;
}
if(flag==1)
cout<<"The character "<<ch<<"  is present in the sentence";
else
cout<<"The character "<<ch<<" is not present in the sentence";
getch();
}

Antony Ajay's Avatar

Blazing goIITian

Joined: 4 Dec 2007
Posts: 356
18 Feb 2008 13:19:26 IST
1 people liked this

    /*Program to print the series 1+2+3.....n*/
#include<iostream.h>
#include<conio.h>
void main()
{
int n;
long int sum=0;
cout<<"1+2+3.....n\n";
cout<<"Enter the value till which you want to calculate the sum of"
    <<"of the series(n)\n";
cin>>n;
for(int i=0;i<=n;++i)
{
    sum=sum+i;
}
cout<<"The sum the the series is "<<sum;
getch();
}
Antony Ajay's Avatar

Blazing goIITian

Joined: 4 Dec 2007
Posts: 356
18 Feb 2008 13:19:42 IST
1 people liked this

/*Program to print the series A
                      AB
                      ABC
                      ABCD*/
#include<iostream.h>
#include<conio.h>
void main()
{
char ans='A';
clrscr();
for(int i=1;i<5;++i)
{
    cout<<"\n";
    for(int j=1;j<i;++j)
    {
    ans=ans+1;
    cout<<ans;
    }
}
getch();
}
Antony Ajay's Avatar

Blazing goIITian

Joined: 4 Dec 2007
Posts: 356
18 Feb 2008 13:20:00 IST
1 people liked this

#include<iostream.h>
#include<conio.h>
void main()
{
int sales[10];
long total=0,avg=0;
clrscr();
cout<<"Enter the sales for ten days";
for(int i=0;i<10;i++)
{
    cin>>sales[i];
    total=total+sales[i];
    avg=total/10;
}
cout<<total<<"\t"<<avg;
getch();
}

Antony Ajay's Avatar

Blazing goIITian

Joined: 4 Dec 2007
Posts: 356
18 Feb 2008 13:20:18 IST
1 people liked this

        /*Program to delete a substring*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
char str[50];
int p,del,j,len;
clrscr();
cout<<"Enter a sentence\n";
gets(str);
for(len=0;str[len]!='\0';++len);
cout<<"Enter the starting position of the substring\n";
cin>>p;
cout<<"Enter the final position of characters to be deleted";
cin>>del;
for(j=p;j<=del;++j)
{
     str[len-1]=str[len-1]-str[j];
}
for(len=0;str[len]!='\0';++len)
cout<<str[len-1];
getch();
}



Quick Reply


Reply

Some HTML allowed.
Keep your comments above the belt or risk having them deleted.
Signup for a avatar to have your pictures show up by your comment
If Members see a thread that violates the Posting Rules, bring it to the attention of the Moderator Team
Free Sign Up!

Preparing for IIT-JEE ?

Arihant Revision Package for IIT JEE - Books, Practice Tests + Rank Predictor


@ INR 1,995/-

For Quick Info

Name

Mobile No.

Find Posts by Topics

Physics.

Topics

Mathematics.

Chemistry.

Biology

Parents

Board

Fun Zone

Sponsored Ads