Charging Battery Code in C++ (Using Graphics)

C language has been fun to play with. If you don't know the concept, it could give you heartbreak. On the other hand, it could make your day if you're very well aware of the ins and outs of it. If you've been visiting this blog, you would have checked out another C++ program that I had written or was about "Piano".

This one is about showing "Charging Battery" using the Graphics.h header file. Remember, this has nothing to do with the current battery status of the computer (i.e. how much power is currently remaining) - it is just the graphical representation of how a battery can be designed using a programming language.

I've made use of three header files: graphics.h, dos.h, and conio.h. I didn't even have to use iostream.h, nor did I use stdio.h since there is no predefined function used in the source code. So, it would be redundant if I did that.

Source Code:

#include<graphics.h>
#include<dos.h>
#include<conio.h>
void nill()
{
setfillstyle(1,2);
bar(310,191,340,185);//
rectangle(300,195,350,300);//Body
}
void tw()
{
setfillstyle(1,RED);
bar(305,295,345,280);//First cell
}
void fo()
{
setfillstyle(1,YELLOW);
bar(305,275,345,260);//Second cell
}
void si()
{
setfillstyle(1,YELLOW);
bar(305,255,345,240);//Third cell
}
void ei()
{
setfillstyle(1,GREEN);
bar(305,235,345,220);//Fourth cell
}
void full()
{
setfillstyle(1,GREEN);
bar(305,215,345,200);//First cell
}
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\turboc3\\bgi");
while(!kbhit())
{
outtextxy(50,50,"Designed by Saifullah");
outtextxy(400,400,"Press any key to Exit");
nill();
outtextxy(50,50,"Designed by Saifullah");
outtextxy(280,350,"Battery Nill");
outtextxy(400,400,"Press any key to Exit");
delay(500);
cleardevice();
nill();
tw();
outtextxy(50,50,"Designed by Saifullah");
outtextxy(280,350,"Battery 20%");
outtextxy(400,400,"Press any key to Exit");
delay(500);
cleardevice();
nill();
tw();
fo();
outtextxy(50,50,"Designed by Saifullah");
outtextxy(280,350,"Battery 40%");
outtextxy(400,400,"Press any key to Exit");
delay(500);
cleardevice();
nill();
tw();
fo();
si();
outtextxy(50,50,"Designed by Saifullah");
outtextxy(280,350,"Battery 60%");
outtextxy(400,400,"Press any key to Exit");
delay(500);
cleardevice();
nill();
tw();
fo();
si();
ei();
outtextxy(50,50,"Designed by Saifullah");
outtextxy(280,350,"Battery 80%");
outtextxy(400,400,"Press any key to Exit");
delay(500);
cleardevice();
nill();
tw();
fo();
si();
ei();
full();
outtextxy(50,50,"Designed by Saifullah");
outtextxy(280,350,"Battery Full");
outtextxy(400,400,"Press any key to Exit");
delay(500);
cleardevice();
}
getch();
}

There you have it - the Charging Battery Code in C/C++! If you've any questions regarding this source code, feel free to reach out to me via the comment section. 

No comments:

The questions that are off the topic will be deleted!

Powered by Blogger.