Implement the following integer methods: a) Method celsius returns the Celsius e
ID: 3855094 • Letter: I
Question
Implement the following integer methods: a) Method celsius returns the Celsius equivalent of a Fahrenheit temperature, using the calculation celsius = 5.0/9.0 * (fahrenheit-32): b) Method fahrenheit returns the Fahrenheit equivalent of a Celsius temperature, using the calculation fahrenheit = 9.0/5.0 * celsius + 32: c) Use the methods from parts (a) and (b) to write an application that enables the user either to enter a Fahrenheit temperature and display the Celsius equivalent or to enter a Celsius temperature and display the Fahrenheit equivalent.Explanation / Answer
c++ code:
#include <bits/stdc++.h>
using namespace std;
float celcius( float fahrenheit)
{
return (5.0)/(9.0)*(fahrenheit - 32);
}
float fahrenheit( float celcius)
{
return (9.0)/(5.0)*(celcius) + 32;
}
int main()
{
int in;
cout << "Enter 1 to convert fahrenheit to celcius ";
cout << "Enter 2 to convert celcius to fahrenheit ";
cin >> in;
float tmp = 0;
if(in == 1)
{
cout << "Enter the temperature in fahrenheit! ";
cin >> tmp;
float out = celcius(tmp);
cout << tmp << " fahrenheit = " << out << " celcius ";
}
else
{
cout << "Enter the temperature in celcius! ";
cin >> tmp;
float out = fahrenheit(tmp);
cout << tmp << " celcius = " << out << " fahrenheit ";
}
return 0;
}
Sample Output:
Enter 1 to convert fahrenheit to celcius
Enter 2 to convert celcius to fahrenheit
1
Enter the temperature in fahrenheit!
100
100 fahrenheit = 37.7778 celcius
C:UsersAkashDesktopcheggc++ file read>a
Enter 1 to convert fahrenheit to celcius
Enter 2 to convert celcius to fahrenheit
2
Enter the temperature in celcius!
38
38 celcius = 100.4 fahrenheit