1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Snowcat [4.5K]
3 years ago
6

If there are 1 to 30 rows the program should: Calculate and display the average of all of values read into the array Calculate a

nd display the average for every column in the array Find and display the smallest value for every row in the array You will need to have different functions to: Calculate the average for the array Calculate the average for a specified column Find the smallest value in a specified row
Computers and Technology
1 answer:
Vikentia [17]3 years ago
6 0

Answer:

see explaination

Explanation:

#Header file section

#include <iostream>

#include <iomanip>

#include <string>

#include <fstream>

using namespace std;

const int MAX_COLUMNS = 5;

//readFile function reads the input file and populates the array

int readFile(double values[][MAX_COLUMNS], int maxRows, string inputFileName)

{

//variable declaration

int i, j;

string line;

//Openin the file

fstream fin(inputFileName, ios::in);

//Check file exists or not

if (fin.fail())

{

//Failed to open file

return -1;

}

else

{

//Read the data

for (i = 0; i<maxRows && fin.good(); i++)

{

for (j = 0; j<MAX_COLUMNS; j++)

{

//Read the value from each row

fin >> values[i][j];

//Return 0 if the file contains no data

if (fin.fail() && i == 0)

{

return 0;

}

}

}

}

//Close the file

fin.close();

//Return the number of rows read

return i;

}

//Avearge function calcuates the average of the array

double average(double values[][MAX_COLUMNS], int numberRows)

{

double sum = 0;

int i, j;

//Iterate over rows

for (i = 0; i<numberRows; i++)

{

//Iterate over columns

for (j = 0; j<MAX_COLUMNS; j++)

{

//Calculate the sum

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

}

}

//Find the avearge and return it

return (sum / (double)(numberRows*MAX_COLUMNS));

}

//columnAverage function calculates the average of each column

double columnAverage(double values[][MAX_COLUMNS], int column, int numberRows)

{

double sum = 0;

int i;

//Iterate over rows

for (i = 0; i<numberRows; i++)

{

//Calculate the sum

sum += values[i][column];

}

//Find the avearge and return it

return (sum / (double)(numberRows));

}

//smallestValue function returns the smallest value in each row

double smallestValue(double values[][MAX_COLUMNS], int rowNumber)

{

double minVal = values[rowNumber][0];

int i;

//Iterate over columns

for (i = 0; i<MAX_COLUMNS; i++)

{

//Calculate the sum

if (values[rowNumber][i] < minVal)

{

//Update the minimum value

minVal = values[rowNumber][i];

}

}

//Return min value

return minVal;

}

//Main function

int main()

{

int rows, cols;

const int MAX_ROWS = 20;

string inputFileName;

double grades[MAX_ROWS][MAX_COLUMNS];

int actualRows;

//Set to two decimal places

cout << fixed << setprecision(2);

//Read file name

//cout << "Enter input file name: ";

cin >> inputFileName;

//Read data from file

actualRows = readFile(grades, MAX_ROWS, inputFileName);

//Check number of rows

if (actualRows == -1)

{

//Print error message

cout << endl << "File \"" << inputFileName << "\" could not be opened " << endl;

}

else if (actualRows == 0)

{

//Print error message

cout << endl << "The input File \"" << inputFileName << "\" did not contain any data " << endl;

}

else

{

cout << "Processing " << actualRows << " rows, and " << MAX_COLUMNS << " columns " << endl;

//Print average value

cout << "Average for all values is " << average(grades, actualRows) << endl;

//Print column wise average

for (cols = 0; cols < MAX_COLUMNS; cols++)

{

//Print column wise average

cout << "Average for column " << cols << " is " << columnAverage(grades, cols, actualRows) << endl;

}

//Print row wise smallest value

for (rows = 0; rows < actualRows; rows++)

{

//Print row wise smallest value

cout << "Smallest value for row " << rows << " is " << smallestValue(grades, rows) << endl;

}

}

return 0;

You might be interested in
Does trend in computing important for organization management?​
mario62 [17]

Answer:

yes it is...................

6 0
3 years ago
BRAINLIEST FOR CORRECT ANSWERS PLS HELP
koban [17]
Either A or B. I would go with A but It can actually be B
5 0
2 years ago
Read 2 more answers
What is meant by check digit
Strike441 [17]

Answer:it is the last number in a general digit

Explanation:

6 0
3 years ago
Question :
BlackZzzverrR [31]

Answer:

D

Explanation:

Search engine optimization (SEO)

4 0
3 years ago
Part B: Find the value of G: if A = 3, b=4, and C = 5.
antiseptic1488 [7]

Answer:

G=(A^3 + B) * 4-c^2

To calculate G if A=3, b=4 and C=5

cobegin

p1: A^3 = 27

P2:C^2 =25

P3: p1 +B =31

P4:P3*4 =124

P5:P4-P2 =99

coend

Explanation:

One operation is performed at a time, and on the basis of priority as we have only one processor.

6 0
3 years ago
Other questions:
  • Select the correct answer.
    8·2 answers
  • PLEASE HURRY
    6·1 answer
  • Repl.it Assignment 4.1.2 (Guess the Number)<br> Please help me<br> I will give brainliest and a like
    10·1 answer
  • Help me pls, thank you
    12·2 answers
  • Discuss at least 1 Microsoft Windows security features that could protect data?
    5·1 answer
  • Super Scores
    11·1 answer
  • I need help!!!! 1.04
    9·1 answer
  • Is Invader Zim gonna come back?
    7·1 answer
  • What is a photographic print made from a negative image?
    7·1 answer
  • When you save a presentation with a .potx file extension, which type of powerpoint file is created?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!