C Program to draw SWASTIKA on center on the screen with blink effect


 #include<stdio.h> 

#include<conio.h> 

void main()

{

int i=0;

clrscr();

textcolor(RED+BLINK);

for(i=8;i<25;i++)

{

gotoxy(20,i); cprintf(“*”);

gotoxy(40,i); cprintf(“*”);

if(i<23)

gotoxy(20+2,i);

cprintf(“*”);

gotoxy(40+2,i+2); 

cprintf(“*”);

}

}


for(i=23;i<=40;i++)

{

if(i<39)

{

gotoxy(40,i);

cprintf(“*”);

gotoxy(60,i+2); 

cprintf(“*”);


}


gotoxy(40+2,i); 

cprintf(“*”);

gotoxy(60+2,i); c

printf(“*”);

}

for(i=20;i<42;i++)

{

gotoxy(i,25);

cprintf(“*”);

gotoxy(i,40); 

cprintf(“*”);

if(i<40)

{

gotoxy(i+2,25-2);

cprintf(“*”);

gotoxy(i,40-2); cprintf(“*”);

}

}

for(i=40;i<62;i++) 

{

if(i<60)

{

gotoxy(i+2,10);

cprintf(“*”);

gotoxy(i,25);

cprintf(“*”);

}

gotoxy(i,10-2); 

cprintf(“*”);

gotoxy(i,25-2); 

cprintfr*”);

getch();

}


OUTPUT IN C



 

MOUSE POINTER IN C(USING GRAPHICS)


#include<dos.h>
#include<graphics.h>
#include<alloc.h>
#include<conio.h>
#include<stdio.h>
char *menu[]={“samosa”,”sambharwada”,”dahiwada”,”exit”};
union REGS i,o;
main()
{
int gd=DETECT,gm,choice=1,bill=0,width=0,i,count;
char **buffer;
initgraph(&gd,&gm,”c:\\tc\\bgi”);
if(initmouse()==0)
{
printf(“\n unable to initialise mouse…”);
exit();
}

count=sizeof(menu)/sizeof(char *);
settextstyle(TRIPLEX_FONT,0,3);
displaymenu(menu,count,100,100);

for(i=0;i<count;i++)
{
if(textwidth(menu[i])>width)
width=textwidth(menu[i]);
}
buffer=malloc(sizeof(menu));
savemenu(menu,buffer,width,count,100,100);

while(choice!=4)
{
choice=getresponse(menu,buffer,width,count,100,100);
gotoxy(50,15);
printf(“you selected%s”,menu[choice-1]);
}
displaymenu(char**menu,int count,int x1,int y1)
{
int i,h;
h=textheight(menu[0]);
for(i=0;i<count;i++)
{
outtexttxy(x1,y1+i*(h+5),menu[i]);
}
}

savemenu(char**menu,char**buffer,int width,int count,int x1,int y1)
{
int i,x2,yy1,yy2,area,h;
h=textheight(menu[0]);
for(i=0;i<count;i++)
{
x2=x1+width;
yy1=y1+i*(h+5);
yy2=y1+(i+1)*(h+5);
area=imagesize(x1,yy1,x2,yy2);
buffer[i]=malloc(area);
getimage(x1,yy1,x2,yy2,buffer[i]);
}
}

getresponse(char**menu,char**buffer,int width,int count,int x1,int y1)
{
int choice=1,prevchoice=0,x,y,x2,y2,button;
int in,i,h;
h=textheight(menu[0]);
y2=y1+count*(h+5);
x2=x1+width;
rectangle(x1-5,y1-5,x2+5,y2+5);

while(1)
{
getmousepos(&button,&x,&y);
if(x>=x1 &&x<=x2 && y>=y1 && y<=y2)
{
in=1;
for(i=1;i<=count;i++)
{
if(y<=y1+i*(h+5))
{
choice=i;
break;
}
}

if(prevchoice!=choice)
{
hidemouseptr();
highlight(buffer,choice,h,x1,y1);
if(prevchoice)
dehighlight(buffer,prevchoice,h,x1,y1);
prevchoice=choice;
showmouseptr();
}

if((button & 1)==1)
{

while((button & 1)==1)
getmousepos(&button,&x,&y);
if(x>=x1 && x<=x2 && y>=y1 && y<=y2)
return(choice);
}
}
else
{
if(in==1)
{
in=0;
prevchoice=0;
hidemouseptr();
dehighlight(buffer,choice,h,x1,y1);
showmouseptr();
}
}
}
}

highlight(char**menu,char**buffer,int width,int count,int x1,int y1)
{
putimage(x1,y1+(ch-1)*(h+5),buffer[ch-1],NOT_PUT);
}

dehighlight(char**menu,char**buffer,int width,int count,int x1,int y1)
{
putimage(x1,y1+(ch-1)*(h+5),buffer[ch-1],COPY_PUT);
}

initmouse()
{
i.x.ax=0;
int86(0x33,&i,&o);
return(o.x.ax);
}

showmouseptr()
{
i.x.ax=1;
int86(0x33,&i,&o);
}

hidemouseptr()
{
i.x.ax=2;
int86(0x33,&i,&o);
}

getmousepos(int*button,int*x,int*y)
{
i.x.ax=3;
int86(0x33,&i,&o);
*button=o.x.bx;
*x=o.x.cx;
*y=o.x.dx;
}
}
}

c program to draw a picture


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

void main(void)
{
    int   gd = DETECT,gm;
    int   x[10],y[10];
    int   x_center = 360, y_center = 180, rad = 100;
    int   i,j;

    initgraph(&gd,&gm,”c:\\tc\\bgi”);
    for ( i = 0; i < 10; i++ )
    {
       x[i] =  x_center + rad *  cos(36*i*3.14159/180);
       y[i] =  y_center + rad *  sin(36*i*3.14159/180);
    }
    for ( i = 0; i < 10; i++ )
       for ( j = 0; j < 10; j++ )
   line(x[i],y[i],x[j],y[j]);
    getch();           /* press any key return to TEXT mode */
    closegraph();
}

LIC DATABASE MANAGEMENT SYSTEM


//////*******************************************************\\\\\\
//////**** ¯     LIC DATABASE MANAGEMENT SOFTWARE     ®  ****\\\\\\
//////*******************************************************\\\\\\
//////Developed By :- Animesh Shaw                           \\\\\\
//////                Computer Science                       \\\\\\
//////                Narula Institute of Technology         \\\\\\
//////                Agrarpara                              \\\\\\
//////                Kolkata                                \\\\\\
//////e-mail:-  rana.animeshshaw73@gmail.com                  \\\\\\
//////         animeshshaw59@gmail.com                       \\\\\\
 
/*          HEADER FILES          */
#include<iostream .h>
#include<conio .h>
#include<string .h>
#include<dos .h>
#include<ctype .h>
#include<stdio .h>
#include<process .h>
#include<iomanip .h>
#include<math .h>
 
 
/*             STRUCTURE DEFINITIONS               */
 
struct address /* STRUCTURE FOR ADDRESS */
{
char hno[30];
char area[30];
char city[30];
char stat[30];
};
 
 
struct agn     /* STRUCTURE FOR AGENT DETAILS */
{
int code;
char nam[80];
int age;
address addagn;
int polsld;       //no. of policies sold
float sal;        //salary
char categ[50];   //category
}agnt[15];
 
 
struct cust    /* STRUCTURE FOR CUSTOMER DETAILS */
{
char nam[80];
int age;
address addcust;
char polbt[20];   //name of policy bought
float sal;        //salary
int code;
float polamt;
int polterm;
char mod_pay;
float sa_pt_pa;   //SA per thousand per annum
float prem;       //premium
}custm[15];
 
 
struct fback   /* STRUCTURE FOR FEEDBACK FORM */
{
int age;
char gndr;        //gender
char occp[20];    //occupation
float inc;        //income
char a[12];       //ratings
}fbk;
 
 
struct poldet  /* STRUCTURE FOR POLICY T&C */
{
char nam[20];
int minagemat;
int maxagemat;
int maxmatage;
int minpolt;
int maxpolt;
float minsumass;
char maxsumass[10];
char modeall[25];
float acci_ben;
float CI;
int femliv;
char agepro[40];
char nonmed_gen[5];
char nonmed_spe[5];
char termrideroptn[4];
char crtcalilnesridr[4];
float sa_pt_patrm1_ag1;//SA per thousand per annum
float sa_pt_patrm1_ag2;
float sa_pt_patrm2_ag1;
float sa_pt_patrm2_ag2;
};
 
/*         STORING POLICY DETAILS  */
 
poldet endow={"ENDOWMENT POLICY",12,65,75,5,55,50000.00,"No Limit","All",1.00,
               7.26,2,"Birth Certificate / Board Certificate","Yes","Yes",
               "Yes","Yes",72.00,73.35,35.80,40.00};
 
poldet monbak={"MONEY BACK POLICY",13,50,70,20,55,50000.00,"No Limit","All",
               2.00,6.57,2,"Birth Certificate / Board Certificate","Yes","Yes",
               "Yes","Yes",65.35,53.45,71.85,61.55};
 
poldet jeevkish={"JEEVAN KISHORE",0,12,45,15,35,50000.00,"40 Lacs","All",1.50,
               6.52,2,"Birth Certificate / Board Certificate","N.A.","N.A.",
               "No","No",49.15,29.25,49.15,29.25};
 
poldet jeevannd={"JEEVAN ANAND",18,65,75,5,57,100000.00,"No Limit",
                 "All Except Single",1.5,6.45,2,"Birth Certificate / Board Certificate",
                 "Yes","Yes","No","Yes",50.95,39.05,155.75,86.25};
 
poldet jeevsurbh={"JEEVAN SURABHI",14,50,70,15,25,50000.00,"No Limit","All",
                  1.00,6.11,2,"Birth Certificate / Board Certificate","Yes",
                  "Yes","No","No",108.80,91.30,123.00,112.80};
 
 
/*           FUNCTION PROTOTYPING     */
 
/* FUNCTION FOR DISPLAYING MAIN MENU */
 
void welcome();//display welcome page
void mainmen();//display main menu
 
 
/* CUSTOMER FUNCTIONS */
 
void cusmen();//display customer menu
void newpol();//display new policies
void tnccus(poldet pol);//display details of policies
void newcus(poldet pol);//new customer data input
float premcalc(cust custm,poldet pol);//premium calculation
void oldcus();//display old customer's previous policy details
void feed();//display feedback form
char feedval();//input & test the ratings of feedback form
 
 
/* AGENT FUNCTIONS */
 
void agnmen();//display agent menu
void newagn();//new agent data input
void oldagn();//old agent details
void tncagn();//display terms & conditions for agents
 
 
/* MAIN FUNCTION */
void main()
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout< <setprecision(2);
 
textbackground(BLACK);
textcolor(CYAN+BLINK);
 
clrscr();
delay(1500);
 
gotoxy(25,20);
puts("LOADING");
delay(2000);
 
for(int i=0;i&lt;11;i++)
         {
         textcolor(CYAN);
         textbackground(BLACK);
         clrscr();
         gotoxy(25,20);
         puts("LOADING");
 
         gotoxy(25,22);
         for(int j=0;j<i;j++)
         cout<<"ÛÛ";
 
         for(int x=10-(i);x>0;x--)
         cout< <"  ";
 
         cout<<" "<<i<<"0%";
         if(i%2==0)
         delay(500);
         else
         delay(200);
         }
gotoxy(33,25);
puts("COMPLETE!!");
delay(500);
 
