Question
need help

Instructions Assume we collected weather temperature data from a city for 5 day, Mon thru Fri. The data is record in a 10 arr
0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ Program:

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>

using namespace std;

//Structure
struct Temperature
{
string day;
float ave;
};

//Function that returns average
float getAverage(unsigned short temps[15], int idx)
{
float sum = 0;
int i;
  
//Looping
for(i=idx; i<idx+3; i++)
{
sum = sum + temps[i];
}
  
return (sum/3.0);
}

//Main function
int main()
{
int i, j;
int max=120, min=32;
unsigned short temp[15];
  
srand(time(0));
  
//Creating array of structures
struct Temperature days[5];
  
cout << fixed << setprecision(1);
  
//Generating random values
for(i=0; i<15; i++)
{
temp[i] = rand()%(max-min + 1) + min;
}
  
//Filling structures
days[0].day = "Monday";
days[0].ave = getAverage(temp, 0);
  
//Filling structures
days[1].day = "Tuesday";
days[1].ave = getAverage(temp, 3);
  
//Filling structures
days[2].day = "Wednesday";
days[2].ave = getAverage(temp, 6);
  
//Filling structures
days[3].day = "Thursday";
days[3].ave = getAverage(temp, 9);
  
//Filling structures
days[4].day = "Friday";
days[4].ave = getAverage(temp, 12);
  
//Printing values
for(i=0; i<5; i++)
{
cout << endl << days[i].day << ", average temp with " << days[i].ave;
}
  
cout << endl;
  
return 0;
}

_____________________________________________________________________________________________________

Sample Run:

Monday, average temp with 73.0 Tuesday, average temp with 75.7 Wednesday, average temp with 89.3 Thursday, average temp with

Add a comment
Know the answer?
Add Answer to:
need help Instructions Assume we collected weather temperature data from a city for 5 day, Mon...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT