Global Warming Do Using The Computer exercise number 2 (Global Warming) from cha
ID: 3817233 • Letter: G
Question
Global Warming
Do Using The Computer exercise number 2 (Global Warming) from chapter 10 on page 318 of the PDFs. Call your program you hand in "username_prog7.c". Align Numbers. Do not do part (A).
SAMPLE INPUT:
85
23
-15
32
75
44
34
56
-1
0
23
23
34
-45
45
45
76
64
-32
0
23
23
34
-45
45
45
76
64
-32
76
-500 (NOT in computation)
SAMPLE OUTPUT:
YourName Program#7 CSCI1110
Input Temperatures
------------------
-9999
...
Average Temp: -99.99
Number of Temps: 99
Number above 32: 99
----PARTIAL SAMPLE OUTPUT
Number above 32: 16
RUBRIC/CHECKLIST
Output Correct – including echo the input with implied decimal point aligned
Indentation
Comments
Used defines for all constants
Read more than one input (loop and an array) until a -500 is entered
Output numbers should aligned
Functions read_temps, hot_days, print_temps must be included. More functions can be used but NOT less.
Output copied into Input
Filename
Upload to Bb9
RUBRIC/CHECKLIST
Output Correct – including echo the input with implied decimal point aligned
Indentation
Comments
Used defines for all constants
Read more than one input (loop and an array) until a -500 is entered
Output numbers should aligned
Functions read_temps, hot_days, print_temps must be included. More functions can be used but NOT less.
Output copied into Input
Filename
Upload to Bb9
Explanation / Answer
#include<stdio.h>
#define MAX_SIZE 1000
#define END_OF_DATA -500
#define THRESHOLD_TEMP 32.0
int read_temps(float temp_data[]);
void print_temps(float temp_data[], int size);
float find_avg_temp(float temp_data[], int size);
int find_hot_days(float temp_data[], int size, float threshold_value);
int main() {
int size, hot_days;
float avg_temp, temp_data[MAX_SIZE];
size = read_temps(temp_data);
hot_days = find_hot_days(temp_data, size, THRESHOLD_TEMP);
avg_temp = find_avg_temp(temp_data, size);
printf("ZubaeyrOdin Program#7 CSC|1110 ");
print_temps(temp_data, size);
printf("Average Temperature : %4.2f ", avg_temp);
printf("Number of Temperature : %d ", size);
printf("Number above %.2f : %d ", THRESHOLD_TEMP, hot_days);
return 0;
}
/*
* Reads the input data from console
* A value of -500 represents the end
* of the input delimeter
*/
int read_temps(float temp_data[]) {
printf("Enter the data : ");
int temp, size = 0;
scanf("%d", &temp);
while(temp != END_OF_DATA && size < MAX_SIZE) {
temp_data[size++] = temp;
scanf("%d", &temp);
}
return size;
}
/*
* Prints the given array of temperatures
*/
void print_temps(float temp_data[], int size) {
printf("-------------------------------- ");
printf(" INPUT TEMPERATURE ");
printf("-------------------------------- ");
int i;
for (i = 0; i < size; i++) {
printf("%d. %.2f ", i, temp_data[i]);
}
printf("-------------------------------- ");
}
/*
* Counts the number of days greater
* than the threshold value
*/
int find_hot_days(float temp_data[], int size, float threshold_value) {
int i, count = 0;
for (i = 0; i < size; i++) {
if (temp_data[i] >= threshold_value) {
count = count + 1;
}
}
return count;
}
/*
* Finds the average of the given data
*/
float find_avg_temp(float temp_data[], int size) {
int i;
float sum = 0;
for (i = 0; i < size; i++) {
sum += temp_data[i];
}
return sum/size;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.