welcome();
}
 
 
/* WELCOME SCREEN */
void welcome()
{
clrscr();
 
for(int x=0;x&lt;80;x++)
{
         gotoxy(x,0);
         cout<<"";
         delay(5);
}
 
for(int y=0;y&lt;48;y++)
{
         gotoxy(0,y);
         cout<<"\n";
         delay(5);
}
 
for(x=79;x>0;x--)
{
         gotoxy(x,49);
         cout< <"";
         delay(5);
}
 
gotoxy(80,49);
cout<<"";
 
for(y;y>0;y--)
{
         gotoxy(80,y);
         cout< <"\n";
         delay(5);
}
 
gotoxy(10,10);
puts("*********************** W E L C O M E *********************** ");
gotoxy(18,16);
puts("L . I . C .  D A T A B A S E  S O F T W A R E");
gotoxy(38,22);
puts(" D E V E L O P E D  B Y : ");
gotoxy(38,26);
puts(" ANIMESH SHAW ");
gotoxy(38,28);
puts(" COMPUTER SCIENCE ");
gotoxy(38,30);
puts(" NARULA INSTITUTE OF TECHNOLOGY ");
gotoxy(38,32);
puts(" AGARPARA ");
gotoxy(38,34);
puts(" KOLKATA ");
gotoxy(38,40);
puts(" *** PRESS ANY KEY TO CONTINUE ***");
 
getch();
mainmen();
}
 
 
/* MAIN MENU */
void mainmen()
{
char a;
clrscr();
cout<<"\n";
 
for(int x=0;x&lt;80;x++)
{
         delay(5);
         cout<<"";
}
 
for(int y=1;y&lt;16;y++)
{
         delay(5);
         gotoxy(0,y);
         cout<<"\n";
}
 
gotoxy(25,5);
cout<<"WELCOME TO LIFE INSURANCE COMPANY";
gotoxy(25,6);
cout<<"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$";
gotoxy(36,9);
cout<<"L.I.C. MENU";
gotoxy(36,12);
cout<<"C=CUSTOMER";
gotoxy(36,14);
cout<<"A=AGENT";
gotoxy(36,16);
cout<<"X=EXIT";
 
cout<<"\n\n";
for(x=1;x&lt;80;x++)
{
         delay(5);
         cout<<"";
}
 
for(y=2;y&lt;19;y++)
{
         delay(5);
         gotoxy(80,y);
         cout<<"";
}
 
gotoxy(30,20);
cout<<"Please enter your choice : ";
x:a=getch();
switch(a)
         {
         case 'c':
         case 'C':cusmen();
                  break;
         case 'a':
         case 'A':agnmen();
                  break;
         case 'x':
         case 'X':feed();
                  break;
         default:goto x;
         }
}
 
 
/* CUSTOMER MENU */
void cusmen()
{
char b;
x:clrscr();
 
cout<<"\n";
for(int x=0;x&lt;80;x++)
{
         delay(5);
         cout<<"";
}
 
for(int y=1;y&lt;16;y++)
{
         delay(5);
         gotoxy(0,y);
         cout<<"\n";
}
 
gotoxy(36,5);
cout<<"CUSTOMER MENU";
gotoxy(36,6);
cout<<"$$$$$$$$$$$$$";
gotoxy(36,9);
cout<<"O=OLD CUSTOMER";
gotoxy(36,11);
cout<<"P=POLICIES";
gotoxy(36,13);
cout<<"B=BACK";
gotoxy(36,15);
cout<<"X=EXIT";
 
cout<<"\n\n";
for(x=0;x&lt;80;x++)
{
         delay(5);
         cout<<"";
}
 
for(y=2;y&lt;18;y++)
{
         gotoxy(80,y);
         delay(5);
         cout<<"";
}
 
gotoxy(30,19);
cout<<"Please enter your choice : ";
y:b=getch();
 
switch(b)
         {
         case 'o':
         case 'O':oldcus();
                  break;
         case 'p':
         case 'P':newpol();
                  break;
         case 'b':
         case 'B':mainmen();
                  break;
         case 'x':
         case 'X':feed();
                  break;
         default:goto y;
         }
}
 
 
/* NEW POLICY */
void newpol()
{
char inp;
clrscr();
 
cout<<"\n";
 
for(int x=0;x&lt;80;x++)
{
         delay(5);
         cout<<"";
}
 
for(int y=1;y&lt;17;y++)
{
         delay(5);
         gotoxy(0,y);
         cout<<"\n";
}
 
gotoxy(30,5);
cout<<"LIFE INSURANCE POLICIES";
gotoxy(30,6);
cout<<"$$$$$$$$$$$$$$$$$$$$$$$";
gotoxy(31,9);
cout<<"1. Endowment Policy";
gotoxy(31,11);
cout<<"2. Money Back Policy";
gotoxy(31,13);
cout<<"3. Jeevan Kishore";
gotoxy(31,15);
cout<<"4. Jeevan Anand";
gotoxy(31,17);
cout<<"5. Jeevan Surabhi";
 
cout<<"\n\n";
for(x=0;x&lt;80;x++)
{
         delay(5);
         cout<<"";
}
 
for(y=2;y&lt;19;y++)
{
         delay(5);
         gotoxy(80,y);
         cout<<"";
}
 
gotoxy(31,21);
cout<<"B=Back";
gotoxy(31,23);
cout<<"X=Exit";
gotoxy(31,25);
cout<<"Please enter your choice : ";
x:inp=getch();
 
switch(inp)
{
case '1':tnccus(endow);
 
case '2':tnccus(monbak);
 
case '3':tnccus(jeevkish);
 
case '4':tnccus(jeevannd);
 
case '5':tnccus(jeevsurbh);
 
case 'b':
case 'B':cusmen();
 
case 'x':
case 'X':exit(0);
 
default:goto x;
}
}
 
 
/* POLICY DETAILS */
void tnccus(poldet pol)
{
char in;
clrscr();
 
cout<<"\n";
for(int x=0;x&lt;80;x++)
{
         delay(5);
         cout<<"";
}
 
for(int y=1;y&lt;32;y++)
{
         delay(5);
         gotoxy(0,y);
         cout<<"\n";
}
 
gotoxy(25,5);
cout<<"TERMS & CONDITIONS FOR ";
puts(pol.nam);
gotoxy(12,8);
cout<<"¯ Min./Max. age at entry  : ";
cout<<pol.minagemat<<" / "<<pol.maxagemat;
gotoxy(12,10);
cout<<"¯ Max. maturity age       : "<<pol.maxmatage;
gotoxy(12,12);
cout<<"¯ Min./Max. policy term   : "<<pol.minpolt<<" / "<<pol.maxpolt;
gotoxy(12,14);
cout<<"¯ Min./Max. sum assured   : "<<pol.minsumass<<" / ";
puts(pol.maxsumass);
gotoxy(12,16);
cout<<"¯ Mode allowed            : ";
puts(pol.modeall);
gotoxy(12,18);
cout<<"¯ Accident Benefit        : "<<pol.acci_ben;
cout<<" per thousand S.A. per annum";
gotoxy(12,20);
cout<<"¯ Compound Interest       : "<<pol.CI;
gotoxy(12,22);
cout<<"¯ Female Lives            : "<<pol.femliv;
gotoxy(12,24);
cout<<"¯ Age Proof               : ";
puts(pol.agepro);
gotoxy(12,26);
cout<<"¯ Non Medical (General)   : ";
puts(pol.nonmed_gen);
gotoxy(12,28);
cout<<"¯ Non Medical (Special)   : ";
puts(pol.nonmed_spe);
gotoxy(12,30);
cout<<"¯ Term rider option           : ";
puts(pol.termrideroptn);
gotoxy(12,32);
cout<<"¯ Critical illness rider  : ";
puts(pol.crtcalilnesridr);
 
cout<<"\n";
for(x=0;x&lt;80;x++)
{
         delay(5);
         cout<<"";
}
 
for(y=2;y&lt;34;y++)
{
         delay(5);
         gotoxy(80,y);
         cout<<"";
}
 
gotoxy(12,36);
cout<<"Does this policy satisfy your needs?(Y/N) : ";
a:in=getch();
 
switch(in)
{
         case 'Y':
         case 'y':newcus(pol);
 
         case 'n':
         case 'N':newpol();
 
         default:goto a;
}
}
 
 
/* NEW POLICY FORM */
void newcus(poldet pol)
{
int j;
clrscr();
 
for(int i=0;i&lt;15;i++)
{
if(strcmp(custm[i].nam,"")==0)
         break;
}
 
gotoxy(28,3);
cout<<"POLICY FORM FOR ";
puts(pol.nam);
gotoxy(25,6);
cout<<"Please enter the following details : ";
gotoxy(25,8);
cout<<"¯ NAME : ";
gotoxy(25,10);
cout<<"¯ AGE : ";
gotoxy(25,12);
cout<<"¯ ADDRESS : ";
gotoxy(29,14);
cout<<"* HOUSE NO. : ";
gotoxy(29,16);
cout<<"* AREA : ";
gotoxy(29,18);
cout<<"* CITY : ";
gotoxy(29,20);
cout<<"* STATE : ";
gotoxy(25,22);
if(strcmp(pol.nam,"JEEVAN KISHORE"))
         cout<<"¯ SALARY : ";
gotoxy(25,24);
cout<<"¯ POLICY AMOUNT : ";
gotoxy(25,26);
cout<<"¯ MODE OF PAYMENT : ";
gotoxy(29,28);
cout<<"( Q=QUARTERLY, H=HALF YEARLY, Y=YEARLY)";
gotoxy(25,30);
cout<<"¯ POLICY TERM : ";
 
a:gotoxy(34,8);
gets(custm[i].nam);
if(strcmp(custm[i].nam,"")==0)
goto a;
 
b:gotoxy(33,10);
for(j=0;j&lt;20;j++)
         cout<<" ";
gotoxy(33,10);
cin>>custm[i].age;
if(custm[i].age<pol .minagemat||custm[i].age>pol.maxagemat)
{
         gotoxy(20,40);
         cout< <"Age must be between "<<pol.minagemat<<" to "<<pol.maxagemat<<" years";
         goto b;
}
else
{
         gotoxy(20,40);
         for(j=0;j&lt;34;j++)
         cout<<" ";
}
 
c:gotoxy(43,14);
gets(custm[i].addcust.hno);
if(strcmp(custm[i].addcust.hno,"")==0)
         goto c;
 
d:gotoxy(38,16);
gets(custm[i].addcust.area);
if(strcmp(custm[i].addcust.area,"")==0)
         goto d;
 
e:gotoxy(38,18);
gets(custm[i].addcust.city);
if(strcmp(custm[i].addcust.city,"")==0)
         goto e;
 
f:gotoxy(39,20);
gets(custm[i].addcust.stat);
if(strcmp(custm[i].nam,"")==0)
         goto f;
 
gotoxy(36,22);
if(strcmp(pol.nam,"JEEVAN KISHORE"))//check if the policy name
         cin>>custm[i].sal;          //is JEEVAN KISHORE
 
g:gotoxy(43,24);
for(j=0;j&lt;20;j++)
         cout< <" ";
gotoxy(43,24);
cin>>custm[i].polamt;
if(custm[i].polamt</pol><pol .minsumass)
{
         gotoxy(20,40);
         cout<<"Policy amount must be more than Rs. "<<pol.minsumass;
         goto g;
}
else
{
         gotoxy(20,40);
         for(j=0;j&lt;50;j++)
         cout<<" ";
}
 
gotoxy(45,26);
h:custm[i].mod_pay=getch();
switch(custm[i].mod_pay)
{
         case 'q':
         case 'Q':
         case 'h':
         case 'H':
         case 'y':
         case 'Y':custm[i].mod_pay=toupper(custm[i].mod_pay);
                  cout<<custm[i].mod_pay;
                  getch();
                  break;
         default:goto h;
}
 
k:custm[i].polterm=0;
gotoxy(41,30);
for(j=0;j&lt;15;j++)
         cout<<" ";
gotoxy(41,30);
cin>>custm[i].polterm;
if((custm[i].polterm</pol><pol .minpolt)||(custm[i].polterm>pol.maxpolt))
{
         gotoxy(20,40);
         cout< <"Policy term must be between "<<pol.minpolt;
         cout<<" to "<<pol.maxpolt<<" years";
         goto k;
}
else
{
         gotoxy(20,40);
         for(j=0;j&lt;34;j++)
         cout<<" ";
}
 
strcpy(custm[i].polbt,pol.nam);//copy the policy name to customer's details
 
custm[i].code=fabs((100*i)+89-(custm[i].age));//create unique code
 
custm[i].prem=premcalc(custm[i],pol);//calculate premium
 
clrscr();
gotoxy(30,3);
cout<<"Your details are : ";
gotoxy(25,6);
cout<<"¯ NAME : ";
puts(custm[i].nam);
gotoxy(25,8);
cout<<"¯ AGE : "<<custm[i].age;
gotoxy(25,10);
cout<<"¯ ADDRESS : ";
gotoxy(29,12);
cout<<"* HOUSE NO. : ";
puts(custm[i].addcust.hno);
gotoxy(29,14);
cout<<"* AREA : ";
puts(custm[i].addcust.area);
gotoxy(29,16);
cout<<"* CITY : ";
puts(custm[i].addcust.city);
gotoxy(29,18);
cout<<"* STATE : ";
puts(custm[i].addcust.stat);
gotoxy(25,20);
cout<<"¯ POLICY NAME : ";
puts(custm[i].polbt);
gotoxy(25,22);
if(strcmp(pol.nam,"JEEVAN KISHORE"))
         cout<<"¯ SALARY : Rs. "<<custm[i].sal;
gotoxy(25,24);
cout<<"¯ POLICY AMOUNT : Rs. "<<custm[i].polamt;
gotoxy(25,26);
cout<<"¯ POLICY TERM : "<<custm[i].polterm<<" years";
gotoxy(25,28);
cout<<"¯ MODE OF PAYMENT : ";
switch(custm[i].mod_pay)
{
case 'Y':cout<<"YEARLY";
          break;
case 'H':cout<<"HALF YEARLY";
          break;
case 'Q':cout<<"QUARTERLY";
}
gotoxy(25,30);
cout<<"¯ PREMIUM : Rs. "<<custm[i].prem<<" per annum";
gotoxy(25,32);
cout<<"¯ CUSTOMER CODE : "<<custm[i].code;
 
getch();
cusmen();
}
 
 
/* PREMIUM CALCULATION */
float premcalc(cust custm,poldet pol)
{
float a;
 
if(custm.age<(pol.minagemat+pol.maxagemat)/2)
{
         if(custm.polterm<=(pol.minpolt+pol.maxpolt)/2)
                 custm.sa_pt_pa=pol.sa_pt_patrm1_ag1;
         if(custm.polterm>(pol.minagemat+pol.maxagemat)/2)
                 custm.sa_pt_pa=pol.sa_pt_patrm2_ag1;
}
 
if(custm.age>=(pol.minagemat+pol.maxagemat)/2)
{
         if(custm.polterm< =(pol.minpolt+pol.maxpolt)/2)
                 custm.sa_pt_pa=pol.sa_pt_patrm1_ag2;
         if(custm.polterm>(pol.minpolt+pol.maxpolt)/2)
                 custm.sa_pt_pa=pol.sa_pt_patrm2_ag2;
}
 
if(custm.mod_pay=='h'||custm.mod_pay=='H')
         custm.sa_pt_pa*=0.985;
 
else if(custm.mod_pay=='y'||custm.mod_pay=='Y')
         custm.sa_pt_pa*=0.97;
 
if(custm.polamt>pol.minsumass&&custm.polamt< =(2*pol.minsumass))
         custm.sa_pt_pa-=1;
 
if(custm.polamt>(2*pol.minsumass))
         custm.sa_pt_pa-=2;
 
a=(custm.sa_pt_pa)*(custm.polamt)/1000;
 
return a;
}
 
 
/* OLD CUSTOMER'S DETAILS */
void oldcus()
{
int flag=0;
clrscr();
 
gotoxy(25,6);
cout< <"PLEASE ENTER CUSTOMER CODE : ";
int pn;
cin>>pn;
 
for(int i=0;i&lt;15;i++)
{
         if(pn==custm[i].code)//check the customer code
         {
                 flag=1;
                 gotoxy(25,10);
                 cout< <"¯ NAME : ";
                 puts(custm[i].nam);
                 gotoxy(25,12);
                 cout<<"¯ AGE : "<<custm[i].age;
                 gotoxy(25,14);
                 cout<<"¯ ADDRESS : ";
                 gotoxy(29,16);
                 cout<<"* HOUSE NO. : ";
                 puts(custm[i].addcust.hno);
                 gotoxy(29,18);
                 cout<<"* AREA : ";
                 puts(custm[i].addcust.area);
                 gotoxy(29,20);
                 cout<<"* CITY : ";
                 puts(custm[i].addcust.city);
                 gotoxy(29,22);
                 cout<<"* STATE : ";
                 puts(custm[i].addcust.stat);
                 gotoxy(25,24);
                 cout<<"¯ POLICY NAME : ";
                 puts(custm[i].polbt);
                 gotoxy(25,26);
                 cout<<"¯ SALARY : Rs. "<<custm[i].sal;
                 gotoxy(25,28);
                 cout<<"¯ POLICY AMOUNT : Rs. "<<custm[i].polamt;
                 gotoxy(25,30);
                 cout<<"¯ POLICY TERM : "<<custm[i].polterm<<" years";
                 gotoxy(25,32);
                 cout<<"¯ MODE OF PAYMENT : ";
                 switch(custm[i].mod_pay)
                 {
                          case 'Y':cout<<"YEARLY";
                                    break;
                          case 'H':cout<<"HALF YEARLY";
                                    break;
                          case 'Q':cout<<"QUARTERLY";
                 }
                 gotoxy(25,34);
                 cout<<"¯ PREMIUM : Rs. "<<custm[i].prem<<" per annum";
 
                 getch();
                 cusmen();
         }
}
 
if(flag==0)  //if customer is not found
{
         gotoxy(25,8);
         cout<<"SORRY, CUSTOMER NOT FOUND";
}
 
getch();
cusmen();
}
 
 
/* AGENT MENU */
void agnmen()
{
char b;
x:clrscr();
 
cout<<"\n";
for(int x=0;x&lt;80;x++)
{
         delay(5);
         cout<<"";
}
 
for(int y=1;y&lt;17;y++)
{
         delay(5);
         gotoxy(0,y);
         cout<<"\n";
}
 
gotoxy(36,5);
cout<<"AGENT MENU";
gotoxy(36,6);
cout<<"$$$$$$$$$$";
gotoxy(36,9);
cout<<"O=OLD AGENT";
gotoxy(36,11);
cout<<"N=NEW AGENT";
gotoxy(36,13);
cout<<"T=TERMS & CONDITIONS";
gotoxy(36,15);
cout<<"B=BACK";
gotoxy(36,17);
cout<<"X=EXIT";
 
cout<<"\n\n";
for(x=0;x&lt;80;x++)
{
         delay(5);
         cout<<"";
}
 
for(y=2;y&lt;19;y++)
{
         delay(5);
         gotoxy(80,y);
         cout<<"";
}
 
gotoxy(30,21);
cout<<"Please enter your choice : ";
y:b=getch();
 
switch(b)
         {
         case 'o':
         case 'O':oldagn();
                  break;
         case 'n':
         case 'N':newagn();
                  break;
         case 'T':
         case 't':tncagn();
                  goto x;
         case 'b':
         case 'B':mainmen();
                  break;
         case 'X':
         case 'x':exit(0);
                  break;
         default:goto y;
         }
}
 
 
/* NEW AGENT FORM */
void newagn()
{
int o;
clrscr();
 
for(int i=0;i&lt;15;i++)
         {
         if(strcmp(agnt[i].nam,"")==0)
                 break;
         }
 
gotoxy(34,3);
cout<<"NEW AGENT FORM";
gotoxy(25,6);
cout<<"Please enter the following details : ";
gotoxy(25,8);
cout<<"¯ NAME : ";
gotoxy(25,10);
cout<<"¯ AGE : ";
gotoxy(25,12);
cout<<"¯ ADDRESS : ";
gotoxy(29,14);
cout<<"* HOUSE NO. : ";
gotoxy(29,16);
cout<<"* AREA : ";
gotoxy(29,18);
cout<<"* CITY : ";
gotoxy(29,20);
cout<<"* STATE : ";
gotoxy(25,22);
cout<<"¯ SALARY : ";
gotoxy(25,24);
cout<<"¯ POLICIES SOLD : ";
 
x:gotoxy(34,8);
gets(agnt[i].nam);
if(strcmp(agnt[i].nam,"")==0)
         goto x;
 
y:gotoxy(33,10);
cin>>agnt[i].age;
if(agnt[i].age&lt;18)
{
         gotoxy(20,40);
         cout< <"Age must be more than 18";
         gotoxy(33,10);
         for(o=0;o&lt;4;o++)
                 cout<<" ";
         goto y;
}
else
{
         gotoxy(20,40);
         for(o=0;o&lt;35;o++)
                 cout<<" ";
}
 
a:gotoxy(43,14);
gets(agnt[i].addagn.hno);
if(strcmp(agnt[i].addagn.hno,"")==0)
         goto a;
 
b:gotoxy(38,16);
gets(agnt[i].addagn.area);
if(strcmp(agnt[i].addagn.area,"")==0)
         goto b;
 
c:gotoxy(38,18);
gets(agnt[i].addagn.city);
if(strcmp(agnt[i].addagn.city,"")==0)
         goto c;
 
d:gotoxy(39,20);
gets(agnt[i].addagn.stat);
if(strcmp(agnt[i].addagn.stat,"")==0)
         goto d;
 
gotoxy(36,22);
cin>>agnt[i].sal;
 
gotoxy(43,24);
cin>>agnt[i].polsld;
 
if((agnt[i].polsld)>0&&(agnt[i].polsld)&lt;1000)   //categorise the agent
         strcpy(agnt[i].categ,"BRANCH MANAGER CLUB MEMBER");
 
else if((agnt[i].polsld)>999&&(agnt[i].polsld)&lt;2000)
         strcpy(agnt[i].categ,"DIVISIONAL MANAGER CLUB MEMBER");
 
else if((agnt[i].polsld)>1999&&(agnt[i].polsld)&lt;3000)
         strcpy(agnt[i].categ,"ZONAL MANAGER CLUB MEMBER");
 
else if((agnt[i].polsld)>2999)
         strcpy(agnt[i].categ,"CHAIRMAN CLUB MEMBER");
 
agnt[i].code=fabs(100+(20*agnt[i].age)-(80*i));  //create unique code
 
clrscr();
gotoxy(34,3);
cout< <"Your details are : ";
gotoxy(25,6);
cout<<"¯ NAME : ";
puts(agnt[i].nam);
gotoxy(25,8);
cout<<"¯ AGE : "<<agnt[i].age;
gotoxy(25,10);
cout<<"¯ SALARY : Rs. "<<agnt[i].sal;
gotoxy(25,12);
cout<<"¯ ADDRESS : ";
gotoxy(29,14);
cout<<"* HOUSE NO. : ";
puts(agnt[i].addagn.hno);
gotoxy(29,16);
cout<<"* AREA : ";
puts(agnt[i].addagn.area);
gotoxy(29,18);
cout<<"* CITY : ";
puts(agnt[i].addagn.city);
gotoxy(29,20);
cout<<"* STATE : ";
puts(agnt[i].addagn.stat);
gotoxy(25,22);
cout<<"¯ POLICIES SOLD : "<<agnt[i].polsld;
gotoxy(25,24);
cout<<"¯ AGENT CATEGORY : ";
puts(agnt[i].categ);
gotoxy(25,26);
cout<<"¯ AGENT CODE : "<<agnt[i].code;
 
getch();
agnmen();
}
 
 
/* OLD AGENT'S DETAILS */
void oldagn()
{
int flag=0;
clrscr();
 
gotoxy(25,6);
cout<<"PLEASE ENTER THE AGENT CODE : ";
int pn;
cin>>pn;
 
for(int i=0;i&lt;15;i++)
{
         if(pn==agnt[i].code)//check agent code
         {
                 flag=1;
                 gotoxy(25,9);
                 cout< <"¯ NAME : ";
                 cout<<agnt[i].nam;
                 gotoxy(25,11);
                 cout<<"¯ ADDRESS : ";
                 gotoxy(29,13);
                 cout<<"* HOUSE NO. : ";
                 puts(agnt[i].addagn.hno);
                 gotoxy(29,15);
                 cout<<"* AREA : ";
                 puts(agnt[i].addagn.area);
                 gotoxy(29,17);
                 cout<<"* CITY : ";
                 puts(agnt[i].addagn.city);
                 gotoxy(29,19);
                 cout<<"* STATE : ";
                 puts(agnt[i].addagn.stat);
                 gotoxy(25,21);
                 cout<<"¯ POLICIES SOLD : ";
                 cout<<agnt[i].polsld;
                 gotoxy(25,23);
                 cout<<"¯ AGENT CATEGORY : ";
                 puts(agnt[i].categ);
                 gotoxy(25,25);
                 cout<<"¯ SALARY : Rs. ";
                 cout<<agnt[i].sal;
                 getch();
                 agnmen();
         }
}
 
if(flag==0)//if agent is not found
{
         gotoxy(25,8);
         cout<<"SORRY, AGENT NOT FOUND";
}
 
getch();
 
agnmen();
}
 
 
/* T&C FOR AGENTS */
void tncagn()
{
clrscr();
 
cout<<"\n";
for(int x=0;x&lt;80;x++)
{
         delay(5);
         cout<<"";
}
 
for(int y=1;y&lt;34;y++)
{
         delay(5);
         gotoxy(0,y);
         cout<<"\n";
}
 
gotoxy(25,5);
cout<<"TERMS & CONDITIONS FOR AGENT";
gotoxy(25,6);
cout<<"$$$$$$$$$$$$$$$$$$$$$$$$$$$$";
gotoxy(15,10);
cout<<"¯ MINIMUM ELIGIBILITY FOR LIFE INSURANCE AGENCY";
gotoxy(19,12);
cout<<"* QUALIFICATION : 12th class passed";
gotoxy(19,14);
cout<<"* AGE : 18 years completed";
gotoxy(19,16);
cout<<"* Applicant should have passed the online exam";
gotoxy(21,18);
cout<<"conducted by NSE-IT";
gotoxy(15,22);
cout<<"¯ AGENT'S LICENSE is issued for 3 years in the";
gotoxy(17,24);
cout<<"beginning and renewed thereafter for another 3 years";
gotoxy(17,26);
cout<<"after the completion of 25 hours of Agent's training.";
gotoxy(15,30);
cout<<"¯ BUSINESS CONDITION FOR THE AGENCY ENFORCED";
gotoxy(19,32);
cout<<"* 12 lives with 1 lac sum assured";
gotoxy(19,34);
cout<<"* First Premium Income(FPI) : Rs. 1 lac";
 
cout<<"\n\n";
for(x=0;x&lt;80;x++)
{
         delay(5);
         cout<<"";
}
 
for(y=2;y&lt;36;y++)
{
         delay(5);
         gotoxy(80,y);
         cout<<"";
}
 
getch();
}
 
 
/* DISPLAY FEEDBACK FORM */
void feed()
{
char str[9]="THANK YOU";
clrscr();
 
gotoxy(34,3);
cout<<"FEEDBACK FORM";
gotoxy(34,4);
cout<<"*************";
gotoxy(6,6);
cout<<"Please enter the following details : ";
gotoxy(6,8);
cout<<"AGE : ";
gotoxy(6,10);
cout<<"GENDER (m/f) : ";
gotoxy(6,12);
cout<<"OCCUPATION : ";
gotoxy(6,14);
cout<<"MONTHLY INCOME : ";
gotoxy(32,16);
cout<<"QUESTIONAIRE FORM";
gotoxy(32,17);
cout<<"*****************";
gotoxy(6,19);
cout<<"How would you rate LIC's performance on the following service features";
gotoxy(6,21);
cout<<"using (1-7) where \"1\" indicates LOW rating & \"7\" indicates HIGH rating";
gotoxy(6,23);
cout<<"1. LIC performs the service right the first time : ";
gotoxy(6,25);
cout<<"2. Agents in LIC give you prompt service : ";
gotoxy(6,27);
cout<<"3. Agents in LIC are always willing to help you : ";
gotoxy(6,29);
cout<<"4. You feel safe in your transactions with LIC : ";
gotoxy(6,31);
cout<<"5. Agents of LIC understand your specific needs : ";
gotoxy(6,33);
cout<<"6. LIC agents have the knowledge to answer your questions : ";
gotoxy(6,35);
cout<<"7. LIC has modern-looking equipments : ";
gotoxy(6,37);
cout<<"8. LIC has convenient business hours : ";
gotoxy(6,39);
cout<<"9. Location of LIC office is conducive : ";
gotoxy(6,41);
cout<<"10. Range of life insurance plans : ";
gotoxy(6,43);
cout<<"11. Premium rates of insurance plans : ";
gotoxy(6,45);
cout<<"12. Trouble free policy servicing : ";
 
gotoxy(12,8);
cin>>fbk.age;
 
gotoxy(21,10);
b:fbk.gndr=getch();
switch(fbk.gndr)
{
         case 'm':
         case 'M':
 
         case 'f':
         case 'F':cout< <fbk.gndr;
                  break;
 
         default:goto b;
}
getch();
 
c:gotoxy(19,12);
gets(fbk.occp);
if(strcmp(fbk.occp,"")==0)
         goto c;
 
gotoxy(23,14);
cin>>fbk.inc;
 
gotoxy(57,23);
fbk.a[0]=feedval();
 
gotoxy(49,25);
fbk.a[1]=feedval();
 
gotoxy(56,27);
fbk.a[2]=feedval();
 
gotoxy(55,29);
fbk.a[3]=feedval();
 
gotoxy(56,31);
fbk.a[4]=feedval();
 
gotoxy(66,33);
fbk.a[5]=feedval();
 
gotoxy(45,35);
fbk.a[6]=feedval();
 
gotoxy(45,37);
fbk.a[7]=feedval();
 
gotoxy(47,39);
fbk.a[8]=feedval();
 
gotoxy(42,41);
fbk.a[9]=feedval();
 
gotoxy(45,43);
fbk.a[10]=feedval();
 
gotoxy(42,45);
fbk.a[11]=feedval();
 
gotoxy(36,47);
for(int x=0;x&lt;9;x++)
{
         cout< <str[x];
         delay(100);
}
 
getch();
exit(0);
}
 
 
/* INPUT THE RATINGS & CHECK THEM */
char feedval()
{
char x;
d:x=getch();
 
if(x>'0'&&x< '8')
         cout<<x;
 
else
         goto d;
 
getch();
 
return x;
}
//////*********************************************\\\\\\
//////*  ¯           END OF PROGRAM            ®  *\\\\\\
//////*********************************************\\\\\\

