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

Can you please submit a code using C++. Thank you! 5. (Name_Lab7_p5.cpp, 20 poin

ID: 3735954 • Letter: C

Question

Can you please submit a code using C++. Thank you!

5. (Name_Lab7_p5.cpp, 20 points) A three-dimensional weather array for the months July and August 2011 has columns labeled by the month 7 and 8. Iin each column, there are rows numbered 1 through 31, representing the days, and for each day, there are two ranks labeled H and L, representing the day's high and low temperature. Use this information to write a C++ program that assigns the high and low temperature for each element of the arrays. Then allow the user to request the following Any day's high and low temperature. Average high and low temperature for a given month Month and day with the highest temperature Month and day with the lowest temperature

Explanation / Answer

Please find my answer:

#include <stdlib.h>
#include <iostream>

#define MONTHS 2
#define DAYS 31
#define RANKS 2
#define HIGH 0
#define LOW 1
#define MIN_TEMP -500
#define MAX_TEMP 500

using namespace std;

int record[MONTHS][DAYS][RANKS];


void input_temperature()
{
int i, j, k;

/**
   * Input the values for a month, a day int the order of high and low
   * temperature
   */

for(i = 0; i < MONTHS; i++)
{
    for(j = 0; j <= DAYS; j++)
    {
      for(k = 0; k <= RANKS; k++)
      {
        cin >> record[i][j][k];
      }
    }
}

return;
}

void print_high_low_temp()
{
int month, day;

cout << "Enter month" << endl;
cin >> month;
cout << "Enter day" << endl;
cin >> day;

cout<< "High temperature for the day is "<< record[month][day][HIGH];

cout<< "Low temperature for the day is "<< record[month][day][LOW];

return;
}

void calculate_avg_high_low_temperature()
{
int month, sum = 0, i;
float avg;

cout << "Enter month" << endl;
cin >> month;

/**
   * Calculate average high temperature
   */

for(i = 0; i < DAYS; i++)
{
    sum += record[month][i][HIGH];
}

avg = sum/DAYS;
cout << "Average high temperature is "<< avg << endl;

sum = 0;

for(i = 0; i < DAYS; i++)                                                  
{                                                                          
    sum += record[month][i][LOW];                                           
}                                                                          
                                                                                 
avg = sum/DAYS;                                                            
cout << "Average low temperature is "<< avg << endl;

return;
}

void search_highest_temperature_day()
{
int max_temp, max_month, max_day, i, j;

/**
   * Initialize max_temp with the first high temperature and search.
   */

max_temp = record[0][0][HIGH];
max_day = 0;
max_month = 0;
for(i = 0; i < MONTHS; i++)
{
    for(j = 0; j < DAYS; j++)
    {
      if(max_temp < record[i][j][HIGH])
      {
        max_temp = record[i][j][HIGH];
        max_month = i + 7;
        max_day = j + 1;
      }
    }
}

cout << "Highest temperature "<< max_temp << endl;
cout << "Month "<< max_month << endl;
cout << "Day "<< max_day << endl;

return;
}


void search_lowest_temperature_day()                                        
{                                                                            
int min_temp, min_month, min_day, i, j;                                    
                                                                                 
/**                                                                        
   * Initialize min_temp with the first high temperature and search.         
   */                                                                   
                                                                                 
min_temp = record[0][0][LOW];                                             
min_day = 0;                                                               
min_month = 0;                                                             
for(i = 0; i < MONTHS; i++)                                                
{                                                                          
    for(j = 0; j < DAYS; j++)                                                
    {                                                                        
      if(min_temp > record[i][j][LOW])                                      
      {                                                                      
        min_temp = record[i][j][LOW];                                       
        min_month = i + 7;                                                       
        min_day = j + 1;                                                         
      }                                                                      
    }                                                                        
}                                                                          
                                                                                         
cout << "Lowest temperature "<< min_temp << endl;                         
cout << "Month "<< min_month << endl;                                          
cout << "Day "<< min_day << endl;                                              
                                                                                               
return;                                                                    
}


int main()
{

int choice;

/**
   * Input the high and low temperature values for all the days of the two
   * months
   */

input_temperature();

/**
   * Enter user's choice
   */

cin >> choice;

switch(choice)
{
    case 1 :
    {
      /**
       * A day's high and low temperature
       */
      print_high_low_temp();
      break;
    }

    case 2 :
    {
      /**
       * Average high and low temperature for given month
       */
      calculate_avg_high_low_temperature();
      break;
    }

    case 3 :
    {
      /**
       * Month and day with the highest temperature
       */
      search_highest_temperature_day();
      break;
    }

    case 4:
    {
      /**
       * Month and day with the lowest temperature
       */

      search_lowest_temperature_day();
      break;
    }
    default :
    {
      cout << "Wrong choice" << endl;
    }
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote