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

Arrays - C++ B Option: Create a program to enter and average the high and low te

ID: 3591131 • Letter: A

Question

Arrays - C++

B Option: Create a program to enter and average the high and low temperatures for the week. . Create a constant to define the size of two float arrays. .Create two one dimensional float arrays in the function main) called highs and lows Best possible grade for the B option is 90 const int MAX=7 float float highs [MAX]; lows [MAX] · Write a loop to ask the user to enter the highs until the size of the array is reached. · Write a similar loop to ask the user to enter the lows until the size of the array is reached. . Use the defined constant (as shown above) when checking for the maximum size of each array. . Calculate the average high for the week * Calculate the average low for the weelk Display those results. n Do the B option and Best possible grade for the A option is 100 A Option: . Display the difference for each day's temperature. Store these differences in a third array float diff [MAX]; difi[0]- highs[0] - lows[0]; // better yet use a loop .Create string variables for the Month, Starting Date of the week and Year of the temperatures. . Prompt the use to enter the Month Day and year from the keyboard. Use gets_sO to input the values. If available -- See the blackboard code example-module 4->gets) (If available - See the blackboard code example->module 4-string functions) If available -- See the blackboard code example-module 4->string arrays) . Use strcpy s0) and strcat_s0 to build a 4th string from the other three .Create a stirng array to hold the days of week to output for your report .Output the new string .Output the highest temperature for the week .Output the lowest temperature for the week Your output should look something like this Acme Weather Report September 17, 2009 Da Monday Tuesday -and so on- High Low Difference 85 72 13 88 73 15 92Low for the week: Xx Average Low 55 High for the week: Average High Turn in: Your compressed project folder(ZIP), Source Code and screen shots Turn in either the B or the A option, but not both. A screen print of these runs: Be sure to use Alt-Print screen to only capture your program window A and B option 85, 88, 87, 90, 92,91,78 72,73, 71, 76, 77, 62, 55 Lows option (also do above Month Day and year of your choice

Explanation / Answer

Here part B is easily implemented but as in the question it is not clear what will be data base from where values are driven so assumptions are made.

code for part 1:

// Implementation of part B

#include <iostream>
#include <math.h>
#include <string.h>

using namespace std;

int main(int argc, char const *argv[])
{
   const int Max = 7; // Declaration
   float highs[Max];
   float lows[Max];
   float havg=0, lavg=0; //Declaring highest and lowest average

   // Code for part B
   for(int i = 0; i<Max; ++i) //loop for inputing high values
   {
       cout<<" Enter the high temperature for day "<<i+1<<":";
       cin>>highs[i];
       havg = havg + highs[i]; // here suming all the high temperatures in havg variable
   }

havg = havg/7; //taking the average of highest temperatures in a havg

   for(int i = 0; i<Max; ++i) //loop for inputing lowest values
   {
       cout<<" Enter the lowest temperature for day "<<i+1<<":";
       cin>>lows[i];
       lavg += lows[i]; // taking some of all lowest avg for later calculating average
   }

lavg =lavg/7; // average of lowest temp for week

cout<<" The average highest temperature for the week is: "<<havg <<" And average of lowest temperatures for day is: "<<lavg;

   return 0;
}

// End of part B

Here in part A it is not clear that what type of database is needed for the same so I just implemeted for a single function you can save inputs to a particular file and then acess from it using file functions easily, Here for an instance only one date is inputing from user and leting user to input that particular date and data is displayed if more enteries are there in file or a database than it become clear to implement it.

// Code for part A

#include <iostream>
#include <iomanip>
#include <string.h>
#include <string>

using namespace std;
int input_store_display ( string &inputing); // function that has values;

int main(int argc, char const *argv[])
{
   cout<<"Enter the month date and year you want to search without space like,(exaple- January252017): ";
   string userdate;
   cin>>userdate;

// taking this data from user for real this data should already stored in some database
   string Month,date_of_week,Year;
   // question is not clear for how many and how inputs are there for months and days
   // so here considering only one day data is avaialble

// for implementing more number of days one shlould implement function for the inputs and put it in an array

   cout<<" Enter the Month (full name of month example January): ";
   cin>>Month;
   cout<<" Enter the Starting date of the month: ";
   cin>>date_of_week;
   cout<<" Enter the year: ";
   cin>>Year;

   // Here strings are combined for easy calculations when inputing directly comparing
   string combine;
   combine = Month;
   combine = Month + date_of_week + Year;
   cout<<"Combined here is: "<<combine;

if (userdate == combine)
   input_store_display (userdate);
else
cout<< " No data found for entered date ";

   return 0;
}


int input_store_display(string &inputing)
{
   const int Max = 7; // Declaration
   float highs[Max];
   float lows[Max];
   // Code for part B
   for(int i = 0; i<Max; ++i) //loop for inputing high values
   {
       cout<<" Enter the high temperature for day "<<i+1<<":";
       cin>>highs[i];
   }

   for(int i = 0; i<Max; ++i) //loop for inputing lowest values
   {
       cout<<" Enter the lowest temperature for day "<<i+1<<":";
       cin>>lows[i];
   }

string days; // used for printing particular name of the day like sunday monday
// formatted display
cout<<"Acme Whether Report "<<inputing<<endl;

cout<<endl<<setw(10)<<" Day "<<setw(10)<<"High"<<setw(10)<<"Low"<<setw(10)<<"Difference";

   for (int i=0; i <Max ; ++i)
   {
       if (i==0)
           days = "Monday";
       else if (i==1)
           days = "Tuesday";
       else if (i==2)
           days = "Wednesday";
       else if (i==3)
           days = "Thursday";
       else if (i==4)
           days = "Friday";
       else if (i==5)
           days = "Satuarday";
       else if (i==6)
           days = "Sunday";

       cout<<endl<<setw(10)<<days<<setw(10)<<highs[i]<<setw(10)<<lows[i]<<setw(10)<< highs[i]-lows[i];
   }

  
}

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