
Use C++
This program will read the contents of a file into an array and calculate various values based on the contents of the file.
The program will make use of a two dimensional array that has 30 rows and 5 columns.
You will be reading in the contents from a file. You will need to read the file name from cin. You will prompt for the file name with the prompt:
Enter input file name
The file will consist of up to 30 sets of 5 values. The values will all be double floating point values.
readFile function
One function you will be required to have is called readFile. This function will read the input file. Each read will read in 5 columns of information into the next available row in the two dimensional array. The first 5 values are read into row 0, the next 5 values will be read into row 1, and so on up to 30 rows of input. You will need to keep track of how many rows of input you have read in. This could be anywhere from 0 to 30. If there are more than 30 rows of input you should only read in the first 30 rows.
To help facilitate this you need to create a global const int value for the maximum number of columns.
Your program should use thisconst value when creating the arrays or when defining function prototypes and function headers.
You will also be creating a const int value for the maximum number of rows, but this will be in your main function.
You should not be hard coding 5 or 30 in your code anywhere except in the two const int declarations. The only possible exception to this is the readFile function. It is easier to just read in all 5 columns at a time. If you want to just read in an entire row at a time you can do that in the readFile function.
No other use of global variables is allowed.
Here is an example of some partial code:
... 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 = 30;
string inputFileName;
double grades[MAX_ROWS][MAX_COLUMNS];
...
int actualRows = readFile(grades, MAX_ROWS,
inputFileName);
...
}
...
Note that in the above code we are not including the max number of rows in the array when we pass it as the parameter on the readFile function. That is done so we could use the readFile function for different arrays with a different number of possible rows.
The readFile function will open the file and read the data into the passed in array. It will also close the file once it has read in the data. If the file cannot be opened the function should return -1 to the calling function. If the file does not contain any data (or contains less than 5 values) it will return 0. Otherwise the function returns the number of row read, up to 30. The file could contain more than 30 rows of data, but you should only read in the first 30. Do not try to read into the array past the valid limits of the array.
main processing
In this program you are going to read in the file name from cin. The file name will be passed to the readFile function. If the file exists the input file will contain 0 or more rows. The readFile function will return -1 if the file does not exist and 0 to MAX_ROWS depending on how many rows of data were actually in the file.
If there are 1 to 30 rows the program should:
- Calculate and display the average of all of values read into the array
- Calculate and 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
You can have additional functions if you want them, but you must have main, readFile and the 3 listed above.
The signatures for the average and columnAverage functions are:
// for the array
double average(double values[][MAX_COLUMNS], int numberRows);
// for a specified column (column)
double columnAverage(double values[][MAX_COLUMNS],
int column, int numberRows);
There will be unit tests for readFile, average, and columnAverage.
The main function will be the driver. It should create the array, read in the file name, and call all of the other functions, processing the logic as required.
Sample run 1 (valid data)
Contents of cin:
grades1.txt
Contents of grades1.txt:
61.4 89.5 62.6 89.0 100.0
99.5 82.0 79.0 91.0 72.5
Here is the output to cout:
Enter input file name
Processing 2 rows, and 5 columns
Average for all values is 82.65
Average for column 0 is 80.45
Average for column 1 is 85.75
Average for column 2 is 70.80
Average for column 3 is 90.00
Average for column 4 is 86.25
Smallest value for row 0 is 61.40
Smallest value for row 1 is 72.50
Sample run 2 (invalid file name)
Contents of cin:
badfile.txt
Here is the output to cout:
Enter input file name File "badfile.txt" could not be opened
Sample run 3 (value, but empty file)
Contents of cin:
grades.txt
Here is the output to cout:
Enter input file name The input file "grades.txt" did not contain any data

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 3 images

- Programming Language: C++ Please use the resources included and provide notes for understanding. Thanks in advance. Code two functions to fill an array with the names of every World Series-winning team from 1903 to 2020, then output each World Series winner with the number of times the team won the championship as well as the years they won them. The input file is attached, along with the main function and screenprint. Please note team names that include two words, such as Red Sox, have an underscore in place of the space. This enables you to use the extraction operator with a single string variable. The following resources are included: Here is main. #include <iostream>#include <fstream>#include<string> using namespace std; // Add function declarations and documentation here void fill(string teams[], int size);void findWinner(string teams[], int size); int main(){ const int SIZE = 118;int lastIndex;string team[SIZE]; fill(team, SIZE);findWinner(team, SIZE); return…arrow_forwardC++ Use 2 D arrays String and float Make simplearrow_forwardProve itarrow_forward
- In visual basic Create an array that will hold 10 integer values.arrow_forwardC++ Programming Code two functions to fill an array with the names of every World Series-winning team from 1903 to 2020, then output each World Series winner with the number of times the team won the championship as well as the years they won them. The input file is attached, along with the main function and screenprint. Please note team names that include two words, such as Red Sox, have an underscore in place of the space. This enables you to use the extraction operator with a single string variable. The following resources are included: Here is main. #include <iostream>#include <fstream>#include<string> using namespace std; // Add function declarations and documentation here void fill(string teams[], int size);void findWinner(string teams[], int size); int main(){ const int SIZE = 118;int lastIndex;string team[SIZE]; fill(team, SIZE);findWinner(team, SIZE); return 0;} // Add function definitions here WorldSeriesChampions.txt…arrow_forwardSorted Names Problem Assume that you already have the bubbleSort () and the svap() modules. Use pseudocode to design the main() program that allows the user to enter 20 names into a String array. Sort the array in ascending (alphabetical) order and display its contents. // The bubbleSort module accepts an array of Strings and array size // and sorts array in ascending order Module bubbleSort(String Ref array[], integer arraySize) Declare Integer index1, index2 // bubblesort scores For index1 = arraySize – 1 to 0 Step -1 For index2 = 0 to index1 – 1 If array[index2] > array[index2 + 1] Then Call swapS(array[index2], array[index2 + 1) End If End For End For End Module // The swapS module accepts two String elements and swaps their contents Module swapS(String ref a, String ref b) Declare String temp // Swap a and b Set temp = a Set a = b Set b = temp End Modulearrow_forward
- The subscript identifies the of a particular element in the array. O range value O location namearrow_forwardc++ language using just one for looparrow_forwardC++ Coding: Arrays Implement a two-dimensional character array. Use a nested loop to store a 12x6 flag. 5 x 2 stars as * Alternate = and – to represent stripe colors Use a nested loop to output the character array to the console.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





