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
All living organisms make up the (4 points)
Airida [17]
Biosphere..
hope it helepd
3 0
3 years ago
You receive an email that appears to legitimately be from your Bank. The email indicates the need for verification of your infor
anzhelika [568]

Answer:

phishing

Explanation:

6 0
2 years ago
Read 2 more answers
A Game Object must have a Transform<br><br> True<br><br> False
vovikov84 [41]

Answer:

Yes

Explanation:because,have to update there apps or games and change there characters

3 0
3 years ago
When describing memory, ____________ is the first component required in the process necessary for retention?
8_murik_8 [283]
Depends on how deep you're willing to go to really,
You need one of a few arrangements of flip flop circuits to keep 1-bit state.
Going deeper, you need either NAND, or NOR gates(or a bunch of other ones) and connectors.
Even deeper, you'll require diodes or transistors to build the logic gates.
Beyond that is particle physics.
8 0
3 years ago
Using Python I need to Prompt the user to enter in a numerical score for a Math Class. The numerical score should be between 0 a
yaroslaw [1]

Answer:

<em>The program doesn't use comments; See explanation section for detailed line by line explanation</em>

<em>Program starts here</em>

def lettergrade(subject,score):

     print(subject+": "+str(score))

     if score >= 90 and score <= 100:

           print("Letter Grade: A")

     elif score >= 80 and score <= 89:

           print("Letter Grade: B")

     elif score >= 70 and score <= 79:

           print("Letter Grade: C")

     elif score >= 60 and score <= 69:

           print("Letter Grade: D")

     elif score >= 0 and score <= 59:

           print("Letter Grade: F")

     else:

           print("Invalid Score")

maths = int(input("Maths Score: "))

english = int(input("English Score: "))

pe = int(input("PE Score: "))

science = int(input("Science Score: "))

arts = int(input("Arts Score: "))

lettergrade("Maths Class: ",maths)

lettergrade("English Class: ",english)

lettergrade("PE Class: ",pe)

lettergrade("Science Class: ",science)

lettergrade("Arts Class: ",arts)

Explanation:

The program makes the following assumptions:

Scores between 90–100 has letter grade A

Scores between 80–89 has letter grade B

Scores between 70–79 has letter grade C

Scores between 60–69 has letter grade D

Scores between 0–69 has letter grade E

<em>Line by Line explanation</em>

This line defines the lettergrade functions; with two parameters (One for subject or class and the other for the score)

def lettergrade(subject,score):

This line prints the the score obtained by the student in a class (e.g. Maths Class)

     print(subject+": "+str(score))

The italicized determines the letter grade using if conditional statement

<em>This checks if score is between 90 and 100 (inclusive); if yes, letter grade A is printed</em>

<em>      if score >= 90 and score <= 100:</em>

<em>            print("Letter Grade: A")</em>

<em />

<em>This checks if score is between 80 and 89 (inclusive); if yes, letter grade B is printed</em>

<em>      elif score >= 80 and score <= 89:</em>

<em>            print("Letter Grade: B")</em>

<em />

<em>This checks if score is between 70 and 79 (inclusive); if yes, letter grade C is printed</em>

<em>      elif score >= 70 and score <= 79:</em>

<em>            print("Letter Grade: C")</em>

<em />

<em>This checks if score is between 60 and 69 (inclusive); if yes, letter grade D is printed</em>

<em>      elif score >= 60 and score <= 69:</em>

<em>            print("Letter Grade: D")</em>

<em />

<em>This checks if score is between 0 and 59 (inclusive); if yes, letter grade F is printed</em>

<em>      elif score >= 0 and score <= 59:</em>

<em>            print("Letter Grade: F")</em>

<em />

<em>If input score is less than 0 or greater than 100, "Invalid Score" is printed</em>

<em>      else:</em>

<em>            print("Invalid Score")</em>

This line prompts the user for score in Maths class

maths = int(input("Maths Score: "))

This line prompts the user for score in English class

english = int(input("English Score: "))

This line prompts the user for score in PE class

pe = int(input("PE Score: "))

This line prompts the user for score in Science class

science = int(input("Science Score: "))

This line prompts the user for score in Arts class

arts = int(input("Arts Score: "))

The next five statements is used to call the letter grade function for each class

lettergrade("Maths Class: ",maths)

lettergrade("English Class: ",english)

lettergrade("PE Class: ",pe)

lettergrade("Science Class: ",science)

lettergrade("Arts Class: ",arts)

7 0
2 years ago
Other questions:
  • What is faster a hi-speed usb port or superspeed usb port?
    13·1 answer
  • why is wrong timing, poor technology, bad implementation and politics in business affected the OSI model as a standard
    5·1 answer
  • How can a user view the options for Junk E-mail?
    11·2 answers
  • William found out that someone used his report on American culture without his permission. What is William a victim of?
    8·2 answers
  • Sally needs to teach her class how to convert a decimal number to a binary number. What is the first step she should take to sta
    5·1 answer
  • What is a relationship between a object and a class?
    7·1 answer
  • A(n) __ is a list of main points and sub-points of a topic to include in a presentation
    14·2 answers
  • Why do we need to make a plan before actions?
    7·1 answer
  • Choose all that apply.
    5·2 answers
  • How do you initiate a sprite’s actions in a scene?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!