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
______ is the ability of a system to do more than one thing at a time. A. Multibusing c. online processing b. Multiprocessing d.
mrs_skeptik [129]

Answer:

Multiprocessing.

Explanation:

In multiprocessing the system uses two or more processors to do more tasks simultaneously.

8 0
2 years ago
Select the proper ergonomic keyboarding techniques.
SCORPION-xisa [38]

Answer:

The correct options are;

-Position the keyboard directly in front and close to you so you don't have an excessive reach

-Keep your shoulders, arms, hands and fingers relaxed

-Position your wrists straight or in neutral position while typing

-Adjust your chair height and position so your feet rest flat on the floor, or add a footrest to compensate for a higher chair

-Adjust the keyboard height so that your shoulders can relax and your arms are straight in front of you

Explanation:

1) It is important to keep the fingers in a relaxed position when typing

2) Ensure to type in a tapping fashion when typing rather than pressing on the keys of the keyboard

3) The fingernails should be kept short when frequent typing is done

4) The wrist is better kept above the keyboard than resting on it

5) Ensure that the mouse is easily reached.

4 0
3 years ago
_____ is a form of witty, amusing speech that is often used to bring people together.
Neporo4naja [7]

Answer:Informative

Explanation:

5 0
3 years ago
Read 2 more answers
Which type of address is the ip address 232. 111. 255. 250?.
Nitella [24]

Answer:

It is either an internal IP address or it is a private IP address.

Explanation:

6 0
2 years ago
what new technology led to the chaos that spurred the establishment of the federal communications commission?
adelina 88 [10]

Answer:

The digital read Harry quaant

3 0
1 year ago
Other questions:
  • Clicking the _____ box completes an entry. cancel formula enter tab
    15·1 answer
  • What would I need to make the perfect music video
    10·1 answer
  • In this problem we consider sending real-time voice from Host A to Host B over a packet-switched network (VoIP). Host A converts
    12·1 answer
  • Two powerboats are about to cross paths. what should the boat on the starboard (right) do?
    11·1 answer
  • List three tacos there are several from the opening page of the help and support center.
    5·1 answer
  • The best way to achieve stronger encryption is to
    13·1 answer
  • What is the definition of a digital signal?
    14·1 answer
  • Write a program that calculates the total amount of a meal purchased at a restaurant by a customer. The program should ask the u
    15·1 answer
  • Which of the following could be a constructor for the public class MyClass? a. public MyClass() b. public void MyClass() c. publ
    7·1 answer
  • Susan discovers the following log entries that occurred within seconds of each other in her Squert (a Sguil web interface) conso
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!