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

#include <iostream> #include <fstream> #include <iomanip> using namespace std; c

ID: 3715720 • Letter: #

Question

#include <iostream>

#include <fstream>

#include <iomanip>

using namespace std;

const int MAX_COLUMNS = 5;

// read input file and populate the array
int readFile(double values[][MAX_COLUMNS], int maxRows, string inputFileName);
int main()
{
const int MAX_ROWS = 20;
string inputFileName;
double grades[MAX_ROWS][MAX_COLUMNS];

// Setting the precision
cout << setprecision(2) << fixed << showpoint;

cin >> inputFileName;


int actualRows = readFile(grades, MAX_ROWS, inputFileName);

if (actualRows == -1)
{
cout << "File "" << inputFileName << "" could not be opened" << endl;
}
else if (actualRows == 0)
{
cout << "The input file "" << inputFileName << "" did not contain any data" << endl;
}
else
{
double tot = 0.0, avg = 0.0;

for (int i = 0; i < actualRows; i++)
{
for (int j = 0; j < MAX_COLUMNS; j++)
{
tot += grades[i][j];
}
}

avg = tot / ((actualRows) * (MAX_COLUMNS));
cout << "Processing " << actualRows << " rows, and " << MAX_COLUMNS << " columns" << endl;

cout << "Average for all values is " << avg << endl;
for (int i = 0; i < MAX_COLUMNS; i++)
{
avg = 0;
tot = 0;
for (int j = 0; j < actualRows; j++)
{
tot += grades[j][i];
}
avg = tot / actualRows;
cout << "Average for column " << i << " is " << avg << endl;
}

double min;
for (int i = 0; i < actualRows; i++)
{
min = grades[i][0];
for (int j = 0; j < MAX_COLUMNS; j++)
{
if (min > grades[i][j])
min = grades[i][j];
}

cout << "Smallest value for row " << i << " is " << min << endl;
}
}

return 0;
}

int readFile(double grades[][MAX_COLUMNS], int MAX_ROWS, string inputFileName)
{
// defines an input stream for the data file
ifstream dataIn;
int i = 0, j = 0;
// Opening the input file
dataIn.open(inputFileName.c_str());
// checking whether the file name is valid or not
if (dataIn.fail())
{
return -1;
}
else
{

double grade;
while (dataIn >> grade)
{


if (j == 5)
{
j = 0;
i++;
}
grades[i][j] = grade;

j++;
}
if (i == 0)
{
dataIn.close();
return 0;
}
dataIn.close();
return i + 1;
}
}

zy 6.16. L80 Lesson 10 (Par x Y e- Outputs And MUST M × ? secure https://learn.zybooks.com/zybook/UTDALLASCS 11 36Spring2018LabB/Chapter/6/section/16 . ::: Apps D Payments ? Exar'' P: Probabilily! - ?? ? zyBooks ylyCS 1135 home 6.1 Lab Lesson 10 (Pert 2 ot 2 ez,000ks catalog @repro ? Hijnsen ? :Unit lest A DSA Test average function Complation fallad 014 1: Unit test lest colurnnAve functin e550 1Upat:2.cpp: In -u-o--on ?.ccol testFa55ed(,'1 Complatian faile Previous submissions 6:52 PM on 4/24/18 8/40 View 6:59 PM Type here to search 4/24/2018

Explanation / Answer

PLEASE REFER BELOW CODE

#include <iostream>

#include <fstream>

#include <iomanip>

using namespace std;

const int MAX_COLUMNS = 5;

// read input file and populate the array
int readFile(double values[][MAX_COLUMNS], int maxRows, string inputFileName);
int main()
{
const int MAX_ROWS = 20;
string inputFileName;
double grades[MAX_ROWS][MAX_COLUMNS];

// Setting the precision
cout << setprecision(2) << fixed << showpoint;

cin >> inputFileName;


int actualRows = readFile(grades, MAX_ROWS, inputFileName);

if (actualRows == -1)
{
cout << "File "" << inputFileName << "" could not be opened" << endl;
}
else if (actualRows == 0)
{
cout << "The input file "" << inputFileName << "" did not contain any data" << endl;
}
else
{
double tot = 0.0, avg = 0.0;

for (int i = 0; i < actualRows; i++)
{
for (int j = 0; j < MAX_COLUMNS; j++)
{
tot += grades[i][j];
}
}

avg = tot / ((actualRows) * (MAX_COLUMNS));
cout << "Processing " << actualRows << " rows, and " << MAX_COLUMNS << " columns" << endl;

cout << "Average for all values is " << avg << endl;
for (int i = 0; i < MAX_COLUMNS; i++)
{
avg = 0;
tot = 0;
for (int j = 0; j < actualRows; j++)
{
tot += grades[j][i];
}
avg = tot / actualRows;
cout << "Average for column " << i << " is " << avg << endl;
}

double min;
for (int i = 0; i < actualRows; i++)
{
min = grades[i][0];
for (int j = 0; j < MAX_COLUMNS; j++)
{
if (min > grades[i][j])
min = grades[i][j];
}

cout << "Smallest value for row " << i << " is " << min << endl;
}
}

return 0;
}

int readFile(double grades[][MAX_COLUMNS], int MAX_ROWS, string inputFileName)
{
// defines an input stream for the data file
ifstream dataIn;
int i = 0, j = 0;
// Opening the input file
dataIn.open(inputFileName.c_str());
// checking whether the file name is valid or not
if (dataIn.fail())
{
return -1;
}
else
{

double grade;
while (dataIn >> grade)
{


if (j == 5)
{
j = 0;
i++;
}
grades[i][j] = grade;

j++;
}
if (i == 0)
{
dataIn.close();
return 0;
}
dataIn.close();
return i + 1;
}
}

THE COMPILATION ERROR WHICH YOU ARE GETTING IS NOT WITH THIS CODE. THE VARIABLE IN COMPILATION ERROR columnAverage IS NOT AT ALL USED OR EVEN DECLARED IN THIS CODE