CS 211, Assignment 8 Spring 2017 Page 1 of 2 CS 211: Introduction to Programming
ID: 3826276 • Letter: C
Question
CS 211, Assignment 8 Spring 2017 Page 1 of 2
CS 211: Introduction to Programming
Spring 2017 – Assignment 8, Due Thursday April 27th, 11:59
PM
Working with two dimensional array.
Write a C++ program which gets the temperatures for morning and afternoon for 7 days of a week.
This means that you have to get 14 temperatures as input. Your program should have four different
functions a required below.
Requirements:
• Declare a two dimensional array called Temp with data type double.
• The two sizes you use for the two dimensions of array Temp should be declared as global
Constants.
• Write a function called fillup_array which is responsible to get the input for array Temp.
• Write a function called find_average which is responsible to find the average temperature for
the entire week.
This function gets the array Temp as input.
Use call by reference to access the average temperature inside the main function (Your
function should not return back any value)
Don't forget the two digits precision when you calculate the average.
Use the cout statement inside the main function to print the average temperature for the
entire week.
• Write a function called find_daily_mmm. This function is responsible to find the maximum,
minimum, and mean temperature for each day in a week. This function has four arguments
including:
array Temp, max, min, and mean.
This function does not return back any value. Use call by reference to save the values for
max, mean, and min inside the related function arguments.
You should call function find_daily_mmm inside the main function for each day of week.
Don't forget the two digits precision when you calculate the mean.
• Write a function called show_warmer. This function takes the array Temp as one of its input
parameters. It also gets another input called cutoff, which is a base temperature using for
comparison. This function compares all the temperatures in a week with the cutoff and prints
each day of a week which is warmer than cutoff. Your function then needs to print the day and
temperature.
Considering the cutoff 10, one example of the printed message by this function is :
At day 6, morning, the temperature was 11 which is warmer than 10
When you check your array to find the temperatures that are warmer than the cutoff you
need to figure out a way to know if the temperature is for morning or afternoon. (you need
this information when you print the message)
Explanation / Answer
#include<iostream.h>
#include <iomanip>
using namespace std;
const int rows = 7;
const int cols = 2;
int count = 0; /* will be used to denote the day while calling function find_daily_mmm, we need to call this function */ for each day in the main*/
void find_average(double Temp[][2], double *avg){
int i;
sum = 0;
for (i = 0; i<7; i++){
for (j=0; j<2; j++){
sum = sum + Temp[i][j]
}
}
*avg = sum / 14;
}
void fillup_array(double *temp){
int i;
cout << Enter morning/afternoon temprature for 7 days(14 double values) << endl;
for (i=0; i<7; i++){
cin >> *(*(temp + i) + 0) >> *(*(temp + i ) + 1);
}
}
void find_daily_mmm(double Temp[][2], int *min, int *max, double *mean){
if (Temp[count][0] > Temp[count][1]){
*max = Temp[count][0];
*min = Temp[count][1];
}
else {
*max = Temp[count][1];
*min = Temp[count][0];
}
*mean = (Temp[count][1] + Temp[count][2] ) / 2;
}
void show_warmer( double Temp[][2], int cut_off){
int i;
for (i=0; i<7; i++){
if (Temp[i][0] > cut_off){
cout << "At day " << i << "morning " << "the the temperature was " << Temp[i][0];
cout << "which is warmer than" << cut_off << endl;
}
if (Temp[i][1] > cut_off) {
cout << "At day " << i << "afternoon " << "the the temperature was " << Temp[i][1];
cout << "which is warmer than" << cut_off << endl;
}
}
}
void main(){
double Temp[rows][cols];
int min,max;
double mean;
int i;
double avg;
fillup_array();
for (i = 0; i<7; i++){
count = i;
find_daily_mmm(Temp,&max,&min,&mean)
cout << "max:" << max << "min:" << min << "mean:" << std::setprecision(2) << mean;
}
find_average(Temp, &avg);
cout << "Average:" << std::setprecision(2) << avg << endl;
show_warmer(Temp, 10);
}