Temperature converter c++ code
#include<iostream.h>
#include<graphics.h>#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
int xf1=200,xf2=230,chf1=0,chf2=0,ex1=0,ex2=0;
void calshp();
void main()
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
clrscr();
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,xf1+chf1,430-ex2,xf2+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<<temp<<" F";
gotoxy(40,10);
cout<<cel<<" C";
break;
case 2:
f=9*(temp+32)/5;
gotoxy(23,10);
cout<<temp<<" C";
gotoxy(40,10);
cout<<cel<<" F";
break;
case 3:
k=temp+273;
gotoxy(23,10);
cout<<temp<<" C";
gotoxy(40,10);
cout<<cel<<" K";
break;
case 4:
cel=273-temp;
gotoxy(23,10);
cout<<temp<<" K";
gotoxy(40,10);
cout<<cel<<" C";
break;
case 5:
cel=5*(temp-32)/9;
k=cel+273;
gotoxy(23,10);
cout<<temp<<" F";
gotoxy(40,10);
cout<<k<<" K";
break;
case 6:
cel=273-temp;
f=9*(cel+32)/5;
gotoxy(23,10);
cout<<temp<<" K";
gotoxy(40,10);
cout<<f<<" F";
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,xf1,430,xf2);
rectangle(160,xf1+30,430,xf2+30);
rectangle(160,xf1+60,430,xf2+60);
rectangle(160,xf1+90,430,xf2+90);
rectangle(160,xf1+120,430,xf2+120);
rectangle(160,xf1+150,430,xf2+150);
rectangle(230,xf1+180,350,xf2+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");
}
No comments:
Post a Comment