Function Objective Write a function that takes a temperature
Function Objective: Write a function that takes a temperature in Kelvin as input and returns that temperature in Fahrenheit and Celsius. Since any function can have only one return value, your function will return the second temperature using a call by reference formal parameter. (in C++).
Function Specifications:
Your function must have the name tempconvertor
- Your function must have two formal parameters, each of type double
The first parameter is the temperature in Kelvin and must be passed by value
The second parameter is the temperature in Celsius and must be passed by reference
The return type for your function must be double
The return value for your function must be the temperature in Fahrenheit
Since zero Kelvin is the lowest possible temperature, your function must set both the Celsius and Fahrenheit temperatures to -1000 for a Kelvin temperature less than zero For all Kelvin temperatures greater than or equal to zero, your function must convert the Kelvin temperature to Celsius and Fahrenheit using the following equations
Celsius = Kelvin – 273.15
Fahrenheit = Kelvin X (9/5) – 459.67
In your Vocareum work directory you will find two files. Do not delete or rename either of these files. One file is named Assignment8_function.cpp. You must write your tempconvertor function definition (and only your function definition) in this file.
The second file is called Assignment8_main.cpp. In this file you should write a main function with which you can test your tempconvertor function. For example, your main function could ask the user to enter a temperature in Kelvin, then call the function tempconvertor, and then display the temperature in Kelvin, Celsius, and Fahrenheit. Writing an appropriate main function in the file Assignment8_main.cpp is the only way to test your tempconvertor function.
Note: You MUST write your tempconvertor prototype above your main function in the file Assignment8_main.cpp.
Note: Only your tempconvertor function will be graded. Your main function will NOT be graded. Therefore, you may write your main function any way you wish
Note: When you click Build or Run in Vocareum, your code in both Assignment8_function.cpp and Assignment8_main.cpp will be linked together and compiled (and then executed if you clicked Run). If your Assignment8_main.cpp file is empty, you can still compile the code in Assignment8_function.cpp by clicking Build. However, you cannot Run just the code in Assignment8_function.cpp.
Solution
#include <iostream>
using namespace std;
double tempconvertor(double,double*);
int main() {
double *celsius;
double kelvin;
cout << \"Enter Kelvin Temperature:\";
cin >> kelvin;
cout << \"Farenheit:\" << tempconvertor(kelvin,celsius)<<endl;
cout << \"celcius:\" << *celsius<<endl;
}
double tempconvertor(double kelvin,double *celsius){
if(kelvin<0){
*celsius = -1000;
return -1000;
}
double farenheit;
*celsius = kelvin-273.15;
farenheit = (9.0/5)*(*celsius) + 32;
return farenheit;
}
/*
sample output
Enter Kelvin Temperature: 1
Farenheit:-457.87
celcius:-272.15
*/

