Saturday, July 6, 2013

Temperature Conversion using C++

Google Temperature Conersion

This is a simple tutorial for conversion of temperature scales to Celsius or Fahrenheit or Kelvin using C++ program. The same can also easily performed using Google search using the letters c, f, and k. In this tutorial, I have used Turbo C++ v3.0 software for compiling the C++ program.

Temperature Conversion and Google Search

The general temperature conversion formulas and Google search methods such as Fahrenheit to Celsius, Celsius to Fahrenheit, Kelvin to Fahrenheit, Fahrenheit to Kelvin, Celsius to Kelvin, and Kelvin to Celsius are given below.

Temperature Conversion Formula Google Search
Fahrenheit to Celsius \[{{T}_{Celsius}}=({{T}_{Fahrenheit}}-32)\times \frac{5}{9}\] 86 f to c
Celsius to Fahrenheit \[{{T}_{Fahrenheit}}={{T}_{Celsius}}\times \frac{9}{5}+32\] 30 c to f
Kelvin to Fahrenheit \[{{T}_{Fahrenheit}}=\left( {{T}_{Kelvin}}\times \frac{9}{5} \right)-459.67\] 300 k to f
Fahrenheit to Kelvin \[{{T}_{Kelvin}}=({{T}_{Fahrenheit}}+459.67)\times \frac{5}{9}\] 30 f to k
Celsius to Kelvin \[{{T}_{Kelvin}}={{T}_{Celsius}}+273.15\] 5 c to k
Kelvin to Celsius \[{{T}_{Celsius}}={{T}_{Kelvin}}-273.15\] 300 k to c

Types of Temperature Conversion

The various type of temperature conversion and programming expressions for Fahrenheit, Celsius, Kelvin, Rankine, Delisle, Newton, Réaumur, and Rømer scales are given below.

