Saturday, November 29, 2014

C++ Graphics pro



Program to change the foreground colors and draw circles on the screen

#include 
#include 
#include 
#include 
void main (int)
{
int gdriver=Detect,gmode,errorcode; 
int midx,midy,x;
initgraph(&gdriver,&gmode,"d:\\bc3\\bgi");
errorcode=graphresult();
if(errorcode!=grOk)
{
printf("Graphics error occurred : %s \n",grapherrormsg(errorcode));
printf("Press any key to stop : ");
getch();
exit(1); 
}
for(x=15;x>=0;x--)
{
setcolor(x);
circle(20+(x*40),200,15);
getch();
}
cleardevice(); 
circle(200,200,50);
getch();
closegraph();
}

Program to change the background colors on the screen

#include 
#include 
#include 
#include 
void main (int)
{
int gdriver=Detect,gmode,errorcode; 
int midx,midy,x;
initgraph(&gdriver,&gmode,"d:\\bc3\\bgi");
errorcode=graphresult();
if(errorcode!=grOk)
{
printf("Graphics error occurred : %s \n",grapherrormsg(errorcode));
printf("Press any key to stop : ");
getch();
exit(1); 
}
for(x=0;x<=15;x++)
{
setbkcolor(x);
getch();
}
closegraph();
}

Program to draw circles

#include 
#include 
#include 
#include 
#include 
#include 
void main()
{
clrscr();
int gd=Detect,gm,errorcode; 
initgraph(&gd,&gm,"d:\\bc3\\bgi"); 
errorcode=graphresult();
if (errorcode!=grOk)
{
cout << "Graphics error occured : \n" << grapherrormsg(errorcode) << endl;
cout << "Press any key to stop : ";
getch();
exit(1);
}
circle(200,200,50); 
getch();
circle(300,203,40); 
getch();
circle(500,303,80); 
getch();
closegraph();
}

Program to draw 2 rectangles and fill 1 of them

#include 
#include 
#include 
#include 
#include 
#include 
void main()
{
  clrscr();
  int gd = Detect,gm,errorcode; 
 
  
  initgraph (&gd, &gm, "d:\\bc3\\bgi"); 
  errorcode = graphresult();
  if (errorcode != grOk)
    {
      cout << "Graphics error occured : \n" << grapherrormsg(errorcode) << endl;
      cout << "Press any key to stop : ";
      getch();
      exit(1);
    }
  rectangle(300, 300, 600, 400);
  rectangle(100, 100, 200, 200);
  getch();
  floodfill(120, 120, White);
  getch();
  closegraph();
}

Program to enter an integer and print out its successor

#include 
#include 
void value(int);
void main()
{
clrscr();
int x;
cout << "Enter an integer : ";
cin>>x;
cout << "The successor of " << x << " is ";
value(x);
getch();
}
void value(int x)
{
x++;
cout << x << "." << endl;
}

Program to enter an integer and output the cube of that integer

#include 
#include 
int cube(int x); 
void main()
{
clrscr();
int a;
cout << "Enter an integer : ";
cin>>a;
cout << "The cube of " << a << " is : " << cube(a) << endl; 
getch();
}
int cube(int x)
{
int y;
y=x*x*x;
return(y);
}
 
Output
       
      The cube of 8 is : 512

No comments:

Post a Comment