Write a program that will input temperatures for consecutive days. The program will store these values into an array and call a function that will return the average of the temperatures. It will also call a function that will return the highest temperature and a function that will return the lowest temperature. The user will input the number of temperatures to be read. There will be no more than 50 temperatures. Use typedef to declare the array type. The average should be displayed to two decimal places

Respuesta :

Answer:

#include <iostream>  

using namespace std;

typedef double* temperatures;

double avg(array t, int length);

double min(array t, int length);

double max(array t, int length);

int main()

{

   cout << "Please input the number of temperatures to be read." << endl;

   int num;

   cin >> num;

   temperatures = new double[num];

   for(int i = 0; i < num; i++)

   {

       cout << "Input temperature " << (i+1) << ":" << endl;

       cin >> temperatures[i];

   }

   cout << "The average temperature is " << avg(temperatures, num) << endl;

   cout << "The highest temperature is " << max(temperatures, num) << endl;

   cout << "The lowest temperature is " << min(temperatures, num) << endl;

}

double avg(array t, int length)

{

   double sum = 0.0;

   for(int i = 0; i < length; i++)

       sum += t[i];

   return sum/length;

}

double min(array t, int length)

{

   if(length == 0)

       return 0;

    double min = t[0];

   for(int i = 1; i < length; i++)

       if(t[i] < min)

           min = t[i];

   return min;

}

double max(array t, int length)

{

   if(length == 0)

       return 0;

      double max = t[0];

   for(int i = 1; i < length; i++)

       if(t[i] > min)

           max = t[i];

   return max;

}

Explanation:

The C++ program get the array of temperatures not more than 50 items and displays the mean, minimum and maximum values of the temperature array.