SNAKE AND LADDER GAME IN C++


//***************************************************************
// Source Code 
//****************************************************************
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
void draw_line(int n,char ch);
void board();
void gamescore(char name1[],char name2[],int p1, int p2);
void play_dice(int &score);
void main()
{
int player1=0,player2=0,lastposition;
char player1name[80],player2name[80];
clrscr();
randomize();
draw_line(50,’=’);
cout<<“\n\n\n\n\t\tSNAKE LADDER GAME\n\n\n\n”;
draw_line(50,’=’);
cout<<“\n\n\nEnter Name of player 1 :”;
gets(player1name);
cout<<“\n\n\Enter Name of player 2 :”;
gets(player2name);
while(player1<=100 && player2<=100)
{
board();
gamescore(player1name,player2name,player1,player2);
cout<<“\n\n—>” <<player1name<<” Now your Turn >> Press any key to play “;
getch();
lastposition=player1;
play_dice(player1);
if(player1<lastposition)
cout<<“\n\aOops!! Snake found !! You are at postion “<<player1<<“\n”;
else if(player1>lastposition+6)
cout<<“\nGreat!! you got a ladder !! You are at position “<<player1;
cout<<“\n\n—>”<<player2name<<” Now your Turn >> Press any key to play “;
getch();
lastposition=player2;
play_dice(player2);
if(player2<lastposition)
cout<<“\n\n\aOops!! Snake found !! You are at position “<<player2<<“\n”;
else if(player2>lastposition+6)
cout<<“\n\nGreat!! you got a ladder !! You are at position “<<player2<<“\n”;
getch();
}
clrscr();
cout<<“\n\n\n”;
draw_line(50,’+’);
cout<<“\n\n\t\tRESULT\n\n”;
draw_line(50,’+’);
cout<<endl;
gamescore(player1name,player2name,player1,player2);
cout<<“\n\n\n”;
if(player1>=player2)
cout<<player1name<<” !! You are the winner of the game\n\n”;
else
cout<<player2name<<” !! You are the winner of the game\n\n”;
draw_line(50,’+’);
getch();
}
void draw_line(int n,char ch)
{
for(int i=0;i<n;i++)
cout<<ch;
}
void board()
{
clrscr();
cout<<“\n\n”;
draw_line(50,’-‘);
cout<<“\n\t\tSNAKE AT POSITION\n”;
draw_line(50,’-‘);
cout<<“\n\tFrom 98 to 28 \n\tFrom 95 to 24\n\tFrom 92 to 51\n\tFrom 83 to 19\n\tFrom 73 to 1\n\tFrom 69 to 33\n\tFrom 64 to 36\n\tFrom 59 to 17\n\tFrom 55 to 7\n\tFrom 52 to 11\n\tFrom 48 to 9\n\tFrom 46 to 5\n\tFrom 44 to 22\n\n”;
draw_line(50,’-‘);
cout<<“\n\t\t LADDER AT POSITION\n”;
draw_line(50,’-‘);
cout<<“\n\tFrom 8 to 26\n\tFrom 21 to 82\n\tFrom 43 to 77\n\tFrom 50 to 91\n\tFrom 62 to 96\n\tFrom 66 to 87\n\tFrom 80 to 100\n”;
draw_line(50,’-‘);
cout<<endl;
}
void gamescore(char name1[],char name2[],int p1, int p2)
{
cout<<“\n”;
draw_line(50,’~’);
cout<<“\n\t\tGAME STATUS\n”;
draw_line(50,’~’);
cout<<“\n\t—>”<<name1<<” is at position “<<p1<<endl;
cout<<“\t—>”<<name2<<” is at position “<<p2<<endl;
draw_line(50,’_’);
cout<<endl;
}
void play_dice(int &score)
{
int dice;
dice=random(6)+1;
cout<<“\nYou got “<<dice<<” Point !! “;
score=score+dice;
cout<<“Now you are at position “<<score;
switch(score)
{
case 98 :score=28;break;
case 95 :score=24;break;
case 92 :score=51;break;
case 83 :score=19;break;
case 73 :score=1;break;
case 69 :score=33;break;
case 64 :score=36;break;
case 59 :score=17;break;
case 55 :score=7;break;
case 52 :score=11;break;
case 48 :score=9;break;
case 46 :score=5;break;
case 44 :score=22;break;
case 8 :score=26;break;
case 21 :score=82;break;
case 43 :score=77;break;
case 50 :score=91;break;
case 54 :score=93;break;
case 62 :score=96;break;
case 66 :score=87;break;
case 80 :score=100;
}
}
//***************************************************************
// END OF PROJECT
//***************************************************************

