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
Which of the following translates packets so that the node can understand them once they enter through a port?
zubka84 [21]

Answer:

The node translates on its own.

Explanation:

3 0
3 years ago
Read 2 more answers
2 Consider the sequence of keys (5,16,22,45,2,10,18,30,50,12,1). Draw the result of inserting entries with these keys (in the gi
Juliette [100K]

Answer:

A) (2,4) tree

  • Insertion of  key 45 makes key unbalanced and this is because it violates the 2,4 tree so we split the node
  • insertion of key 10 makes key unbalanced and this is because it violates the 2,4 tree so we split the node

B) Red-black tree

Explanation:

The diagrams for the solutions are attached showing the results of inserting entries

6 0
3 years ago
Where or what website can I download anime's? For free ​
Artemon [7]

<em>https://todo-anime.com/</em>

5 0
2 years ago
⣠⣤⣤⣤⣤⣤⣶⣦⣤⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀
mestny [16]

Answer:

LOL sweet

Explanation:

4 0
2 years ago
Read 2 more answers
SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. Assume that the classes listed in the Java Quick R
Ne4ueva [31]

Answer:

Check the explanation

Explanation:

CODE:-

import java.util.*;

class UserName{

  ArrayList<String> possibleNames;

  UserName(String firstName, String lastName){

      if(this.isValidName(firstName) && this.isValidName(lastName)){

          possibleNames = new ArrayList<String>();

          for(int i=1;i<firstName.length()+1;i++){

              possibleNames.add(lastName+firstName.substring(0,i));

          }  

      }else{

          System.out.println("firstName and lastName must contain letters only.");

      }

  }

  public boolean isUsed(String name, String[] arr){

      for(int i=0;i<arr.length;i++){

          if(name.equals(arr[i]))

              return true;

      }

      return false;

  }

  public void setAvailableUserNames(String[] usedNames){

      String[] names = new String[this.possibleNames.size()];

      names = this.possibleNames.toArray(names);

      for(int i=0;i<usedNames.length;i++){

          if(isUsed(usedNames[i],names)){

              int index = this.possibleNames.indexOf(usedNames[i]);

              this.possibleNames.remove(index);

              names = new String[this.possibleNames.size()];

              names = this.possibleNames.toArray(names);

          }

      }

  }

  public boolean isValidName(String str){

      if(str.length()==0) return false;

      for(int i=0;i<str.length();i++){

          if(str.charAt(i)<'a'||str.charAt(i)>'z' && (str.charAt(i)<'A' || str.charAt(i)>'Z'))

              return false;

      }

      return true;

  }

  public static void main(String[] args) {

      UserName person1 = new UserName("john","smith");

      System.out.println(person1.possibleNames);

      String[] used = {"harta","hartm","harty"};

      UserName person2 = new UserName("mary","hart");

      System.out.println("possibleNames before removing: "+person2.possibleNames);

      person2.setAvailableUserNames(used);

      System.out.println("possibleNames after removing: "+person2.possibleNames);

  }

}

Kindly check the attached image below for the code output.

5 0
3 years ago
Other questions:
  • Which of the following assignment statements contains a LOGICAL error? I multiply two numbers when they need to be added I write
    9·1 answer
  • The trademarked name of the accepted standard for configuring wireless networks is _______________
    12·1 answer
  • Multiple users report that the network printer, which is connected through the print server, is not printing. Which of the follo
    12·1 answer
  • What are two most common types of microcomputers? a. IBM-style PCs and Macs c. Clients and Servers b. Mainframes and Minicompute
    14·1 answer
  • What are 7 good facts on Computer Viruses?
    10·1 answer
  • To have different formatting for odd and even rows, select the _____ option.
    8·1 answer
  • Create a derived class called Car that inherits from Vehicle. The constructor should call the base class constructor, with 4 for
    13·1 answer
  • The mobile nodes (devices) add or leave a Mobile Ad-hoc Network, changing the _____ of this network over time. a) infrastructure
    14·1 answer
  • What are search tries? Why are they more efficient than usualsearching<br><br> algorithms?
    8·1 answer
  • The Binary Search algorithm works by testing a mid-point, then eliminating half of the list.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!