ConversionFormulaExpression
Fahrenheit to Celsius\[{{T}_{Celsius}}=({{T}_{Fahrenheit}}-32)\times \frac{5}{9}\](x-32)×5÷9
Fahrenheit to Kelvin\[{{T}_{Kelvin}}=({{T}_{Fahrenheit}}+459.67)\times \frac{5}{9}\](x+459.67)×5÷9
Fahrenheit to Rankine\[{{T}_{Rankine}}={{T}_{Fahrenheit}}+459.67\]x+459.67
Fahrenheit to Delisle\[{{T}_{Delisle}}=(212-{{T}_{Fahrenheit}})\times \frac{5}{6}\](212-x)×5÷6
Fahrenheit to Newton\[{{T}_{Newton}}=({{T}_{Fahrenheit}}-32)\times \frac{11}{60}\](x-32)×11÷60
Fahrenheit to Réaumur\[{{T}_{R\acute{e}aumur}}=({{T}_{Fahrenheit}}-32)\times \frac{4}{9}\](x-32)×4÷9
Fahrenheit to Rømer\[{{T}_{Rømer}}=({{T}_{Fahrenheit}}-32)\times \frac{7}{24}+7.5\](x-32)×7÷24+7.5
Celsius to Fahrenheit\[{{T}_{Fahrenheit}}={{T}_{Celsius}}\times \frac{9}{5}+32\]x×9÷5+32
Celsius to Kelvin\[{{T}_{Kelvin}}={{T}_{Celsius}}+273.15\]x+273.15
Celsius to Rankine\[{{T}_{Rankine}}=({{T}_{Celsius}}+273.15)\times \frac{9}{5}\](x+273.15)×9÷5
Celsius to Delisle\[{{T}_{Delisle}}=(100-{{T}_{Celsius}})\times \frac{3}{2}\](100-x)×3÷2
Celsius to Newton\[{{T}_{Newton}}={{T}_{Celsius}}\times \frac{33}{100}\]x×33÷100
Celsius to Réaumur\[{{T}_{R\acute{e}aumur}}={{T}_{Celsius}}\times \frac{4}{5}\]x×4÷5
Celsius to Rømer\[{{T}_{Rømer}}={{T}_{Celsius}}\times \frac{21}{40}+7.5\]x×21÷40+7.5
Kelvin to Fahrenheit\[{{T}_{Fahrenheit}}=\left( {{T}_{Kelvin}}\times \frac{9}{5} \right)-459.67\](x×9÷5)-459.67
Kelvin to Celsius\[{{T}_{Celsius}}={{T}_{Kelvin}}-273.15\]x-273.15
Kelvin to Rankine\[{{T}_{Rankine}}={{T}_{Kelvin}}\times \frac{9}{5}\]x×9÷5
Kelvin to Delisle\[{{T}_{Delisle}}=(373.15-{{T}_{Kelvin}})\times \frac{3}{2}\](373.15-x)×3÷2
Kelvin to Newton\[{{T}_{Newton}}=({{T}_{Kelvin}}-273.15)\times \frac{33}{100}\](x-273.15)×33÷100
Kelvin to Réaumur\[{{T}_{R\acute{e}aumur}}=({{T}_{Kelvin}}-273.15)\times \frac{4}{5}\](x-273.15)×4÷5
Kelvin to Rømer\[{{T}_{Rømer}}=({{T}_{Kelvin}}-273.15)\times \frac{21}{40}+7.5\](x-273.15)×21÷40+7.5
Rankine to Fahrenheit\[{{T}_{Fahrenheit}}={{T}_{Rankine}}-459.67\]x-459.67
Rankine to Celsius\[{{T}_{Celsius}}=({{T}_{Rankine}}-491.67)\times \frac{5}{9}\](x-491.67)×5÷9
Rankine to Kelvin\[{{T}_{Kelvin}}={{T}_{Rankine}}\times \frac{5}{9}\]x×5÷9
Rankine to Delisle\[{{T}_{Delisle}}=(671.67-{{T}_{Rankine}})\times \frac{5}{6}\](671.67-x)×5÷6
Rankine to Newton\[{{T}_{Newton}}=({{T}_{Rankine}}-491.67)\times \frac{11}{60}\](x-491.67)×11÷60
Rankine to Réaumur\[{{T}_{R\acute{e}aumur}}=({{T}_{Rankine}}-491.67)\times \frac{4}{9}\](x-491.67)×4÷9
Rankine to Rømer\[{{T}_{Rømer}}=({{T}_{Rankine}}-491.67)\times \frac{7}{24}+7.5\](x-491.67)×7÷24+7.5
Delisle to Fahrenheit\[{{T}_{Fahrenheit}}=212-{{T}_{Delisle}}\times \frac{6}{5}\]212-x×6÷5
Delisle to Celsius\[{{T}_{Celsius}}=100-{{T}_{Delisle}}\times \frac{2}{3}\]100-x×2÷3
Delisle to Kelvin\[{{T}_{Kelvin}}=373.15-\left( {{T}_{Delisle}}\times \frac{2}{3} \right)\]373.15-(x×2÷3)
Delisle to Rankine\[{{T}_{Rankine}}=671.67-{{T}_{Delisle}}\times \frac{6}{5}\]671.67-x×6÷5
Delisle to Newton\[{{T}_{Newton}}=33-{{T}_{Delisle}}\times \frac{11}{50}\]33-x×11÷50
Delisle to Réaumur\[{{T}_{R\acute{e}aumur}}=80-{{T}_{Delisle}}\times \frac{8}{15}\]80-x×8÷15
Delisle to Rømer\[{{T}_{Rømer}}=60-{{T}_{Delisle}}\times \frac{7}{20}\]60-x×7÷20
Newton to Fahrenheit\[{{T}_{Fahrenheit}}={{T}_{Newton}}\times \frac{60}{11}+32\]x×60÷11+32
Newton to Celsius\[{{T}_{Celsius}}={{T}_{Newton}}\times \frac{100}{33}\]x×100÷33
Newton to Kelvin\[{{T}_{Kelvin}}={{T}_{Newton}}\times \frac{100}{33}+273.15\]x×100÷33+273.15
Newton to Rankine\[{{T}_{Rankine}}={{T}_{Newton}}\times \frac{60}{11}+491.67\]x×60÷11+491.67
Newton to Delisle\[{{T}_{Delisle}}=(33-{{T}_{Newton}})\times \frac{50}{11}\](33-x)×50÷11
Newton to Réaumur\[{{T}_{R\acute{e}aumur}}={{T}_{Newton}}\times \frac{80}{33}\]x×80÷33
Newton to Rømer\[{{T}_{Rømer}}={{T}_{Newton}}\times \frac{35}{22}+7.5\]x×35÷22+7.5
Réaumur to Fahrenheit\[{{T}_{Fahrenheit}}={{T}_{R\acute{e}aumur}}\times \frac{9}{4}+32\]x×9÷4+32
Réaumur to Celsius\[{{T}_{Celsius}}={{T}_{R\acute{e}aumur}}\times \frac{5}{4}\]x×5÷4
Réaumur to Kelvin\[{{T}_{Kelvin}}={{T}_{R\acute{e}aumur}}\times \frac{5}{4}+273.15\]x×5÷4+273.15
Réaumur to Rankine\[{{T}_{Rankine}}={{T}_{R\acute{e}aumur}}\times \frac{9}{4}+491.67\]x×9÷4+491.67
Réaumur to Delisle\[{{T}_{Delisle}}=(80-{{T}_{R\acute{e}aumur}})\times \frac{15}{8}\](80-x)×15÷8
Réaumur to Newton\[{{T}_{Newton}}={{T}_{R\acute{e}aumur}}\times \frac{33}{80}\]x×33÷80
Réaumur to Rømer\[{{T}_{Rømer}}={{T}_{R\acute{e}aumur}}\times \frac{21}{32}+7.5\]x×21÷32+7.5
Rømer to Fahrenheit\[{{T}_{Fahrenheit}}=({{T}_{Rømer}}-7.5)\times \frac{24}{7}+32\](x-7.5)×24÷7+32
Rømer to Celsius\[{{T}_{Celsius}}=({{T}_{Rømer}}-7.5)\times \frac{40}{21}\](x-7.5)×40÷21
Rømer to Kelvin\[{{T}_{Kelvin}}=({{T}_{Rømer}}-7.5)\times \frac{40}{21}+273.15\](x-7.5)×40÷21+273.15
Rømer to Rankine\[{{T}_{Rankine}}=({{T}_{Rømer}}-7.5)\times \frac{24}{7}+491.67\](x-7.5)×24÷7+491.67
Rømer to Delisle\[{{T}_{Delisle}}=(60-{{T}_{Rømer}})\times \frac{20}{7}\](60-x)×20÷7
Rømer to Newton\[{{T}_{Newton}}=({{T}_{Rømer}}-7.5)\times \frac{22}{35}\](x-7.5)×22÷35
Rømer to Réaumur\[{{T}_{R\acute{e}aumur}}=({{T}_{Rømer}}-7.5)\times \frac{32}{21}\](x-7.5)×32÷21

