Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

WRITTEN IN C CODE ONLY INTRODUCTION: In order to determine a suitable site for a

ID: 3725889 • Letter: W

Question

WRITTEN IN C CODE ONLY

INTRODUCTION: In order to determine a suitable site for a wind turbine in a mountain canyon, wind speed data was collected over a 24-hour period. The data was collected at the mouth of the canyon, and at a location one mile downstream from the mouth. The data was placed in an input file called wind turbine. The first record line contains the two-dimensional array size (rows and columns). The second record line contains the mountain canyon name. The remaining record lines contain the hour of the day (24-hour clock), the average wind speeds at the mouth of the canyon, and the average wind speeds one mile downstream respectively ASSIGNMENT: Write a C program that will do the following 1) Read the size (nrows and ncols) of the two-dimensional array from the input file 2) Using a one-dimensional character array read the canyon name 3) Using a two-dimensional array read the hour, the mouth wind speed, and the downstream wind speed 4) Compute the average 24-hour wind speed at the mouth of the canyon. 5) Compute the average 24-hour wind speed one mile downstream 6) Determine the minimum wind speed and hour that it occurred 7) Determine the maximum wind speed and hour that it occurred Additionally, assume that the maximum wind speed that the turbine can sustain is 19.5 miles per hour Compute the hour ofthe day that the 19.5 miles per hour occurred for the one-mile downstream wind speeds To compute the hour of the day for 19.5 miles per hour you will use linear interpolation. The equation is Where y is the computed hours, x is the interpolating value, xl is the first downstream wind speed, x2 is the second downstream wind speed, y1 is the first hour, and y2 is the second hour. A partial flowchart is provided ow Your program will print to the computer screen and to an output file called wind report Notice that you will be printing the time column based on a 24-hour clock. That means that when the time is less than 1000 hours you will need to print a leading zero. A partial flowchart is provided below For the composite report 1. When printing the minimum wind speed, if the time of the minimum wind speed is less than 1000 hours, print the wind speed and print the time with a leading zero, else print the wind speed and time 2. When printing the maximum wind speed, if the time of the maximum wind speed is less than 1000 hours, print the wind speed and print the time with a leading zero, else print the wind speed and time

Explanation / Answer

// FileName: WindSpeed.c

#include<stdio.h>
#include<stdlib.h>
#define MAX 100

// Function to read data from file and stores it in arrays
int readFile(int time[], float mouth[], float downStream[])
{
// To store number of rows and columns from the file
int row, col, counter = 0;
// To store heading
char arr[50];
// FILE pointer declared
FILE *fRead;
// Open the file for reading
fRead = fopen("terrain.txt", "r");
// Checks if file is unable to open display error message
if(fRead == NULL)
{
printf("Cannot open input file terrain.txt ");
exit(0);
}// End of if condition
// Read the row value
fscanf(fRead,"%d", &row);
// Read the column value
fscanf(fRead,"%d", &col);

// Read the heading
fscanf(fRead,"%s", arr);

// Loops till not end of file
while(!feof(fRead))
{
// Reads data from file and stores it in counter position of the array's
fscanf(fRead,"%d %f %f", &time[counter], &mouth[counter], &downStream[counter]);
// Increase the counter by one
counter++;
}// End of while loop
// Returns the counter
return counter;
}// End of function

// Function to calculate
void calculate(int time[], float mouth[], float down[], float *avgMouth, float *avgDownStream, float *minSpeed, float *maxSpeed, int *minTime, int *maxTime, int len)
{
int c;
// Stores the starting position of the array as initial value
*minSpeed = mouth[0];
*minTime = time[0];
*maxSpeed = down[0];
*maxTime = time[0];
float totalMouth = mouth[0];
float totalDown = down[0];
// Loops from one to length
// Starts from one because already zero index position considered above
for(c = 1; c < len; c++)
{
// Calculates total
totalDown += down[c];
totalMouth += mouth[c];
// Checks if the current index position value of the array is less than the earlier minimum speed
if(mouth[c] < *minSpeed)
{
// Update the minimum speed
*minSpeed = mouth[c];
// Update the time
*minTime = time[c];
}// End of if condition
// Checks if the current index position value of the array is greater than the earlier maximum speed
if(down[c] > *maxSpeed)
{
// Update the maximum speed
*maxSpeed = down[c];
// Update the maximum time
*maxTime = time[c];
}// End of if condition
}// End of for loop
// Calculates average
*avgDownStream = totalDown / len;
*avgMouth = totalMouth / len;
}// End of function

// Function to display data
void display(int time[], float mouth[], float down[], float avgMouth, float avgDownStream, float minSpeed, float maxSpeed, int minTime, int maxTime, int len)
{
int c;
printf(" **********************************************");
printf(" WINDY-SLOPE-CANYON");
printf(" Wind Speed(mi/h)");
printf(" Time(h) Mouth Downstream");
// Loops till length
for(c = 0; c < len; c++)
printf(" %04d %4.2f %4.2f", time[c], mouth[c], down[c]);
printf(" Average %.2f %.2f", avgMouth, avgDownStream);
printf(" Minimum wind speed: %.2f mph Time: %04d hours", minSpeed, minTime);
printf(" Maximum wind speed: %.2f mph Time: %04d hours", maxSpeed, maxTime);
}// End of function
// main function definition
int main()
{
// To store time and number of record in file
int time[MAX], len;
// To store mouth and down stream values
float mouth[MAX], downStream[MAX];
float avgMouth, avgDownStream, minSpeed, maxSpeed;
int minTime, maxTime;
// Calls the function to read data from file
len = readFile(time, mouth, downStream);
// Calls the function to calculate
calculate(time, mouth, downStream, &avgMouth, &avgDownStream, &minSpeed, &maxSpeed, &minTime, &maxTime, len);
// Calls the function to display data
display(time, mouth, downStream, avgMouth, avgDownStream, minSpeed, maxSpeed, minTime, maxTime, len);
}// End of main function

Sample Output:


**********************************************
WINDY-SLOPE-CANYON
Wind Speed(mi/h)
Time(h) Mouth Downstream
0100 7.80 6.70
0200 7.50 6.40
0300 8.50 8.00
0400 8.40 6.50
0500 11.10 6.90
0600 14.50 11.50
0700 22.60 15.60
0800 34.90 20.00
0900 30.00 18.50
1000 29.50 18.00
1100 21.30 14.50
1200 20.50 13.40
1300 18.40 13.00
1400 15.60 8.90
1500 14.00 8.50
1600 13.90 8.80
1700 13.00 7.40
1800 11.80 6.30
1900 12.40 6.80
2000 13.40 5.40
2100 5.60 4.70
2200 6.70 3.60
2300 4.20 3.20
2400 5.90 3.80
Average 14.65 9.43
Minimum wind speed: 4.20 mph
Time: 2300 hours
Maximum wind speed: 20.00 mph
Time: 0800 hours