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

Combine questions a and b and code one program to do both activities. Fill the 1

ID: 3688216 • Letter: C

Question

Combine questions a and b and code one program to do both activities. Fill the 10X7 array with random numbers between 1-100. Do not use the srand() command. Show the source and output.

Power Plant Data. The data file power1.dat contains a power plant output in megawatts over a period of 10 weeks. Each row of data contains 7 floating point numbers that represent 1 weeks’ data. In developing the following programs, use symbolic constants NROWS and NCOLS to represent the number of rows and columns in the array used to store the data.

a. Write a program to compute and print the average power output over this period. Also print the number of days with greater than average power output.

b. Write a program to print a report that lists the average power output for the first day of the week, then for the second day of the week, and so on. Print the information in the following format:

Day x: Average Power Output in Megawatts: xxxx.xx

Explanation / Answer

Data is incomplete.power1.dat file is not given.

#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <stdio.h>
#include <fstream>
#define NROWS 10
#define NCOLS 7
using namespace std;
int main()
{
   int low = 500, high = 1000, middle, RanNum;
   middle = high - low;
   int pow[NROWS][NCOLS];
   srand(NULL);

   ofstream fout;

   fout.open("power1.dat");

   for(int i = 0; i< NROWS; ++i){

       for(int j = 0; j < NCOLS; ++j){

           pow[i][j] = rand() % (middle) + low;

       }

   }

  
   fout << " Day 1" << " Day 2" << " Day 3"<< " Day 4"<< " Day 5"<< " Day 6"<< " Day 7";

   for(int i = 0; i <NROWS; ++i){

       fout << " week " << i + 1;

       for(int j = 0; j < NCOLS; ++j){

           fout << " " << pow[i][j];

       }

   }

  
   int sum = 0;

   for(int i = 0; i <NROWS; ++i){

       for(int j = 0; j < NCOLS; ++j){

           sum = sum + pow[i][j];

       }

   }

   int avgpow = sum / (NCOLS * NROWS);

   int cnt = 0;

   fout << " Day of the Week and Number of week output is greater than average" << endl;

   fout << "Day " << "Week" << endl;

   for(int i = 0; i <NROWS; ++i){

       for(int j = 0; j < NCOLS; ++j){

           if(pow[i][j] > avgpow){

               cnt++;

               fout << i + 1 << " " << j+1 << endl;

           }

       }

   }

   fout << "Number of days output greater than average power " << cnt << endl;

   int minp = INT_MAX, maxp = INT_MIN;

   for(int i = 0; i <NROWS; ++i){

       for(int j = 0; j < NCOLS; ++j){

           minp = min(minp, pow[i][j]);

           maxp = max(maxp, pow[i][j]);

       }

   }

   fout << "printing Minimum Power and Maximum power day of the week and week number" << endl;

   int kmin =0, kmax = 0;

   for(int i = 0; i <NROWS; ++i){

       for(int j = 0; j < NCOLS; ++j){

           if(pow[i][j] == minp){

               fout << i + 1 << " " << j + 1 << endl;

           }

           if(pow[i][j] == maxp){

               fout << i + 1 << " " << j + 1 << endl;

           }

       }

   }

   fout.close();

   return 0;

}