In cold weather meteorologists report an index called the wi

In cold weather, meteorologists report an index called the wind chill factor, which takes into account the wind speed and the temperature. The index provides a measure of the chilling effect of wind at a given air temperature. Wind chill may be approximated by the following formula, w = 33 -(10 Squareroot u - u + 10.5) (33 - t)/23.1 where u = wind speed in m/sec t = temperature in degrees Celsius: t leftarrow 10 W = wind chill index (in degrees Celsius) Write a function that returns the wind chill index. Your code should ensure that the restriction on the temperature is not violated. Look up some weather reports in back issues of a newspaper in your library and compare the wind chill index you calculate with the result reported in the newspaper.

Solution

Please follow the code and comments for description :

CODE :

#include <iostream> // required header files for the code
#include <cmath>

using namespace std;

float windChillIndex (float temperature, float windspeed) { // function that returns the wind index for the given temperature and speed
float windindex = 35.74f + 0.6215f * temperature; // initialising the wind index
windindex -= 35.75f * pow(windspeed, 0.16f); // calculating the index values
windindex += 0.4275f * temperature * pow(windspeed, 0.16f);
return windindex; // returning the index result value
}

int main() // driver method
{
cout << \"Welcome to Wind Chill Index Calculator.!\" << endl; // prompt for the user about the code
cout << \"Enter the Temperature (in Celsius <= 10) : \" << endl; // prompt to enter the data
float temp = 0;
cin >> temp; // getting the data
if(temp < 0 || temp > 10){ // checking for the entered data temperature
cout << \"Invalid Temperature.!\" << endl;
exit(0); // exiting the code
}
cout << \"Enter the Wind Speed (in m/sec) : \" << endl; // prompt to enter the speed of the wind
float windSpeed = 0;
cin >> windSpeed; // getting the data

float windIndex = windChillIndex (temp, windSpeed); // calculating the result by calling the function
cout << \"The Resultant Wind Chill Index is : \" << windIndex << \" C\"<< endl; // printing the result in celsius format

return 0;
}

OUTPUT :

Welcome to Wind Chill Index Calculator.!
Enter the Temperature (in Celsius <= 10) :
10
Enter the Wind Speed (in m/sec) :
50
The Resultant Wind Chill Index is : -16.9024 C


Hope this is helpful.

 In cold weather, meteorologists report an index called the wind chill factor, which takes into account the wind speed and the temperature. The index provides a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site