CASINO GAME PROJECT IN C++


//***************************************************************
// Source Code 
//****************************************************************
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
void draw_line(int n,char ch);
void rules();
void main()
{
int balanceamt,amt,no,dice;
char playername[80],ch;
clrscr();
draw_line(60,’=’);
cout<<“\n\n\n\n\t\tCASINO GAME\n\n\n\n”;
draw_line(60,’=’);
cout<<“\n\n\nEnter Your Name :”;
gets(playername);
cout<<“\n\n\Enter Deposit amount to play game :”;
cin>>balanceamt;
do
{
clrscr();
rules();
cout<<“\n\nYour current balance is Rs.”<<balanceamt;
do
{
cout<<“\n\n”<<playername<<” enter money to bet”;
cin>>amt;
if(amt>balanceamt)
cout<<“Your betting amount is more than your current balance\n\nRe-enter data\n “;
else
break;
}while(1);
do
{
cout<<“Enter your lucky number to bet between 1 to 12 :”;
cin>>no;
if(no<=0||no>12)
cout<<“Please check the number!! should be between 1 to 12\n\nRe-enter data\n “;
else
break;
}while(1);
randomize();
dice=random(12)+1;
if(dice==no)
{
cout<<“\n\nGood Luck!! You won Rs.”<<amt*10;
balanceamt=balanceamt+amt*10;
}
else
{
cout<<“Bad Luck this time !! You lose Rs.”<<amt;
balanceamt=balanceamt-amt;
}
cout<<“\n\nThe winning number was : “<<dice;
cout<<“\n\n\t”<<playername<<” You have Rs. “<<balanceamt<<endl;
cout<<“\n\n–>Do you want to play (y/n)? “;
cin>>ch;
}while(ch==’Y’|| ch==’y’);
clrscr();
cout<<“\n\n\n”;
draw_line(70,’+’);
cout<<“\n\n\t\THANKS FOR COME TO CASINO YOUR BALANCE AMOUNT IS RS.”<<balanceamt<<“\n\n”;
draw_line(70,’+’);
cout<<“\n\nGame developed by ANIKET RAJPUT\n”;
draw_line(70,’+’);
getch();
}
void draw_line(int n,char ch)
{
for(int i=0;i<n;i++)
cout<<ch;
}
void rules()
{
clrscr();
cout<<“\n\n”;
draw_line(60,’-‘);
cout<<“\n\t\tRULES OF THE GAME\n”;
draw_line(60,’-‘);
cout<<“\n\t1. Choose any number between 1 to 12\n\t2. If you win you will get 10 times of money you bet\n\t3. If you bet on wrong number you will lose your betting amount\n\n”;
draw_line(60,’-‘);
cout<<endl;
}

//***************************************************************
// END OF PROJECT
//***************************************************************

C WEB BROWSER PROJECT



web browser project in c, c program to open a website/url

This program opens a website entered by the user. User can open any website .It will launch mozilla firefox web browser to open a website so it should be installed on your computer, if you are using an another web-browser then you can change the path in the program.

C programming code

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
#include<dos.h>
#include<string.h>

void initialize_graphics_mode();
int get_key();
void draw();

union REGS i, o;

main()
{
int key, i = 0, xpos, ypos, button;
char arr[200], temp[5], *ptr;
char a[] = "C:\\Progra~1\\Mozill~1\\firefox ";

strcpy(arr,a);

i = strlen(a);

initialize_graphics_mode();

draw();

while(1)
{
if(kbhit())
key = get_key();

if((key>=97&&key<=122)||(key>=65&&key<=90)||key==46||key==47||key==63)
{
arr[i] = key;
sprintf(temp,"%c",arr[i]);
outtext(temp);
if(getx()>470)
{
clearviewport();
moveto(5,2);
}
i++;
}
else if ( key == 13 )
{
arr[i] = '';
system(arr);
break;
}
else if ( key == 27 )
{
closegraph();
exit(EXIT_SUCCESS);
}
if(button==1&&xpos>=150&&xpos<=480&&ypos>=300&&ypos<=330)
{
system("C:\\Progra~1\\Mozill~1\\firefox animesh-programmingmania.blogspot.com");
break;
}
key = -1;
}

closegraph();
return 0;
}

void initialize_graphics_mode()
{
int gd = DETECT, gm, errorcode;

initgraph(&gd,&gm,"C:\\TC\\BGI");
errorcode = graphresult();

if( errorcode != grOk )
{
printf("Graphics error : %s\n",grapherrormsg(errorcode));

printf("Press any key to exit...\n");
getch();
exit(EXIT_FAILURE);
}
}

int get_key()
{
i.h.ah = 0;
int86(22,&i,&o);

return( o.h.al );
}

void draw()
{
settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
outtextxy(275,11,"Web Browser");
outtextxy(155,451,"
animesh-programmingmania.blogspot.com");
outtextxy(5,105,"Enter URL : ");
rectangle(120,100,600,130);
setviewport(121,101,599,129,1);
moveto(5,1);
}

//Download executable file of c web browser project.

SMILING FACE ANIMATION PROGRAM IN C


#include<graphics.h>
#include<conio.h>
#include<stdlib.h>
 
main()
{
int gd = DETECT, gm, area, temp1, temp2, left = 25, top = 75;
void *p;
 
initgraph(&gd,&gm,"C:\\TC\\BGI");
 
setcolor(YELLOW);
circle(50,100,25);
setfillstyle(SOLID_FILL,YELLOW);
floodfill(50,100,YELLOW);
 
setcolor(BLACK);
setfillstyle(SOLID_FILL,BLACK);
fillellipse(44,85,2,6);
fillellipse(56,85,2,6);
 
ellipse(50,100,205,335,20,9);
ellipse(50,100,205,335,20,10);
ellipse(50,100,205,335,20,11);
 
area = imagesize(left, top, left + 50, top + 50);
p = malloc(area);
 
setcolor(WHITE);
settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
outtextxy(155,451,"Smiling Face Animation");
 
setcolor(BLUE);
rectangle(0,0,639,449);
 
while(!kbhit())
{
temp1 = 1 + random ( 588 );
temp2 = 1 + random ( 380 );
 
getimage(left, top, left + 50, top + 50, p);
putimage(left, top, p, XOR_PUT);
putimage(temp1 , temp2, p, XOR_PUT);
delay(100);
left = temp1;
top = temp2;
}
 
getch();
closegraph();
return 0;
}

Output of program:
smiling face

C graphics tutorial



This tutorial is for all those who wish to learn c graphics programming, no knowledge of graphics concepts is required. C Graphics programming is very easy and interesting. You can use graphics programming for developing your own games, in making projects, for animation etc. It’s not like traditional C programming in which you have to apply complex logic in your program and then you end up with a lot of errors and warnings in your program. In C graphics programming you have to use standard library functions ( need not worry if you don’t know functions ) to get your task done. Just you pass arguments to the functions and it’s done. On this website you will find almost all functions with detailed explanation and a sample program showing the usage of a function. To make things easy you are provided with executable files which you can download and execute. Just click on the links below to know about various functions but firstly you should know the function initgraph which is used to initialize the graphics mode . To initialize graphics mode we use initgraph function in our program. initgraph function is present in “graphics.h” header file, so your every graphics program should include “graphics.h” header file. We will discuss initgraph withe help of following sample program:-

Sample graphics code

#include<graphics.h>
#include<conio.h>
 
int main()
{
int gd = DETECT, gm;
 
initgraph(&gd, &gm, "C:\\TC\\BGI");
 
getch();
closegraph();
return 0;
}

Firstly let me tell you what is the output of this program, this program initializes graphics mode and then closes it after a key is pressed. To begin with we have declared two variables of int type gd and gm for graphics driver and graphics mode respectively, you can choose any other variable name as you wish. DETECT is a macro defined in “graphics.h” header file, then we have passed three arguments to initgraph function first is the address of gd, second is the address of gm and third is the path where your BGI files are present ( you have to adjust this accordingly where you turbo compiler is installed). Initgraph function automatically decides an appropriate graphics driver and mode such that maximum screen resolution is set, getch helps us to wait until a key is pressed, closegraph function closes the graphics mode and finally return statement returns a value 0 to main indicating successful execution of your program. After you have understood initgraph function then you can use functions to draw shapes such as circle, line , rectangle etc, then you can learn how to change colors and fonts using suitable functions, then you can go for functions such as getimage, putimage etc for doing animation.

C Game Programming Tutorial


C Game Programming tutorial is for all those who wish to make their own games or are curious to know about what works behind when we play games. First of all we must know what qualities a game should have, your game should work fast and responds to user input very quickly and it’s look should be very good. As far as speed is concerned we know that C is very fast so you need not worry about speed you just have to ensure that you have applied the best method to solve a particular problem and look of the game is entirely in your hand. Now a question that may come in your mind is that what i need to know to make my first own game. To make a game in C you need to know the following things:-

1) C Graphics programming2) Mouse Programming ( How to handle mouse events )

