156k views
4 votes
Write a program totake a depth (in kilometers) inside the earth as input data;compute

and display thetemperature at this depth in degrees Celsius and degreesFahrenheit.

The relevant formulasare

Celsius = 10 (depth) +20 (Celsius temperature at depth in km)

Fahrenheit = 1.8 (Celsius)+ 32

Include two functionsin your program. Function celsius_at_depth should

compute and return theCelsius temperature at a depth measure in kilometers.

Function fahrenheit should convert a Celsius temperature toFahrenheit.

1 Answer

2 votes

Answer:

#include<iostream>

using namespace std;

//define function to calculate the temperature in Celsius

float celsius_at_depth(float depth){

float celsius = 10 * (depth) + 20; //formula for calculation

return celsius;

}

//define function to calculate the temperature in Fahrenheit

float fahrenheit(float celsius){

float fahrenheit = 1.8 * (celsius)+ 32;//formula for calculation

return fahrenheit;

}

//main function program start from here

int main(){

//initialization

float depth;

print message

cout<<"Please enter the depth (in kilometers): ";

cin>>depth;

float cel = celsius_at_depth(depth); //Calling the function

float feh = fahrenheit(cel); //Calling the function

//print the outputs

cout<<"The Celsius temperature at depth in km: "<<cel<<endl;

cout<<"The temperature in Fahrenheit is: "<<feh<<endl;

}

Step-by-step explanation:

Create function celsius_at_depth with return type float and a parameter. This function takes the value depth from the calling function and calculate the temperature in Celsius and then returns the result to the calling function.

create the second function Fahrenheit with return type float and with one parameter. This function takes the temperature input in Celsius and convert into Fahrenheit and then return to the calling function.

Create the main function and declare the variable.

print the message for the user and store the value enter by the user by using the instruction cin.

then, calling the function and store the return outputs.

Finally, print the output.

User Chanwit
by
5.6k points