C++ program that will read in a two dimensional array from a file after prompting for the file from the user. The first two values in the file are the dimensions of the array. The dimensions will NOT exceed a 20 by 20 2d array and are guaranteed to be at least 0 by 0. The rest of the values will be integers delimited by white space. Determine the largest and smallest values in the file. Program Requirements: Use global constants for the maximum dimensions of the array Use a void function called FillArray that accepts four arguments (an input file object, a two dimensional array, the actual row size, and the a

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I need to write a C++ program that will read in a two dimensional array from a file after prompting for the file from the user. The first two values in the file are the dimensions of the array. The dimensions will NOT exceed a 20 by 20 2d array and are guaranteed to be at least 0 by 0. The rest of the values will be integers delimited by white space. Determine the largest and smallest values in the file.

Program Requirements:

  • Use global constants for the maximum dimensions of the array
  • Use a void function called FillArray that accepts four arguments (an input file object, a two dimensional array, the actual row size, and the actual column size). This function should read through the file and fill the array. The file object, row size, and column size should be defined as reference parameters.
  • Use a value returning function called FindMax that accepts three arguments: the 2d array as a constant parameter, the row size, and the column size. It should return the largest value in the array.
  • Use a value returning function called FindMin that accepts three arguments: the 2d array as a constant parameter, the row size, and the column size. It should return the smallest value in the array.
1. Sample Run 1 (invalid file)
Enter filename to process: nofile.dat
nofile.dat not found!
2. Sample Run 2 (dataone.dat)
Enter filename to process: dataone.dat
Min value: -4
Max value: 7
3. Sample Run 3 (datatwo.dat)
Enter filename to process: datatwo.dat
Min value: -99
Max value: 100
4. Sample Run 4 (datathree.dat)
Enter filename to process: datathree.dat
Min value: 0
Max value: 0
Transcribed Image Text:1. Sample Run 1 (invalid file) Enter filename to process: nofile.dat nofile.dat not found! 2. Sample Run 2 (dataone.dat) Enter filename to process: dataone.dat Min value: -4 Max value: 7 3. Sample Run 3 (datatwo.dat) Enter filename to process: datatwo.dat Min value: -99 Max value: 100 4. Sample Run 4 (datathree.dat) Enter filename to process: datathree.dat Min value: 0 Max value: 0
1 #include <fstream>
2 #include <iostream>
3 #include <string>
45
const int MAX_DM = 0;
6
7 void FillArray (int arr[], int row_size[], int col_size[]);
bool FindMax(int row_size[], int col_size[]);
bool FindMin(int row_size[], int col_size[]);
8
9
10
11 ✓ int main() {
12
13
14
15
16
17
18
19
20
21
int row_size[MAX_DM];
int col_size[MAX_DM];
std::string filename;
}
std::ifstream data_file;
std::cout << "Enter filename to process:
getline(std::cin, filename);
data_file.open(filename);
22
23 ✓
24
25 ✓
26
27
28
29
30
31
void FillArray (input, int arr[], int row_size[], int col_size[]) {}
32
33 v bool FindMax(int row_size[], int col_size[]) {
34
35 }
36
37 bool FindMin(int row_size[], int col_size[]) {
38
39 }
if (!data_file) {
std::cout << filename <<< "not found!";
} else {
std::cout << filename <<< '\n'
}
<< "Min value: << '\n' << "Max value: ";
Transcribed Image Text:1 #include <fstream> 2 #include <iostream> 3 #include <string> 45 const int MAX_DM = 0; 6 7 void FillArray (int arr[], int row_size[], int col_size[]); bool FindMax(int row_size[], int col_size[]); bool FindMin(int row_size[], int col_size[]); 8 9 10 11 ✓ int main() { 12 13 14 15 16 17 18 19 20 21 int row_size[MAX_DM]; int col_size[MAX_DM]; std::string filename; } std::ifstream data_file; std::cout << "Enter filename to process: getline(std::cin, filename); data_file.open(filename); 22 23 ✓ 24 25 ✓ 26 27 28 29 30 31 void FillArray (input, int arr[], int row_size[], int col_size[]) {} 32 33 v bool FindMax(int row_size[], int col_size[]) { 34 35 } 36 37 bool FindMin(int row_size[], int col_size[]) { 38 39 } if (!data_file) { std::cout << filename <<< "not found!"; } else { std::cout << filename <<< '\n' } << "Min value: << '\n' << "Max value: ";
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education