3) Keyboard

Graphics programming is needed to build key game elements. For example if in your game you want a car then you can use rectangle and circle to draw it. If you don’t know c graphics programming then visit c graphics programming tutorial(IN THE POST BEFORE).

If your game is such that it takes user input through a mouse then you should know how to handle mouse events. Some of the things which we frequently need to know in our games are what is the mouse current position, which mouse button is clicked etc.

here you will find sample source code and programs, you can also download executable files so you can understand a program better. Similarly if your game gets input from keyboard you need to know which key is pressed and then you can take appropriate action according to the key pressed.

C program to display bitmap images(*.bmp)


#include stdio.h
#include conio.h
#include dos.h
#define DECLARE

#define VGALOW 0x101

typedef unsigned int UINT;
typedef unsigned char UCHAR;
struct VgaInfoBlock {
 char signature[4];
 short version;
 char far  *oemname;
long capabilities;
unsigned far *modes;
char buffer[238];
};

typedef struct
{
 char red;
char green;
char blue;
}RGB;

 struct VgaModeInfoBlock
{
 UINT ModeAttributes;
UCHAR WinAAttributes;
UCHAR WinBAttributes;
UINT WindowGranularity;
UINT WinSize;
UINT WinASegment;
UINT WinBSegment;
void (far *WinFuncPtr)(void);
UINT BytesperScanLine;
UINT XResolution;
UINT YResolution;
UCHAR XCharSize;
UCHAR YCharSize;
UCHAR NumberOfPlanes;
UCHAR BitsPerPixel;
UCHAR NumberOfBanks;
UCHAR MemoryModel;
UCHAR BankSize;
UCHAR NumberOfImagePages;
UCHAR Reserved1;
UCHAR RedMaskSize;
UCHAR RedMaskPosition;
UCHAR GreenMaskSize;
UCHAR GreenMaskPosition;
UCHAR BlueMaskSize;
UCHAR BlueMaskPosition;
UCHAR ReservedMaskSize;
UCHAR ReservedMskPosition;
UCHAR DirectScreenModeInfo;
UCHAR Reserved2[216];
}modeinfo;

typedef enum
{
 memPL = 3,
memPK = 4,
memRGB = 6,
memYUV = 7
}memModels;

typedef struct tagBMPHEADER
{
 unsigned char bftype[2];
unsigned long bfsize;
unsigned int bfres1,bfres2;
unsigned long bfoffbits;
unsigned long bisize,biwidth,biheight;
unsigned int biplanes,bibitcount;
unsigned long
bicompression,bisizeimage,bixpelspermeter,biypelspermeter;
unsigned long biclrused,biclrimportant;
}BMPHEADER;
typedef struct tagRGBQUAD
{
 unsigned char blue,green,red,rgbreserved;
}RGBQUAD;
typedef struct tagBMPINFO
{
 BMPHEADER bmiheader;
 RGBQUAD bmicolors[256];
}BMPINFO;

DECLARE int maxx,maxy;
DECLARE int xres,yres;
DECLARE int bytesperline;
DECLARE int curbank;
DECLARE unsigned int bankshift;
DECLARE int oldmode;
DECLARE char far *screenptr;
DECLARE void (far *bankswitch)(void);
DECLARE int pcolor,xp,yp;
DECLARE int ccolor;

DECLARE int GetVesaMode(void);
DECLARE void SetVseaMode(int);
DECLARE void setbank(int);
DECLARE void SetPalette(RGB pal[256]);
DECLARE void vinitgraph(int);
DECLARE void setwidth(int);
DECLARE void vclosegraph(void);
DECLARE void startaddr(int *,int *,int);
DECLARE void vputpixel(int,int,int);
DECLARE void SetPalette(RGB color[256]);
DECLARE char *ReadMemString(char far *);
DECLARE void showbitmap(char *infname,int xs,int ys);

void Vesa(int state)
{
 union REGS reg;
reg.x.ax=0x4FFF;
reg.h.dl=(char ) state;
int86(0x10,®,®);
return ;
}

int GetSvgaInfo(struct VgaInfoBlock far *buffer)
{
 struct REGPACK reg;
reg.r_ax = 0x4F00;
reg.r_es = FP_SEG(buffer);
reg.r_di = FP_OFF(buffer);
intr(0x10,®);
if(reg.r_ax==0x004F)
 return 0;
else
 return 1;
}

char *ReadMemString(char far *pointer)
{
 char string[200];
int i=0;
while(*pointer)
{
 string[i]=*pointer;
 pointer++;
i++;
}
string[i]=0;
return string;
}

int GetSvgaModeInfo(int mode,struct VgaModeInfoBlock far *buffer)
{
 struct REGPACK reg;
reg.r_ax = 0x4F01;
reg.r_es = FP_SEG(buffer);
reg.r_di = FP_OFF(buffer);
reg.r_cx=mode;
intr(0x10,®);
if(reg.r_ax!=0x004F)
 return 1;
else
 return 0;
}

int GetVesaMode(void)
{
 union REGS in,out;
in.x.ax=0x4F03;
int86(0x10,&in,&out);
return out.x.bx;
}

void SetVesaMode(int mode)
{

struct REGPACK reg;
oldmode = GetVesaMode();
reg.r_ax = 0x4F02;
reg.r_bx=mode;
intr(0x10,®);
GetSvgaModeInfo(GetVesaMode(), &modeinfo);

xres = modeinfo.XResolution;
yres = modeinfo.YResolution;

maxx=xres;
bytesperline = modeinfo.BytesperScanLine;
bankshift = 0;
while((unsigned ) (64 >> bankshift)!= modeinfo.WindowGranularity)
 bankshift++;
bankswitch = modeinfo.WinFuncPtr;
curbank=-1;
screenptr = (char far *)( ((long) 0xA000 )<<16 | 0);

return ;
}
void setbank(int bank)
{
  if(bank==curbank)
   return;
  curbank = bank;
bank<<=bankshift;
_BX=0;
_DX=bank;
bankswitch();
_BX=1;
bankswitch();
return ;
}

void SetPalette(RGB pal[256])
{
 union REGS reg;
 struct SREGS inreg;
 reg.x.ax=0x1012;
 segread(&inreg);
 inreg.es = inreg.ds;
 reg.x.bx=0;
reg.x.cx=256;
reg.x.dx=(int ) &pal[0];
int86x(0x10,®,®,&inreg);
return ;
}
void vputpixel(int x,int y,int c)
{
 long addr = (long ) y *  bytesperline + x;
setbank((int) (addr>>16));
*(screenptr+(addr & 0xFFFF))=(char) c;
return;
}
void setwidth(int width)
{
  union REGS in,out;
in.x.ax = 0x4F06;
in.x.bx=0x0000;
in.x.cx=width;
int86(0x10,&in,&out);

bytesperline = (int ) out.x.bx;
maxy = (int ) out.x.dx;
maxx = (int ) out.x.cx;
return ;
}
void vinitgraph(int mode)
{
 SetVesaMode(mode);
 setwidth(xres);
return ;
}

void vclosegraph(void)
{
 vinitgraph(oldmode);
/* union REGS regs;
regs.h.ah = 0x00;
regs.h.al = 0x03;
int86(0x10, ®s, ®s);*/
 maxx=xres;
}
void startaddr(int *xs,int *ys,int mode)
{
  union REGS in,out;
in.x.ax = 0x4F07;
if(mode==0)
 {
  in.x.bx=0x0000;
  in.x.cx=*xs;
  in.x.dx = *ys;
 }
else
 in.x.bx = 0x0001;
int86(0x10,&in,&out);
if(mode==1)
 {
   *xs = out.x.cx;
   *ys = out.x.dx;
 }
return ;

}

char ISValidBitmap(char *fname)
{
 BMPINFO bmpinfo;
 FILE *fp;
 if((fp = fopen(fname,”rb+”))==NULL)
 {
  printf(“
Unable open the file %s”,fname,”!!”);
  return 0;
 }

 fread(&bmpinfo,sizeof(bmpinfo),1,fp);
 fclose(fp);
 if(!(bmpinfo.bmiheader.bftype[0]==’B’ &&
bmpinfo.bmiheader.bftype[1]==’M’))
 {
  printf(“
can’t read the file: not a valid BMP file!”);
  return 0;
 }

 if(!bmpinfo.bmiheader.bicompression==0)
 {
  printf(“
can’t read the file: should not be a RLR encoded!!”);
  return 0;
 }
 if(!bmpinfo.bmiheader.bibitcount==8)
 {
 printf(“can’t read the file: should be 8-bit per color format!!”);
 return 0;
 }

return 1;
}

void showbitmap(char *infname,int xs,int ys)
{
BMPINFO bmpinfo;
RGB pal[256];
FILE *fpt;
int i,j,w,h,c,bank;
unsigned char byte[1056];
long addr;
unsigned int k;
if((fpt=fopen(infname,”rb+”))==NULL)
 {
  printf(“
Error opening file “);
  getch();
  return 1;
 }

fread(&bmpinfo,sizeof(bmpinfo),1,fpt);
fseek(fpt,bmpinfo.bmiheader.bfoffbits,SEEK_SET);
w = bmpinfo.bmiheader.biwidth;
h = bmpinfo.bmiheader.biheight;
for(i=0;i<=255;i++)
{
 pal[i].red = bmpinfo.bmicolors[i].red/4;
pal[i].green = bmpinfo.bmicolors[i].green/4;
pal[i].blue = bmpinfo.bmicolors[i].blue/4;
}
vinitgraph(VGALOW);
setwidth(1000);
SetPalette(pal);
for(i=0;i<h;i++)

</h;i++)
{
   fread(&byte[0],sizeof(unsigned char),w,fpt);
 for(j=0;j<w;j++)

</w;j++)
  {
   c= (int ) byte[j];
     addr= (long) (ys+h-i)*bytesperline+xs+j;
bank = (int ) (addr >>16);
if(curbank!= bank)
{
 curbank =bank;
bank<<=bankshift;
_BX=0;
_DX=bank;
bankswitch();
_BX=1;
bankswitch();
}
*(screenptr+(addr & 0xFFFF)) = (char ) c;
}
}
fclose(fpt);
getch();
vclosegraph();
return 0;
}

int ColorToGrey(char *infname,int xs,int ys)
{
BMPINFO bmpinfo;
FILE *fpt1,*fpt2;
char fname[13];
unsigned char r,g,b,byte[1056],pal[256];
double e,grey;
int i,j,h,w,pcnt=0;
long size,curpos;
strcpy(fname,infname);
fpt2=fopen(“Grey.bmp”,”wb”);
if((fpt1=fopen(fname,”rb+”))==NULL)
{
  printf(“can’t open the file %s”,infname);
getch();
return 1;
}

clrscr();
printf(“Preparing taget file..”);
fseek(fpt1,0,SEEK_END);
size = ftell(fpt1) + 256;
fseek(fpt1,0,SEEK_SET);
fread(&bmpinfo,sizeof(bmpinfo),1,fpt1);
curpos=ftell(fpt1);
pcnt = (int )ceil((float) curpos *100.0/(float) size);
gotoxy(25,1);
printf(“%d completed”,pcnt);
for(i=0;i<=255;i++)
{
 r = bmpinfo.bmicolors[i].red;
 g = bmpinfo.bmicolors[i].green;
 b = bmpinfo.bmicolors[i].blue;
grey = (double) 0.3 * (double ) r+ (double ) 0.11 * (double ) b +
(double ) 0.59 * (double) g;
if(grey-(int) grey >=0.5)
 grey++;
if(grey>255)
 grey=255;
pal[i]=(unsigned char ) grey;
bmpinfo.bmicolors[i].red = (unsigned char ) i;
bmpinfo.bmicolors[i].green = (unsigned char ) i;
bmpinfo.bmicolors[i].blue = (unsigned char ) i;
curpos++;
}
bmpinfo.bmiheader.biclrused=0;
i = bmpinfo.bmiheader.bfoffbits;
bmpinfo.bmiheader.bfoffbits=1078;
fwrite(&bmpinfo,sizeof(bmpinfo),1,fpt2);
fseek(fpt1,i,SEEK_SET);
fseek(fpt2,bmpinfo.bmiheader.bfoffbits,SEEK_SET);
w=bmpinfo.bmiheader.biwidth;
h = bmpinfo.bmiheader.biheight;
curpos = ftell(fpt1) + 256;
for(i=0;i<h;i++)

</h;i++)
{
 fread(&byte[0],sizeof(unsigned char),w,fpt2);
 for(j=0;j<w;j++)

</w;j++)
   byte[j]=pal[byte[j]];
 fwrite(&byte[0],sizeof(unsigned char ) , w,fpt2);
curpos+=w;
pcnt = (int )ceil((float) curpos *100.0/(float) size);
gotoxy(25,1);
printf(“%d completed”,pcnt);
}
fclose(fpt1);
fclose(fpt2);
showbitmap(“Grey.bmp”,xs,ys);
return 0;
}

void main()
{
  char file[13];
  memset(file,0,13);
 clrscr();
 printf(“
Enter the file name[*.bmp]:”);
 scanf(“%s”,file);
 if(IsValidBitmap(file))
   showbitmap(file,0,0);
 else
   printf(“
Not a valid bitmap file”);
 printf(“
That’s all folks”);
   getch();

}