Source Code

// Temperature to Farenheit / Celsius / Kelvin Conversion 
#include <iostream.h>
#include <conio.h>
void main()
{
  double temp, ctemp;
  int ch;
  char c;
  again:
  clrscr();
  cout<<"+------------------------+\n";
  cout<<"| Temperature Conversion |\n";
  cout<<"+------------------------+\n";
  cout<<"\n1. Fahrenheit to Celsius";
  cout<<"\n2. Celsius to Fahrenheit";
  cout<<"\n3. Kelvin to Fahrenheit";
  cout<<"\n4. Fahrenheit to Kelvin";
  cout<<"\n5. Celsius to Kelvin";
  cout<<"\n6. Kelvin to Celsius";
  cout<<"\n\nEnter your choice number: ";
  cin>>ch;
  if(ch == 1) {
    cout<<"\nEnter Temperature in Fahrenheit: ";
    cin>>temp;
    ctemp = (temp - 32) * 5 / 9;
    cout<<"\nTemperature in Celsius is "<<ctemp<<"\370";
  } else if(ch == 2) {
    cout<<"Enter Temperature in Celsius: ";
    cin>>temp;
    ctemp = temp * 9 / 5 + 32;
    cout<<"\nTemperature in Fahrenheit is "<<ctemp<<"\370";
  } else if(ch == 3) {
    cout<<"Enter Temperature in Kelvin: ";
    cin>>temp;
    ctemp = (temp * 9 / 5) - 459.67;
    cout<<"\nTemperature in Fahrenheit is "<<ctemp<<"\370";
  } else if(ch == 4) {
    cout<<"Enter Temperature in Fahrenheit: ";
    cin>>temp;
    ctemp = (temp + 459.67) * 5 / 9;
    cout<<"\nTemperature in Kelvin is "<<ctemp;
  } else if(ch == 5) {
    cout<<"Enter Temperature in Celsius: ";
    cin>>temp;
    ctemp = temp + 273.15;
    cout<<"\nTemperature in Kelvin is "<<ctemp;
  } else if(ch == 6) {
    cout<<"Enter Temperature in Kelvin: ";
    cin>>temp;
    ctemp = temp - 273.15;
    cout<<"\nTemperature in Celsius is "<<ctemp<<"\370";
  } else {
    cout<<"\nWrong choice.....!!";
  }
  cout<<"\n\nDo you want to try again (y/n)? ";
  cin>>c;
  if(c == 'y' || c == 'Y') {
    goto again;
  } else if(c == 'n' || c == 'N') {
    getch();
  } else {
    cout<<"\nWrong choice.....!!";
    getch();
  }
}

Output

Temperature Conersion Output

0 comments :

Post a Comment