Friends here I am introducing a new code for temperature converter. This is a graphical converter that you can use and run with your converter. Hope you like this thanks.
#include
#include
#include
#include
#include
#include
#include
//////////////////////
int xfm1=200,xfm2=230,chf1=0,chf2=0,ex1=0,ex2=0;
void calshp();
void main()
{
int gdriver = DETECT, gmode;
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
char ch,mv;
float cel,f,k,temp;
calshp();
/////////////////////////////////////////////////////////////////////////////
gotoxy(23,10);
cin>>temp;
do
{ calshp();
if(mv==72)
{ chf1-=30;
chf2-=30;
}
if(mv==80)
{chf1+=30;
chf2+=30;
}
if(chf1>180)
{
chf1=0;
chf2=0;
}
if(chf1<0)
{ chf1=180,chf2=180;}
if(chf1==180)
{ex1=70,ex2=80;}
if(chf1!=180)
{ex1=0,ex2=0;}
setcolor(BLUE);
rectangle(160+ex1,xfm1+chf1,430-ex2,xfm2+chf2);
mv=getche();
}
while(mv!=13);
if(chf1==0)
{
ch=1; }
else if(chf1==30)
{
ch=2;
}
else if(chf1==60)
{
ch=3;
}
else if(chf1==90)
{
ch=4;
}
else if(chf1==120)
{
ch=5;
}
else if(chf1==150)
{
ch=6;
}
////////////////////////////////////////////////////////////////////////////
switch(ch)
{
case 1:
cel=5*(temp-32)/9;
gotoxy(23,10);
cout<
gotoxy(40,10);
cout<
break;
case 2:
f=9*(temp+32)/5;
gotoxy(23,10);
cout<
gotoxy(40,10);
cout<
break;
case 3:
k=temp+273;
gotoxy(23,10);
cout<
gotoxy(40,10);
cout<
break;
case 4:
cel=273-temp;
gotoxy(23,10);
cout<
gotoxy(40,10);
cout<
break;
case 5:
cel=5*(temp-32)/9;
k=cel+273;
gotoxy(23,10);
cout<
gotoxy(40,10);
cout<
break;
case 6:
cel=273-temp;
f=9*(cel+32)/5;
gotoxy(23,10);
cout<
gotoxy(40,10);
cout<
break;
}
getche();
}
void calshp()
{
setcolor(RED);
settextstyle(4,0,6);
outtextxy(90,4,"Temprature Converter");
rectangle(70,10,580,70);
/////////////////////////////////////////////////////////////////////
settextstyle(0,0,0);
rectangle(130,135,460,165);
rectangle(130,135,290,165);
outtextxy(180,125,"Input");
outtextxy(340,125,"Output");
rectangle(160,xfm1,430,xfm2);
rectangle(160,xfm1+30,430,xfm2+30);
rectangle(160,xfm1+60,430,xfm2+60);
rectangle(160,xfm1+90,430,xfm2+90);
rectangle(160,xfm1+120,430,xfm2+120);
rectangle(160,xfm1+150,430,xfm2+150);
rectangle(230,xfm1+180,350,xfm2+180);
outtextxy(190,210,"Fahrenheit To Celsius");
outtextxy(190,240,"Celsius To Fahrenheit");
outtextxy(190,270,"Celsius To Kalvin");
outtextxy(190,300,"Kalvin To Celsius");
outtextxy(190,330," Fahrenheit To Kalvin");
outtextxy(190,360," Kalvin To Fahrenheit");
outtextxy(270,390,"Exit");
setcolor(BLUE);
rectangle(10,425 ,620,477);
settextstyle(0,0,1);
outtextxy(16,430,"NAME: Muhammad Waqas");
outtextxy(16,445,"Roll # 9275");
outtextxy(16,460,"Class : BCs-A(2011 - 2014)");
outtextxy(400,430,"S u b m e t t e d T o");
outtextxy(380,460,"S i r . U m e r H a y a t");
settextstyle(4,0,16);
outtextxy(30,180,"T T");
}
#include
#include
#include
#include
#include
#include
#include
//////////////////////
int xfm1=200,xfm2=230,chf1=0,chf2=0,ex1=0,ex2=0;
void calshp();
void main()
{
int gdriver = DETECT, gmode;
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
char ch,mv;
float cel,f,k,temp;
calshp();
/////////////////////////////////////////////////////////////////////////////
gotoxy(23,10);
cin>>temp;
do
{ calshp();
if(mv==72)
{ chf1-=30;
chf2-=30;
}
if(mv==80)
{chf1+=30;
chf2+=30;
}
if(chf1>180)
{
chf1=0;
chf2=0;
}
if(chf1<0)
{ chf1=180,chf2=180;}
if(chf1==180)
{ex1=70,ex2=80;}
if(chf1!=180)
{ex1=0,ex2=0;}
setcolor(BLUE);
rectangle(160+ex1,xfm1+chf1,430-ex2,xfm2+chf2);
mv=getche();
}
while(mv!=13);
if(chf1==0)
{
ch=1; }
else if(chf1==30)
{
ch=2;
}
else if(chf1==60)
{
ch=3;
}
else if(chf1==90)
{
ch=4;
}
else if(chf1==120)
{
ch=5;
}
else if(chf1==150)
{
ch=6;
}
////////////////////////////////////////////////////////////////////////////
switch(ch)
{
case 1:
cel=5*(temp-32)/9;
gotoxy(23,10);
cout<
gotoxy(40,10);
cout<
break;
case 2:
f=9*(temp+32)/5;
gotoxy(23,10);
cout<
gotoxy(40,10);
cout<
break;
case 3:
k=temp+273;
gotoxy(23,10);
cout<
gotoxy(40,10);
cout<
break;
case 4:
cel=273-temp;
gotoxy(23,10);
cout<
gotoxy(40,10);
cout<
break;
case 5:
cel=5*(temp-32)/9;
k=cel+273;
gotoxy(23,10);
cout<
gotoxy(40,10);
cout<
break;
case 6:
cel=273-temp;
f=9*(cel+32)/5;
gotoxy(23,10);
cout<
gotoxy(40,10);
cout<
break;
}
getche();
}
void calshp()
{
setcolor(RED);
settextstyle(4,0,6);
outtextxy(90,4,"Temprature Converter");
rectangle(70,10,580,70);
/////////////////////////////////////////////////////////////////////
settextstyle(0,0,0);
rectangle(130,135,460,165);
rectangle(130,135,290,165);
outtextxy(180,125,"Input");
outtextxy(340,125,"Output");
rectangle(160,xfm1,430,xfm2);
rectangle(160,xfm1+30,430,xfm2+30);
rectangle(160,xfm1+60,430,xfm2+60);
rectangle(160,xfm1+90,430,xfm2+90);
rectangle(160,xfm1+120,430,xfm2+120);
rectangle(160,xfm1+150,430,xfm2+150);
rectangle(230,xfm1+180,350,xfm2+180);
outtextxy(190,210,"Fahrenheit To Celsius");
outtextxy(190,240,"Celsius To Fahrenheit");
outtextxy(190,270,"Celsius To Kalvin");
outtextxy(190,300,"Kalvin To Celsius");
outtextxy(190,330," Fahrenheit To Kalvin");
outtextxy(190,360," Kalvin To Fahrenheit");
outtextxy(270,390,"Exit");
setcolor(BLUE);
rectangle(10,425 ,620,477);
settextstyle(0,0,1);
outtextxy(16,430,"NAME: Muhammad Waqas");
outtextxy(16,445,"Roll # 9275");
outtextxy(16,460,"Class : BCs-A(2011 - 2014)");
outtextxy(400,430,"S u b m e t t e d T o");
outtextxy(380,460,"S i r . U m e r H a y a t");
settextstyle(4,0,16);
outtextxy(30,180,"T T");
}
More C++ and C codes:
Hope you like theses codes. Thanks
No comments:
Post a Comment