Write C++ program as described below. Call this programChill.cpp.
In April 2018 the lowest and the highest temperatures ever recorded in Ohio are 25F and 81F, respectively. The wind chill factor is the perceived temperature when taking temperature and wind into account. The standard formula for wind chill factor (from the US Weather Service) is:
0.0817 * (3.71 * sqrt(Wind) + 5.81 – 0.25 * sqrt(Wind)) * (Temp – 91.4) + 91.4
where ‘sqrt’ is the square root, Wind is the current wind speed in limes per hour and Temp is the current temperature in Fahrenheit.
You must write a program that:
- Creates a file with some randomly generated temperatures.
- Asks the user for a wind speed .
- Generates an output file that contains the wind chill factor of each temperature stored in the input file.
Here are the details.
First, write a function that generates 30 integer numbers, which represent hypothetically the temperature of the 30 days of April in Ohio, and stores all the generated temperature in an output file A. The temperatures generated must range between 25F and 81F. The file Amust contain nothing but integer numbers separated by a blank or a line break. The name of the file A should be given by the user and read from the keyboard. Call this functiongentemp.cpp.
Second, write the program Chill.cpp that prompts the user for the wind speed in miles per hour, reads the temperatures stored in file A and write in a file B the wind chill factor of those temperatures. The name of the file Bcan be chosen by you.
To generate integer numbers, use the functions rand() and srand() defined in <cstdlib>.
rand() - Returns a pseudo-random integral number in the range 0 to RAND_MAX
(Note: RAND_MAX is usually equal to 32767 but it may vary between cstlib library implementation).
A typical way to generate pseudo-random numbers in a determined
range using
rand() is to use the modulo of the returned value by the
range span and add the initial value of the range:
For example:
( value % 100 ) is in the range 0 to 99
( value % 100 + 1 ) is in the range 1 to 100
( value % 30 + 1985 ) is in the range 1985 to 2014
Before generating pseudo-random numbers, use a seed to generate the series. The seed is initialized by using the function srand().
Here is a small example that generates 20 pseudo-random integers.
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int random_integer;
srand(9);
for(int index=0; index<20; index++)
{
random_integer = (rand()%100)+1;
cout << random_integer << endl;
}
return 0;
}