KAUN BANEGA KARORPATI GAME IN C


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

void question1();
main()
{

 printf(“\n\n\n\n\n\n\t\t\t\t  ______________________\
 \n\t\t\t\t | Hello And WELCOME TO\t|\
 \t\t\t\t\t\t\t | KAUN BANEGA    \t|\
 \t\t\t\t\t\t\t | CROREPATI          \t|\
 \n\t\t\t\t |______________________|\n”);
 getche();
 question1();
 getch();
}
char a,b,c,d,A,B,C,D,ans;
void question2();
void question1()
{
 fflush(stdin);
 printf(“\nQ1.What does AC and DC stand for in the electrical field?”);
 printf(“\n A. A Rock Band from Australia\t B. Alternating Current and Direct Current”);

 printf(“\n C. Average Current\t and Discharged Capacitor\
 \nD. Atlantic City and District of Columbia\n  “);
 scanf(“%c”,&ans);
 switch(ans)
 {
  case ‘A':
  case ‘a':
  case ‘C':
  case ‘c':
  case ‘D':
  case ‘d':
   printf(“\n\nWRONG ANSWER!!”);
  break;
  case ‘B':
  case ‘b':
   printf(“\n\nCORRECT ANSWER!!”);
   printf(“\n\nYOU WON Rs.1,000!!”);
  break;
  default:
   printf(“\n\nIMPROPER CHOICE!!”);
 }

 if(ans == ‘B’ || ans == ‘b’)
 {
  getche();
 
  question2();
 }
}
void question3();
void question2()
{

 fflush(stdin);

 printf(“\nQ2. Sometimes computers and cash registers in a foodmart are connected to a UPS system. What does UPS mean?”);
 printf(“\nA. United Parcel Service \t B. Uniform Product Support”);
 printf(“\nC. Under Paneling Storage\t D.Uninterruptable Power Supply”);
 scanf(“%c”,&ans);
 switch(ans)
 {
  case ‘A':
  case ‘a':
  case ‘B':
  case ‘b':
  case ‘C':
  case ‘c':
   printf(“\n\nWRONG ANSWER!!”);
  break;
  case ‘D':
  case ‘d':
  {
   printf(“\n\nCORRECT ANSWER!!”);
   printf(“\n\nYOU WON Rs.2,000!!”);
  }
  break;
  default:
   printf(“\n\nIMPROPER CHOICE!!”);
 }

 if(ans == ‘D’ || ans == ‘d’)
 {
  getche();
 
  question3();
 }

}
void question4();
void question3()
{

 fflush(stdin);

 printf(“Q3.Who is the author of Hamlet?”);
 printf(“\nA. Christopher Marlowe\t B. William Shakespeare”);
 printf(“\nC. Geoffrey Chaucer\\t D. Edith Wharton”);
 scanf(“%c”,&ans);
 switch(ans)
 {
  case ‘A':
  case ‘a':
  case ‘C':
  case ‘c':
  case ‘D':
  case ‘d':
   printf(“\n\nWRONG ANSWER!!”);
  break;
  case ‘B':
  case ‘b':
  {
   printf(“\n\nCORRECT ANSWER!!”);
   printf(“\n\nYOU WON Rs.3,000!!”);
  }
  break;
  default:
   printf(“\n\nIMPROPER CHOICE!!”);
 }
 if(ans == ‘B’ || ans == ‘b’)
 {
  getche();
 
  question4();
 }

}
void question5();
void question4()
{

 fflush(stdin);

 printf(“Q4.What frequency range is the High Frequency band?”);
 printf(“\nA. 100 kHz\tB. 1GHz”);
 printf(“\nC. 30 to 300 MHz\t D. 3 to 30 MHz”);
 scanf(“%c”,&ans);
 switch(ans)
 {
  case ‘A':
  case ‘a':
  case ‘B':
  case ‘b':
  case ‘C':
  case ‘c':
   printf(“\n\nWRONG ANSWER!!”);
  break;
  case ‘D':
  case ‘d':
  {
   printf(“\n\nCORRECT ANSWER!!”);
   printf(“\n\nYOU WON Rs.5,000!!”);
  }
  break;
  default:
   printf(“\n\nIMPROPER CHOICE!!”);
 }
 if(ans == ‘D’ || ans == ‘d’)
 {
  getche();
 
  question5();
 }

}
void question6();
void question5()
{

 fflush(stdin);
 printf(“Q5.What does EPROM stand for?”);
 printf(“\nA. Electric Programmable Read Only Memory\n \n    B. Erasable Programmable Read Only Memory”);

 printf(“\n| C. Evaluable Philotic Random Optic Memory \n \n   D. Every Person Requires One Mind\t\t\t|”);
 scanf(“%c”,&ans);
 switch(ans)
 {
  case ‘A':
  case ‘a':
  case ‘C':
  case ‘c':
  case ‘D':
  case ‘d':
   printf(“\n\nWRONG ANSWER!!”);
  break;
  case ‘B':
  case ‘b':
  {
   printf(“\n\nCORRECT ANSWER!!”);
   printf(“\n\nYOU WON Rs.10,000!!”);
  }
  break;
  default:
   printf(“\n\nIMPROPER CHOICE!!”);
 }
 if(ans == ‘B’ || ans == ‘b’)
 {
  getche();
 
  question6();
 }

}
void question7();
void question6()
{

 fflush(stdin);
 printf(“Q6.Which motor is NOT suitable for use as a DC machine?”);
 printf(“\nA. Permanent magnet motor \t B. Series motor”);
 printf(“\nC. Squirrel cage motor \t D. Synchronous motor”);
 scanf(“%c”,&ans);
 switch(ans)
 {
  case ‘A':
  case ‘a':
  case ‘B':
  case ‘b':
  case ‘D':
  case ‘d':
   printf(“\n\nWRONG ANSWER!!”);
  break;
  case ‘C':
  case ‘c':
  {
   printf(“\n\nCORRECT ANSWER!!”);
   printf(“\n\nYOU WON Rs.25,000!!”);
  }
  break;
  default:
   printf(“\n\nIMPROPER CHOICE!!”);
 }
 if(ans == ‘C’ || ans == ‘c’)
 {
  getche();
 
  question7();
 }

}
void question8();
void question7()
{

 fflush(stdin);
 printf(“Q7.Compact discs, (according to the original CD specifications)hold how many minutes of music?”);
 printf(“\nA. 74 mins\t B. 56 mins”);
 printf(“\nC. 60 mins\t D. 90 mins”);
 scanf(“%c”,&ans);

 switch(ans)
 {
  case ‘B':
  case ‘b':
  case ‘C':
  case ‘c':
  case ‘D':
  case ‘d':
   printf(“\n\nWRONG ANSWER!!”);
  break;
  case ‘A':
  case ‘a':
  {
   printf(“\n\nCORRECT ANSWER!!”);
   printf(“\n\nYOU WON Rs.50,000!!”);
  }
  break;
  default:
   printf(“\n\nIMPROPER CHOICE!!”);
 }
 if(ans == ‘A’ || ans == ‘a’)
 {
  getche();
 
  question8();
 }

}
void question9();
void question8()
{

 fflush(stdin);
 printf(“Q8.Who was played by Kenneth Branagh in ‘Hamlet’ (1996)?”);
 printf(“\n| A. Horatio\t\t     |\t B. Laertes\t\t\t|”);
 printf(“\n| C. Polonius\t\t     |\t D. Hamlet\t\t\t|”);
 scanf(“%c”,&ans);
 switch(ans)
 {
  case ‘A':
  case ‘a':
  case ‘B':
  case ‘b':
  case ‘C':
  case ‘c':
   printf(“\n\nWRONG ANSWER!!”);
  break;
  case ‘D':
  case ‘d':
  {
   printf(“\n\nCORRECT ANSWER!!”);
   printf(“\n\nYOU WON Rs.1,00,000!!”);
  }
  break;
  default:
   printf(“\n\nIMPROPER CHOICE!!”);
 }
 if(ans == ‘D’ || ans == ‘d’)
 {
  getche();
 
  question9();
 }
}
void question10();
void question9()
{

 fflush(stdin);
 printf(“Q9.Which famous national leader of India has written books on the ancient Greek philosopher Socrates and the ancient Roman king Marcus Aurelius?”);
 printf(“\nA. Mahatma Gandhi\t B. Jawaharlal Nehru”);
 printf(“\nC. Bal Gangadhar Tilak\t D. C.Rajagopalachari”);
 scanf(“%c”,&ans);
 switch(ans)
 {
  case ‘A':
  case ‘a':
  case ‘B':
  case ‘b':
  case ‘C':
  case ‘c':
   printf(“\n\nWRONG ANSWER!!”);
  break;
  case ‘D':
  case ‘d':
  {
   printf(“\n\nCORRECT ANSWER!!”);
   printf(“\n\nYOU WON Rs.10,00,000!!”);
  }
  break;
  default:
   printf(“\n\nIMPROPER CHOICE!!”);
 }
 if(ans == ‘D’ || ans == ‘d’)
 {
  getche();
 
  question10();
 }

}
void question11();
void question10()
{
 
  fflush(stdin);
  printf(“\n\nQ10.Sishu is the literary work of which Indian author?”);
  printf(“\nA. Jawaharlal Nehru”);
  printf(“\nB. Arundhati Roy”);
  printf(“\nC. Rabindranath Tagore”);
  printf(“\nD. Vikram Seth \n”);
  scanf(“%c”,&ans);

  switch(ans)
  {
   case ‘A':
   case ‘a':
   case ‘B':
   case ‘b':
   case ‘D':
   case ‘d':
    printf(“\n\nWRONG ANSWER!!”);
   break;
   case ‘C':
   case ‘c':
   {
    printf(“\n\nCORRECT ANSWER!!”);
    printf(“\n\nYOU WON Rs.50,00,000!!”);
   }
   break;
   default:
    printf(“\n\nIMPROPER CHOICE!!”);
  }

  if(ans == ‘C’ || ans == ‘c’)
  {
   getche();
  
   question11();
  }

}
void question11()
{
 
  fflush(stdin);
  printf(“\n\nQ11.What was the active medium used in the first working laser ever constructed?”);
  printf(“\nA. Helium-neon gas”);
  printf(“\nB. A ruby rod”);
  printf(“\nC. A diamond block “);
  printf(“\nD. Carbon dioxide gas\n”);
  scanf(“%c”,&ans);

  switch(ans)
  {
   case ‘A':
   case ‘a':
   case ‘C':
   case ‘c':
   case ‘D':
   case ‘d':
    printf(“\n\nWRONG ANSWER!!”);
   break;
   case ‘B':
   case ‘b':
   {
    printf(“\n\nCORRECT ANSWER!!”);
    printf(“\n\nYOU WON Rs.1,00,00,000!!”);
   }
   break;
   default:
    printf(“\n\nIMPROPER CHOICE!!”);
  }

  if(ans == ‘B’ || ans == ‘b’)
  {
   getche();
   printf(“CONGRATULATIONS!”);
   printf(“\n\t Thank you!!”);
  }
}

/*FOR ANY HELP PLEASE CONTACT 9874328556 OR MAILTO *animeshshaw59@gmail.com
*/

C PROGRAM TO MAKE A 3D CAR IN GRAPHICS


#include<graphics.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#include<process.h>

