Hello, can you please help me complete this C++ programming challenge? Writing a
ID: 3777010 • Letter: H
Question
Hello, can you please help me complete this C++ programming challenge?
Writing a Function
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.
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
Create two files.One file is named Challenge8_function.cpp. You must write your tempconvertor function definition (and only your function definition) in this file. The second file is called Challenge8_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 Challenge8_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 Challenge8_main.cpp.
(This is the asker request: Please write the call file function in the code.)
Explanation / Answer
Challenge_function.cpp
#include<stdio.h>
#include<iostream>
using namespace std;
double tempconverter(double kel)
{
double *celsius=0.0;
double fahrenheit=0.0;
if(kel<0){
celsius=-1000;
fahrenheit=-1000;
return fahrenheit;
}
else{
//celsius = kel–273.15;
celsius=kel-273.15;
//fahrenheit = (kel X (9/5))–459.67;
fahrenheit=(kel*(9/5))-459.67;
return fahrenheit;
}
}
--------------
challenge_main.cpp
#include "Challenge_function.cpp"
#include<stdio.h>
#include<iostream>
using namespace std;
double tempconverter(double kel);
int main()
{
//declaration
double kelvin;
cout<<"enter temperature in kelvin"<<endl;
cin>>kelvin;
double temprature=tempconverter(kelvin);
cout<<"the kelvin temperature in fahrenheit"<<temprature;
}
output
enter temperature in kelvin
56
the kelvin temperature in fahrenheit-403.67
enter temperature in kelvin
-25
the kelvin temperature in fahrenheit-1000
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.