Output Video
/* WAP in C & C++ to run a Car ,when user get input ‘w’,’s’,’a’,’d’ and when click ‘e’ to exit . */
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<stdlib.h>
void main()
{
int gd=DETECT,gm,i,j,l,m=0,n=0,x,y,z;
char k;
initgraph(&gd,&gm,”..\\BGI”);
k=’g’;
for(i=0,j=0;k!=’e’; )
{
arc(100,200+j,10-i,330-i,10);
arc(200,200+j,0-i,320-i,10);
line(110,200+j,190,200+j);
line(210,200+j,250,200+j);
line(90,200+j,50,200+j);
line(50,200+j,80,170+j);
line(250,200+j,220,170+j);
line(80,170+j,220,170+j);
line(100,170+j,120,150+j);
line(200,170+j,180,150+j);
line(120,150+j,180,150+j);
line(135,150+j,135,170+j);
line(165,150+j,165,170+j);
line(310-i,210+n,500-i,210+n);
line(310-m,210+n,500-m,210+n);
if(i==500)
i=0;
else if(i==280)
m=0;
k=getch();
if(k==’d’)
{
i=i+10;
m=m+10;
}
else if(k==’a’)
{
i=i-10;
m=m-10;
}
else if(k==’w’)
{
j=j-10;
n=n-10;
}
else if(k==’s’)
{
j=j+10;
n=n+10;
}
clearviewport();
}
getch();
closegraph();
}
Output
You should check these programs in C & C++
Draw Shoulin Symbol in C & C++
Standard Calculator in C & C++ (Calculator, Algebra, Statistics)
/*WAP of Car Run on running road Press= W , S, A , D ,”(CAR_RUN3.cpp)” */
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<stdlib.h>
void car(int *i,int *j);
void control(char *k,int *i,int *j);
void road(int *r,int *a,int *i,int *j);
void main()
{
int gd=DETECT,gm;
int i=0,j=0;
int r=0,a=0; //,d=0;
char k=’a’,rd;
initgraph(&gd,&gm,”..\\BGI”);
do
{
car(&i,&j);
do
{
road(&r,&a,&i,&j);
}while(!kbhit());
control(&k,&i,&j);
clearviewport();
}while(k!=’e’);
//setbkcolor(BLUE);
getch();
closegraph();
}
void car(int *i,int *j)
{
arc(100+*i,200+*j,10-*i,330-*i,10);
arc(200+*i,200+*j,0-*i,320-*i,10);
line(110+*i,200+*j,190+*i,200+*j);
line(210+*i,200+*j,250+*i,200+*j);
line(90+*i,200+*j,50+*i,200+*j);
line(50+*i,200+*j,80+*i,170+*j);
line(250+*i,200+*j,220+*i,170+*j);
line(80+*i,170+*j,220+*i,170+*j);
line(100+*i,170+*j,120+*i,150+*j);
line(200+*i,170+*j,180+*i,150+*j);
line(120+*i,150+*j,180+*i,150+*j);
line(135+*i,150+*j,135+*i,170+*j);
line(165+*i,150+*j,165+*i,170+*j);
}
void control(char *k,int *i,int *j)
{
*k=getch();
if(*k==’d’)
{
*i=*i+10;
}
else if(*k==’a’)
{
*i=*i-10;
}
else if(*k==’w’)
{
*j=*j-10;
}
else if(*k==’s’)
{
*j=*j+10;
}
else if(*k==’e’)
exit;
}
void road(int *r,int *a,int *i,int *j)
{
{
clearviewport();
car(i,j);
line(310-*a,210,500-*a,210);
line(310-*r,210,500-*r,210);
if(*a==500)
*a=0;
else if(*a==280)
*r=0;
*r=*r+10;
*a=*a+10;
delay(30);
}}
Output
You should check these programs in C & C++
Draw Shoulin Symbol in C & C++
Standard Calculator in C & C++ (Calculator, Algebra, Statistics)