Saturday, November 29, 2014

C++ Model pro



Program to enter an integer and find out if it is even or odd

#include 
#include 
void main()
{
clrscr();
int x;
cout << "Enter an integer : ";
cin>>x;
if(x%2==0)
cout << "The number " << x << " is even.";
else
cout << "The number " << x << " is odd.";
getch();
}
 
Output
 
The number 86 is even.

Program to enter two integers and print the quotient and remainder

#include 
#include 
int main()
{
clrscr();
int x,y,quotient,remainder;
cout << "Enter 2 integers greater than 0 : ";
cin>>x>>y;
quotient=x/y;
remainder=x-(quotient*y);
cout << "Quotient of " << x << " & " << y << " = " << quotient << "\n";
cout << "Remainder" << " = " << remainder << "\n";
getch();
return 0;
}
 
Output
 
Quotient of 23 & 4 = 5
Remainder = 3

Program to plot pixels

#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=40;x<120 x="x+10)</span">
{
putpixel(x,200,14); color(14)
getch();
}
}

Program to construct a 3-dimensional bar

#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); 
}
setfillstyle(Empty_fill,0);
bar3d(200,200,300,450,10,1);
getch();
closegraph();
}

Program to write in different fonts on the screen

#include 
#include 
#include 
#include 
void main (int)
{
int gdriver=Detect,gmode,errorcode; 
int midx,midy,fstyle;
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); 
}
cleardevice();
settextstyle(Default_font,horiz_dir,4);
outtextxy(200,200,"Default font");
getch();
cleardevice();
settextstyle(Triplex_font,vert_dir,5);
outtextxy(200,200,"Triplex font");
getch();
cleardevice();
settextstyle(Gothic_font,horiz_dir,5);
outtextxy(200,200,"Gothic font");
getch();
cleardevice();
settextstyle(Small_font,vert_dir,5);
outtextxy(200,200,"Small font");
getch();
cleardevice();
settextstyle(Sans_serif_font,horiz_dir,5);
outtextxy(200,200,"Sans Serif font");
getch();
closegraph();
}

No comments:

Post a Comment