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

How to write this in C++program. I will aso give points if someone is helpful. D

ID: 3568880 • Letter: H

Question

How to write this in C++program. I will aso give points if someone is helpful. Do not worry about the data file.  

(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 headings (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 to a datafile, power1.dat .

Explanation / Answer

The program has been completely implemented.

outputs is recorded to a datafile, power1.dat. This file will be created (if not exit) or overwritten if exits in the same folder where this .cpp file you will be executing.

Run the program and let me know if you have any doubts or changes want to make. If my code helped you Please do rate. Hope its easy to understand.

#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, m, RanNum;

m = high - low;

int pow[NROWS][NCOLS];

srand(NULL);

ofstream myfile;

myfile.open("power1.dat");

/////////////1/////////////////

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

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

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

}

}

/////////////print///////////////

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

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

myfile << " week " << i + 1;

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

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

}

}

///////////3///////////////

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;

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

myfile << "Day " << "Week" << endl;

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

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

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

cnt++;

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

}

}

}

myfile << "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]);

}

}

myfile << "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){

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

}

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

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

}

}

}

myfile.close();

return 0;

}

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