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

(1) Generate a power plant output (random numbers between 500 and 1000 ) in mega

ID: 3645518 • Letter: #

Question

(1) Generate a power plant output (random numbers between 500 and 1000 ) in megawatts over a period of 10 weeks. Each row of data contains 7 floating-point numbers that represent 1 week's data. Use symbolic constants NROWS and NCOLS to represent the number of rows and columns in the 2-D array. Apply srand() in the program. (2) Print the power plant output in a 2-D format with headers (number of week and number of day). (3) Compute and print the average power output over this 10-week period. Print the number of days with greater-than-average power output. Also print the day of the week and the number of the week on which the output is greater-than-average. (4) Print the day of the week and the number of the week on which the minimum and maximum power output occurred.If there are several days with the minimum and maximum power output, print the information for each of these days. (5) Record outputs in a datafile, power1.dat

Explanation / Answer

please rate - thanks

message me if any problems

#include<iostream>
#include <fstream>
using namespace std;
#define NROWS 10
#define NCOLS 7
int main()
{double pp[NROWS][NCOLS],min,max,sum=0,average;
int i,j;
ofstream out;
srand(time(0));
out.open("power1.dat");
for(i=0;i<NROWS;i++)
    for(j=0;j<NCOLS;j++)
        pp[i][j]=rand()%501+500; //500-1000 is 501 numbers get a number between
                                  //500 then add 500 to it, to get a number between 500 and 1000
cout<<"The data ";         //output headings
cout<<" day week t";
for(i=1;i<8;i++)
    cout<<i<<" ";
cout<<endl;
for(i=0;i<NROWS;i++)               //output data
   {cout<<i+1<<" ";
    for(j=0;j<NCOLS;j++)
       cout<<pp[i][j]<<" ";
      cout<<endl;
      }
//get the sum, min and max
min=pp[0][0];
max=pp[0][0];
for(i=0;i<NROWS;i++)
    for(j=0;j<NCOLS;j++)
        {sum+=pp[i][j];
        if(pp[i][j]<min)
             min=pp[i][j];
        if(pp[i][j]>max)
             max=pp[i][j];
        }
// and average
average=sum/(NROWS*NCOLS);
cout<<"Total usage: "<<sum<<endl;
cout<<"average daily usage: "<<average<<endl;
cout<<"minimum 1 day usage="<<min<<endl;
cout<<"maximum 1 day usage="<<max<<endl;
cout<<"days with minimum output week day ";
for(i=0;i<NROWS;i++)
    for(j=0;j<NCOLS;j++)
        if(pp[i][j]==min)
             cout<<i+1<<" "<<j+1<<endl;
cout<<"days with maximum output week day ";
for(i=0;i<NROWS;i++)
    for(j=0;j<NCOLS;j++)
        if(pp[i][j]==max)
             cout<<i+1<<" "<<j+1<<endl;     
cout<<"days with >average output week day ";
for(i=0;i<NROWS;i++)
    for(j=0;j<NCOLS;j++)
        if(pp[i][j]>average)
             cout<<i+1<<" "<<j+1<<endl;     
//output the data
for(i=0;i<NROWS;i++)
    {for(j=0;j<NCOLS;j++)
        out<<pp[i][j]<<" ";
    out<<endl;
   }                    
out.close();
system("pause");
return 0;
}