void main()
{
   int gd=DETECT,gm;
   initgraph(&gd,&gm,”c:\\tc\\bgi”);
int c=12;
setbkcolor(0);
//setlinestyle(0,1,2);
int t;
while(1)
{
settextstyle(2,0,5);
outtextxy(100,10,”Press L,H ,T,P”);
outtextxy(100,30,”Press 1 for Quit”);
as:
setcolor(13);
ellipse(380,127,20,152,130,35);
//////////////////////////////rear//////////////////////////

line(490,109,560,142);
line(560,142,569,142);
line(569,142,582,102);
line(582,102,620,92);
line(593,132,617,125);

line(617,124,627,96);
line(620,92,628,97);

line(472,86,602,96);
line(501,113,575,121);
line(443,77,475,80);

line(443,77,432,93);
line(475,80,472,85);
//setcolor(4);
   line(593,132,593,137);
   line(593,137,600,141);
   line(600,141,600,185);
   line(600,185,608,192);
   line(608,192,608,234);
   line(608,234,586,253);
    line(586,253,577,248);

/////////////////////////           mirror
   line(263,112,363,127);
      line(193,160,263,112);
   line(193,160,220,170);
      line(220,170,280,180);
      line(280,180,320,185);
      line(320,185,363,127);
////////////////////////////////sidemirror
line(340,194,460,169);
 line(460,169,519,152);

ellipse(512,144,300,30,10,10);
ellipse(467,143,28,100,50,30);
line(510,128,521,138);
line(435,116,440,171);

//   setcolor(4);
////////////////////////////////////////cont//
   line(339,194,372,144);
//    line(372,140,386,128);
ellipse(454,208,87,123,128,95);
line(372,144,384,128);
   int b,x,y;
////////////////////////lower
line(365,298,524,264);
line(365,298,330,310);
line(330,310,323,310);

///////////////////////////////bumper
ellipse(162,221,135,190,90,40);
line(96,193,140,174);
line(140,174,160,168);
line(160,168,192,161);

//////////////////////front
ellipse(75,246,95,190,18,18);
line(57,251,57,286);
//setcolor(4);
ellipse(181,178,232,263,200,137);
ellipse(195,180,256,286,200,137);

ellipse(191,171,228,247,200,100);
ellipse(231,198,234,275,200,80);

//setcolor(9);
//ellipse(195,170,256,286,200,137);
//setcolor(12);

ellipse(196,167,228,246,200,90);
ellipse(231,184,234,276,200,80);

ellipse(191,200,228,246,200,90);
ellipse(228,218,234,276,200,80);

ellipse(258,268,180,220,200,40);
ellipse(178,296,244,355,16,10);

ellipse(238,249,227,250,200,60);

/////////////wheel1
ellipse(302,281,320,77,26,45);
ellipse(290,277,65,162,40,45);
ellipse(278,288,144,212,31,45);

/////////////wheel2
//setcolor(5);
ellipse(302+260,229,328,87,26,45);
ellipse(290+280-7,277-50+2,90,162,40,45);
ellipse(278+270,288-50,144,215,27,45);
 b=0;
int v=0;

/////////
ellipse(302+250+v,227+b,295,90,29,41);
ellipse(302+234+v,231+b,245,306,50,40);
//setlinestyle(3,0,3);
ellipse(302+248+v,229+b,0,360,21,30);

ellipse(302+247+v,229+b,0,360,8,10);
setfillstyle(6,11);
//floodfill(302+248+v,230+b,13);
//line(546,201,546,257);
//line(554,201,554,257);
//setcolor(4);

line(546+v,201+b,546+v,220+b);
line(551+v,201+b-2,551+v,220+b);

line(546+v,238+b,546+v,257+b);
line(551+v,238+b+2,551+v,257+b+2);

line(530+v,225+b,541+v,225+b);
line(530+v,230+b,541+v,230);

line(557+v,225+b,570+v,225+b);
line(557+v,230+b,570+v,230+b);

line(563+v,206+b,552+v,222+b);
line(534+v,246+b,543+v,232+b);

line(566+v,210+b,556+v,223+b);
line(536+v,250+b,544+v,238+b);

line(536+v,207+b,546+v,222+b);
line(532+v,213+b,542+v,224+b);

line(556+v,235+b,566+v,247+b);
line(551+v,237+b,563+v,253+b);

////////////////////////////////////////////////////
v=-260;
b=56;
ellipse(302+233+v,221+b,260,60,49,51);
//ellipse(302+234+v,231+b,245,306,50,40);
//setlinestyle(3,0,3);
ellipse(302+243+v,224+b,0,360,28,35);
//  line(249,328,269,328);
ellipse(300+245+v,223+b,0,360,10,12);

ellipse(285+249+v,239+b,210,260,30,33);
//floodfill(285+258+v,230+b,12);
b=45;
v=v-4;
line(546+v,201+b,546+v,220+b+2);
line(551+v,201+b,551+v,220+b+2);
b=b+8;
line(546+v,238+b,546+v,257+b+4);
line(551+v,238+b,551+v,257+b+4);
v=v-2;
line(530+v-6,225+b,541+v,225+b);
line(530+v-6,230+b,541+v,230+b);
v=v+5;
line(557+v,225+b,570+v+3,225+b);
line(557+v-1,230+b,570+v+3,230+b);

b=b-5;
v=v-5;
line(565+v+3,206+b,552+v+4,222+b-2);
b=b+15;

line(534+v,246+b,543+v+3,232+b-5);
b=b-10;
line(566+v+7,210+b-5,556+v+4,220+b);
line(536+v-5,250+b,544+v-2,238+b-4);

line(536+v,207+b-8,545+v,222+b-5);
line(531+v,212+b-8,542+v,224+b-2);

line(556+v,235+b,566+v+3,247+b+5);
line(551+v,237+b,563+v+2,253+b+3);

///////////////////lights
ellipse(199,250,144,345,18,8);
line(185,245,206,230);
//setcolor(4);
ellipse(223,234,340,110,8,5);
line(230,237,217,252);
line(206,230,220,229);
//setfillstyle(1,4);

//floodfill(200,240,12);

/////////////////////////////////////
line(90,223,152,236);
line(152,236,137,254);
line(90,223,90,242);

//setfillstyle(10,9);
//floodfill(91,230,14);
ellipse(240,270,104,136,100,60);
ellipse(185,237,120,160,100,60);
ellipse(80,221,357,134,10,10);

line(152,236,168,228);
///////////////////////////////////////////////
line(435,116,440,171);
//////////////////////////////////////////hp
//line(134,185,220,210);
line(134,185,196,160);
line(214,212,318,185);
/////////////////////////////////////////////////light

//setcolor(14);
ellipse(166,247,99,330,8,8);
ellipse(171,243,310,129,7,7);
putpixel(174,250,13);
putpixel(173,251,13);
putpixel(164,239,13);
putpixel(165,238,13);

/////////////////////////////////////////road/////////////////////
setcolor(13);
line(1,430,639,300);
line(1,445,639,315);

line(1,210,93,194);
line(1,195,194,158);

//line(1,170,639,71);
//line(1,170,229,135);
line(520,90,639,71);
line(478,86,639,56);

   int c=0;

   line(10,194+c,10,208+c);
line(40,189+c,40,204+c);
line(70,183+c,70,198+c);
line(100,176+c,100,190+c);
line(130,170+c,130,177+c);
line(160,166+c,160,168+c);
line(190,160+c,190,161+c);
line(190+330,78+c,190+330,89+c);

line(190+360,72+c,190+360,85+c);
line(190+390,67+c,190+390,81+c);
line(190+420,62+c,190+420,76+c);
line(190+449,57+c,190+449,71+c);
c=236;

line(10,192+c,10,208+c);
line(40,189+c-2,40,204+c-3);
line(70,183+c-3,70,198+c-3);
line(100,176+c-2,100,190+c-2);
line(130,170+c-2,130,177+c+5);
line(160,166+c-3,160,168+c+8);
line(190,160+c-4,190,161+c+9);

line(190+30,156+c-5,190+30,170+c-5);

line(190+30+30,156+c-12,190+30+30,170+c-12);

line(190+90,156+c-18,190+90,170+c-17);

line(190+120,156+c-25,190+120,170+c-25);

line(190+150,156+c-30,190+150,170+c-30);

line(190+180,156+c-37,190+180,170+c-36);

line(190+210,156+c-42,190+210,170+c-42);

line(190+240,156+c-48,190+240,170+c-48);

line(190+270,156+c-55,190+270,170+c-54);

line(190+300,156+c-61,190+300,170+c-61);

line(190+330,78+c+10,190+330,89+c+13);

line(190+360,72+c+11,190+360,85+c+13);
line(190+390,67+c+10,190+390,81+c+10);
line(190+420,62+c+8,190+420,76+c+10);
line(190+449,57+c+8,190+449,71+c+8);

/////////////////road

setcolor(12);          /////////////////////////////1

line(1,310,25,306);
line(6,318,30,315);
line(1,310,6,318);
line(25,306,30,314);
int k,m;
k=13*45+19;
m=16*(-8);
                            //2
setcolor(12);

line(605,310-128,629,306-128);
line(610,318-128,634,315-128);
line(605,310-128,610,318-128);
line(629,306-128,634,314-128);

setcolor(12);    //////////////////////////////////3
k=45;
m=-8;
line(46,302,70,298);
line(51,310,75,307);
line(46,302,51,310);
line(70,298,75,306);

setfillstyle(1,0);
floodfill(64,303,12);

setfillstyle(1,14);
floodfill(14,314,12);
floodfill(617,183,12);

setfillstyle(1,0);
floodfill(14,314,12);
floodfill(617,183,12);

setfillstyle(1,14);
floodfill(64,303,12);

t=getch();
if(t==’1′)
exit(0);
if(t==’h’)
{
sound(710);
delay(500);
nosound();
//break;
}
if(t==’t’)
{
while(!kbhit())  {
setfillstyle(1,0);
floodfill(536,213,13);
floodfill(563,213,13);
floodfill(561,244,13);
floodfill(538,244,13);
floodfill(274,295,13);
floodfill(294,295,13);
floodfill(274,265,13);
floodfill(294,265,13);
floodfill(548,250,13);
floodfill(548,214,13);
floodfill(533,228,13);
floodfill(563,228,13);
floodfill(262,281,13);
floodfill(308,281,13);
floodfill(284,251,13);
floodfill(284,295,13);

setfillstyle(1,random(12));

floodfill(200,250,13);
delay(10);
//setfillstyle(1,11);

 floodfill(170,250,13);
 floodfill(80,230,13);

 }

setfillstyle(1,0);

floodfill(200,250,13);
delay(10);
//setfillstyle(1,11);

 floodfill(170,250,13);
 floodfill(80,230,13);

    }

if(t==’l’)
{
while(!kbhit())
{

delay(120);
setfillstyle(6,0);         //////////////////////////ty
floodfill(536,213,13);
floodfill(563,213,13);
floodfill(561,244,13);
floodfill(538,244,13);
floodfill(274,295,13);
floodfill(294,295,13);
floodfill(274,265,13);
floodfill(294,265,13);

setfillstyle(1,0);
floodfill(64,303,12);

///////////////////////////////////road

setfillstyle(9,0);       /////////////////////color
floodfill(81-40+5,419+7,13);
floodfill(151-40,409+7,13);
floodfill(211-40,397+7,13);
floodfill(271-40,380+7,13);
floodfill(331-40,368+7,13);
floodfill(396-40,355+7,13);
floodfill(450-40,345+7,13);
floodfill(510-40,335+7,13);
floodfill(570-40,325+7,13);
floodfill(630-40,312+7,13);

//////////////////////
floodfill(50,197,13);
floodfill(110,177,13);
floodfill(166,165,13);
floodfill(527,86,13);
floodfill(587,71,13);

setfillstyle(6,14); //////////////////////////ty
floodfill(548,250,13);
floodfill(548,214,13);
floodfill(533,228,13);
floodfill(563,228,13);
floodfill(262,281,13);
floodfill(308,281,13);
floodfill(284,251,13);
floodfill(284,295,13);
////////////////////////////////////////road

setfillstyle(9,10);///////////////////////////////////color
floodfill(19,429,13);
floodfill(81,419,13);
floodfill(151,409,13);
floodfill(211,397,13);
floodfill(271,380,13);
floodfill(331,368,13);
floodfill(396,355,13);
floodfill(450,345,13);
floodfill(510,335,13);
floodfill(570,325,13);
floodfill(630,312,13);
//////////////////////////////////////
floodfill(20,197,13);
floodfill(80,187,13);
floodfill(133,174,13);
floodfill(517,86,13);
floodfill(557,81,13);
floodfill(627,70,13);

setfillstyle(1,14);
floodfill(14,314,12);
floodfill(617,183,12);

///////////////////////////////////////
setfillstyle(10,4);
floodfill(302+248,230,13);
floodfill(302+248+v,230+b,13);
///light
setfillstyle(6,11);                             ///////////

floodfill(200,250,13);

floodfill(170,250,13);
 floodfill(80,230,13);

delay(120);

setfillstyle(6,0);/////////////////////ty
floodfill(548,250,13);
floodfill(548,214,13);
floodfill(533,228,13);
floodfill(563,228,13);
floodfill(262,281,13);
floodfill(308,281,13);
floodfill(284,251,13);
floodfill(284,295,13);
/////////////////////////////////////road
setfillstyle(9,0);      ///////////////color

floodfill(19,429,13);
floodfill(81,419,13);
floodfill(151,409,13);
floodfill(211,397,13);
floodfill(271,380,13);
floodfill(331,368,13);
floodfill(396,355,13);
floodfill(450,345,13);
floodfill(510,335,13);
floodfill(570,325,13);
floodfill(630,312,13);
///////////////////////////////////////////////////////
floodfill(20,197,13);
floodfill(80,187,13);
floodfill(133,174,13);
floodfill(517,86,13);
floodfill(557,81,13);
floodfill(627,70,13);
/////////////////////////////
setfillstyle(1,0);
floodfill(14,314,12);
floodfill(617,183,12);

setfillstyle(6,10);            /////////////ty

floodfill(536,213,13);
floodfill(563,213,13);
floodfill(561,244,13);
floodfill(538,244,13);
floodfill(274,295,13);
floodfill(294,295,13);
floodfill(274,265,13);
floodfill(294,265,13);
////////////////////////////////////////////////road
setfillstyle(9,14);/////////////////////////////////////////color
floodfill(81-40+5,419+7,13);
floodfill(151-40,409+7,13);
floodfill(211-40,397+7,13);
floodfill(271-40,380+7,13);
floodfill(331-40,368+7,13);
floodfill(396-40,355+7,13);
floodfill(450-40,345+7,13);
floodfill(510-40,335+7,13);
floodfill(570-40,325+7,13);
floodfill(630-40,312+7,13);
/////////////////////////////////////////

floodfill(50,197,13);
floodfill(110,177,13);
floodfill(166,165,13);
floodfill(527,86,13);
floodfill(587,71,13);
setfillstyle(1,14);
floodfill(64,303,12);

setfillstyle(9,4);
floodfill(302+248,230,13);
floodfill(302+248+v,230+b,13);

delay(20);
setfillstyle(1,14);

floodfill(200,250,13);

floodfill(170,250,13);
 floodfill(80,230,13);

 delay(20);
setfillstyle(1,0);

floodfill(200,250,13);

floodfill(170,250,13);
 floodfill(80,230,13);


}
if(t==’p’)
{
int n=0;
while(!kbhit())
{
if(n<=60)
n++;
setcolor(0);
rectangle(1+1,-10,90-1,-12+n);
delay(14);

setcolor(9);
rectangle(1,-10,90,-10+n);
if(n==60)
{

outtextxy(10,10,”L-LIGHTS”);
outtextxy(10,20,”H-HORN”);
//outtextxy(10,30,”T-AllOY”);
 delay(400);
 }
}
setcolor(0);
rectangle(1,-10,90,-10+n);
rectangle(1,-10,90,-11+n);
outtextxy(10,10,”L-LIGHTS”);
outtextxy(10,20,”H-HORN”);
//outtextxy(10,30,”T-AllOY”);

}
}
circle(300,100,3);

nosound();

getch();
}

/*WELL THIS IS MY FIRST ATTEMPT IN GRAPHICS PROGRAMMING, IF YOU HAVE ANY QUERY OR ANY PROBLEM JUST MAIL ME TO animeshshaw59@gmail.com*/

GRAPHICS PROGRAMMING IN C


To start with graphics programming, Turbo C is a good choice. Even though DOS has its own limitations, it is having a large number of useful functions and is easy to program. To implement graphics algorithms, To give graphical display of statistics, To view signals from any source, we can use C graphics. Here is a article to start programming with Turbo C. ‘Run and Learn’ is our method. We have used source codes throughout the explanations. Just execute them to understand what is happening.

Turbo C has a good collection of graphics libraries. If you know the basics of C, you can easily learn graphics programming. To start programming, let us write a small program that displays a circle on the screen.
/* simple.c
example 1.0
*/
#include<graphics.h>
#include<conio.h>

void main()
{
int gd=DETECT, gm;

initgraph(&gd, &gm, “c:\\turboc3\\bgi ” );
circle(200,100,150);

getch();
closegraph();
}

To run this program, you need graphics.h header file, graphics.lib library file and Graphics driver (BGI file) in the program folder. These files are part of Turbo C package. In all our programs we used 640×480 VGA monitor. So all the programs are according to that specification. You need to make necessary changes to your programs according to your screen resolution. For VGA monitor, graphics driver used is EGAVGA.BGI.

Here, initgraph() function initializes the graphics mode and clears the screen. We will study the difference between text mode and graphics mode in detail latter.
InitGraph:

Initializes the graphics system.

Declaration:
void far initgraph(int far *graphdriver, int far *graphmode, char far *pathtodriver);

Remarks: To start the graphics system, you must first call initgraph.

initgraph initializes the graphics system by loading a graphics driver from disk (or validating a registered driver) then putting the system into graphics mode.

initgraph also resets all graphics settings (color, palette, current position, viewport, etc.) to their defaults, then resets graphresult to 0.
Arguments:

*graphdriver: Integer that specifies the graphics driver to be used. You can give graphdriver a value using a constant of the graphics drivers enumeration type.

*graphmode : Integer that specifies the initial graphics mode (unless *graphdriver = DETECT). If *graphdriver = DETECT, initgraph sets *graphmode to the highest resolution available for the detected driver. You can give *graphmode a value using a constant of the graphics_modes enumeration type.

pathtodriver : Specifies the directory path where initgraph looks for graphics drivers (*.BGI) first. If they’re not there, initgraph looks in the current directory. If pathtodriver is null, the driver files must be in the current directory. This is also the path settextstyle searches for the stroked character font files (*.CHR).

closegraph() function switches back the screen from graphcs mode to text mode. It clears the screen also. A graphics program should have a closegraph function at the end of graphics. Otherwise DOS screen will not go to text mode after running the program. Here, closegraph() is called after getch() since screen should not clear until user hits a key.

If you have the BGI file in the same folder of your program, you can just leave it as “” only. you need not mention *graphmode if you give *graphdriver as DETECT.

To get details of different graphics modes and graphics drivers, view appendix.

In graphics mode, all the screen co-ordinates are mentioned in terms of pixels. Number of pixels in the screen decides resolution of the screen. In the example 1.0, circle is drawn with x-coordinate of the center 200, y-coordinate 100 and radius 150 pixels. All the coordinates are mentioned with respect to top-left corner of the screen.

Basic Shapes and Colors:

Now let us write a program to draw some basic shapes. /*
shapes.c
example 1.1
*/

#include<graphics.h>
#include<conio.h>

void main()
{
int gd=DETECT, gm;
int poly[12]={350,450, 350,410, 430,400, 350,350, 300,430, 350,450 };
initgraph(&gd, &gm, “”);

circle(100,100,50);
outtextxy(75,170, “Circle”);
rectangle(200,50,350,150);
outtextxy(240, 170, “Rectangle”);
ellipse(500, 100,0,360, 100,50);
outtextxy(480, 170, “Ellipse”);
line(100,250,540,250);
outtextxy(300,260,”Line”);

sector(150, 400, 30, 300, 100,50);
outtextxy(120, 460, “Sector”);
drawpoly(6, poly);
outtextxy(340, 460, “Polygon”);
getch();
closegraph();
}

Here is the screenshot of output:

Here, circle() function takes x, y coordinates of the circle with respect to left top of the screen and radius of the circle in terms of pixels as arguments. Not that, in graphics, almost all the screen parameters are measured in terms of pixels.

Function outtextxy() displays a string in graphical mode. You can use different fonts, text sizes, alignments, colors and directions of the text that we will study later. Parameters passed are x and y coordinates of the position on the screen where text is to be displayed. There is another function outtext() that displayes a text in the current position. Current position is the place where last drawing is ended. These functions are declared as follows:

void far outtextxy(int x, int y, char *text);
void far outtext(char *text);

Circle, arc, pieslice are declared as follows:Declaration:
void far arc(int x, int y, int stangle, int endangle, int radius);
void far circle(int x, int y, int radius);
void far pieslice(int x, int y, int stangle, int endangle, int radius);

Remarks:
arc draws a circular arc in the current drawing color.
circle draws a circle in the current drawing color.
pieslice draws a pie slice in the current drawing color, then fills it using
the current fill pattern and fill color.

Arguments:
(x,y): Center point of arc, circlew, or pie slice
stangle: Start angle in degrees
endangle: End angle in degrees
radius: Radius of arc, circle, and pieslice

Here, stangle and endangle are in degrees starting from the +ve x-axis in the polar coordinate system in the anti-clockwise direction. if stangle is 0, endangle is 360, it will draw a full circle. Refer this figure for clear idea: For the details of current color, fill color and fill patterns, refer the sections Lines and Colors.

Another basic shape that we come across is a rectangle. To draw a border, use rectangle with the coordinates of outline, to draw a square use rectangle with same height and width. drawpoly() and fillpoly() are two functions useful to draw any polygons. To use these functions, store coordinates of the shape in an array and pass the address of array as an argument to the function. By looking at the output of the previous program, you can understand what drawpoly is. fillpoly is similar except that it fills in the shape with current fill color.
Declaration:

void far rectangle(int left, int top, int right, int bottom);

void far drawpoly(int numpoints, int far *polypoints);

void far fillpoly(int numpoints, int far *polypoints);

Remarks:

rectangle draws a rectangle in the current line style, thickness, and drawing color.

drawpoly draws a polygon using the current line style and color.

fillpoly draws the outline of a polygon using the current line style and color, then fills the polygon using the current fill pattern and fill color.

Arguments:

(left,top) is the upper left corner of the rectangle, and (right,bottom) is its lower right corner.

numpoints: Specifies number of points

*polypoints: Points to a sequence of (numpoints x 2) integers. Each pair of integers gives the x and y coordinates of a point on the polygon.

To draw a closed polygon with N points, numpoints should be N+1 and the array polypoints[] should contain 2(N+1) integers with first 2 integers equal to last 2 integers.

Let us study more about shapes latter. Here is some idea about colors. There are 16 colors declared in graphics.h as listed bellow.
BLACK: 0
BLUE: 1
GREEN: 2
CYAN: 3
RED: 4
MAGENTA: 5
BROWN: 6
LIGHTGRAY: 7
DARKGRAY: 8
LIGHTBLUE: 9
LIGHTGREEN: 10
LIGHTCYAN: 11
LIGHTRED: 12
LIGHTMAGENTA: 13
YELLOW: 14
WHITE: 15

To use these colors, use functions setcolor(), setbkcolor() and setfillstyle(). setcolor() function sets the current drawing color. If we use setcolor(RED); and draw any shape, line or text after that, the drawing will be in red color. You can either use color as defined above or number like setcolor(4);. setbkcolor() sets background color for drawing. Setfillstyle sets fill pattern and fill colors. After calling setfillstyle, if we use functions like floodfill, fillpoly, bar etc, shpes will be filled with fill color and pattern set using setfillstyle. These function declarations are as follows.Declaration:
void far setfillstyle(int pattern, int color);
void far setcolor(int color);
void far setbkcolor(int color);

Remarks:
setfillstyle sets the current fill pattern and fill color.
setcolor sets the current drawing color to color, which can range from 0 to getmaxcolor.
setbkcolor sets the background to the color specified by color.

The parameter pattern in setfillstyle is as follows: Names Value Means Fill With…
EMPTY_FILL 0 Background color
SOLID_FILL 1 Solid fill
LINE_FILL 2 —
LTSLASH_FILL 3 ///
SLASH_FILL 4 ///, thick lines
BKSLASH_FILL 5 \\\, thick lines
LTBKSLASH_FILL 6 \\\
HATCH_FILL 7 Light hatch
XHATCH_FILL 8 Heavy crosshatch
INTERLEAVE_FILL 9 Interleaving lines
WIDE_DOT_FILL 10 Widely spaced dots
CLOSE_DOT_FILL 11 Closely spaced dots
USER_FILL 12 User-defined fill pattern

Here is an example program with colors, pixels, bar, cleardevice etc. stdlib.h is used for random number generation. We have a function random(no), it returns a random number between 0 an no. The effect is by drawing random radius, random color circles with same center and random pixels. kbhit() function(defined in conio.h) returns a nonzero value when a key is pressed in the keyboard. So, the loop will continue until a key is pressed.
/*
random.c
some graphics effects using random numbers.
example 1.2
by HarshaPerla, http://eharsha.tk
*/

#include “graphics.h”
#include “conio.h”
#include “stdlib.h”

void main()
{
int gd,gm;
gd=DETECT;

initgraph(&gd, &gm, “”);
setcolor(3);
setfillstyle(SOLID_FILL,RED);
bar(50, 50, 590, 430);

setfillstyle(1, 14);
bar(100, 100, 540, 380);

while(!kbhit())
{
putpixel(random(439)+101, random(279)+101,random(16));
setcolor(random(16));
circle(320,240,random(100));
}
getch();
closegraph();
}

CLOCK PROGRAM IN C


#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <graphics.h>
#include <dos.h>
#include <math.h>
void main()
{
struct time t;
void drawclock(void);
void intro(void);
void sound(void);
int gd=DETECT,gm;
initgraph(&gd,&gm,”c:\tc\bgi”);
int i,j,k,s,m,h;
intro();
settextstyle(DEFAULT_FONT, HORIZ_DIR, 1);
drawclock();
gettime(&t);

if(t.ti_sec>15)
s=360-((t.ti_sec-15)*6);
else
s=90-(t.ti_sec*6);

if(t.ti_min>15)
m=360-((t.ti_min-15)*6);
else
m=90-(t.ti_min*6);

if( (t.ti_hour==0)||(t.ti_hour==1)||(t.ti_hour==2)||(t.ti_hour==3))
h=90-(t.ti_hour*30)-((t.ti_min/12)*6);
else if((t.ti_hour>=4)&&(t.ti_hour<=12)) h=360-((t.ti_hour-3)*30)-((t.ti_min/12)*6); else if((t.ti_hour>=13)&&(t.ti_hour<=23))
h=360-((t.ti_hour-15)*30)-((t.ti_min/12)*6);
else// if(t.ti_hour==12)
h=90-((t.ti_hour-12)*30)-((t.ti_min/12)*6);

for(k=0;k<=12;k++)
{
if(h==0)
h=360;
delay(1000);
drawclock();
for(j=0;j<=60;j++)
{
if(m==0)
m=360;
setcolor(4);
sector(320,150,m,m+1,75,75);
m=m-6;
delay(1000);
drawclock();
for(i=0;i<=60;i++)
{
setcolor(4);
sector(320,150,h,h+3,60,60);
setcolor(4);
sector(320,150,m,m+1,75,75);
if(s==0)
s=360;
setcolor(1);
sector(320,150,s,s+1,80,80);
sound();
s=s-6;
delay(1000);
drawclock();
if(kbhit())
exit(0);
}
setcolor(6);
sector(320,150,h,h+3,60,60);
}
}
getch();
}
void drawclock()
{
cleardevice();
setbkcolor(15);
setcolor(1);
circle(320,150,80);
setcolor(5);
circle(320,150,95);
circle(320,150,1);
outtextxy(314,58,”12″);
outtextxy(268,70,”11″);
outtextxy(235,105,”10″);
outtextxy(233,147,”9″);
outtextxy(241,190,”8″);
outtextxy(273,225,”7″);
outtextxy(318,238,”6″);
outtextxy(362,225,”5″);
outtextxy(392,190,”4″);
outtextxy(403,147,”3″);
outtextxy(393,105,”2″);
outtextxy(361,70,”1″);
outtextxy(302,200,”TILAK”);
}
void intro()
{
int i;
int u=installuserfont(“TSCR.CHR”);
settextstyle(u,0,7);
outtextxy(175,100,”TILAK’s”);
outtextxy(250,200,”CLOCK”);
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 1);
outtextxy(380,400,”Loading..”);

for(i=0;i<510;i++)
{
setcolor(15);
rectangle(50,100,50+i,110);
delay(5);
}
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 1);
outtextxy(380,400,”Loading….”);

for( i=0;i<510;i++)
{
setcolor(4);
rectangle(50,100,50+i,110);
delay(5);
}

settextstyle(TRIPLEX_FONT, HORIZ_DIR, 1);
outtextxy(380,400,”Loading……”);

for(i=0;i<510;i++)
{
setcolor(15);
rectangle(50,200,50+i,210);
delay(5);
}
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 1);
outtextxy(380,400,”Loading……..”);

setfillstyle(SOLID_FILL,1);
fillellipse(320,205,6,6);
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 1);
outtextxy(380,400,”Loading……….”);

for(i=0;i<510;i++)
{
setcolor(15);
rectangle(50,300,50+i,310);
delay(5);
}
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 1);
outtextxy(380,400,”Loading…………”);

for( i=0;i<510;i++)
{
setcolor(2);
rectangle(50,300,50+i,310);
delay(5);
}
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 1);
outtextxy(380,400,”Loading…………..”);
delay(1000);
}
void sound()
{
sound(2000);
delay(100);
nosound();
}