[Solved]Included Files Maincpp Include Specialarrayh Include Include Include Using Namespace Std I Q37192508


Included Files:
main.cpp:
#include “SpecialArray.h”
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int measureElementsPerLine(ifstream& inFile) {
// Add your code here.
}
int measureLines(ifstream& inFile) {
// Add your code here.
}
int main()
{
int numOfLines, numOfElements;
string fileName, dataType;
cin >> fileName >> dataType;
ifstream inFile(fileName);
// Add try statement below
numOfElements = measureElementsPerLine(inFile);
inFile.close();
inFile.open(fileName);
numOfLines = measureLines(inFile);
inFile.close();
if (dataType == “int”){
SpecialArray<int> specialArray(numOfLines,numOfElements);
inFile.open(fileName);
specialArray.readFile(inFile);
inFile.close();
specialArray.print();
specialArray.sort();
cout << “nSorted outputs: n”;
specialArray.print();
}
else if (dataType == “string”){
SpecialArray<string> specialArray(numOfLines,numOfElements);
inFile.open(fileName);
specialArray.readFile(inFile);
inFile.close();
specialArray.print();
specialArray.sort();
cout << “nSorted outputs: n”;
specialArray.print();
}
// Add catch statement below
return 0;
}
SpecialArray.h:
// Add headers here
#ifndef SpecialArray_H
#define SpecialArray_H
// Add your function declarations and definitions here. Withtemplate classes, it is recommended to put them in the samefile.
#endif
input1:
1 2 3 4
8 7 6 5
9 10 11 12
16 15 14 13
17 18 19 20
input2:
aA bB cC
fF eE dD
gG hH iI
lL kK jJ
mM nN oO
input3 is a blank file
Homework 8 Instructions In this homework, you will be using a template class to read in data from an input file and manipulate it. Here is an example of an input file gg hh її In the above example of an input file, there are 4 rows and 3 elements per row. Input files will store either strings or integers. Rows will be on different lines and all elements will be separated by a space Your template class will be called SpecialArray. It will need to contain the following private members: 1. A pointer for a 2D dynamic array. The pointer will be of templated type 2. An integer variable for the number of rows in an input file 3. An integer variable for the number of columns in an input file (AKA the number of elements per row). Your template class will also need the following public members: 1. A default constructor that sets the array pointer to null and both numbers of rows and columns to zero 2. A constructor which takes two integer parameters for the numbers of rows and columns in an input file 3. A destructor that properly release the memory allocated to the array 4. A function called readFile to read the elements in from an input file and store them in your 2D dynamic array. This function will take the ifstream variable as a parameter (assume the variable already has an associated file open- I have open/closed the file in main/unit tests, so you will not need to worry about that.). 5. A function called max with empty argument list that returns the value of the maximum element in the array 6. A function called min with empty argument list that returns the value of minimum element in the array. 6. A function called min with empty argument list that returns the value of minimum element in the array. 7. A function called sort with empty argument list which sorts each row in the array (as in, each individual row will be sorted from smallest to largest, with each element staying in its original row and each row staying in its original position) row should be separated by spaces, and each row should be on a new line (just like in the input file) file called ‘output.txit 8. A function called print with empty argument list which prints/cout’s the contents of the 2D dynamic array to the display. Elements in a 9. A function called save ToFile with empty argument list which outputs the contents of the 2D dynamic array, formatted as above, to a In addition to writing the above SpecialArray class, you will need to modify the main.cpp to achieve the following. You will fill in the code for the measureLines and measureElementsPerLine functions(which count the number of rows in the file and the number of elements per row, respectively). You may assume that all rows will have the same number of elements, and that the ifstream variable will be associated with an open file already when it is passed to these two functions Add throw clause in the above two functions. In particular, if a file associated with an ifstream variable passed to the above two functions does not exist, they will throw a run_time error which says “File does not exist. If these functions are passed an ifstream variable for an empty file, they will throw a run time error which says File is empty. Add try-catch construct in the main0 as indicated. Do not alter main outside of the areas which are commented for you Please Note Code that does not compile will receive ZERO points. Your code will be graded based on test cases (5 test cases available plus 5 more test cases hidden from students) provided in zybooks Show transcribed image text Homework 8 Instructions In this homework, you will be using a template class to read in data from an input file and manipulate it. Here is an example of an input file gg hh її In the above example of an input file, there are 4 rows and 3 elements per row. Input files will store either strings or integers. Rows will be on different lines and all elements will be separated by a space Your template class will be called SpecialArray. It will need to contain the following private members: 1. A pointer for a 2D dynamic array. The pointer will be of templated type 2. An integer variable for the number of rows in an input file 3. An integer variable for the number of columns in an input file (AKA the number of elements per row). Your template class will also need the following public members: 1. A default constructor that sets the array pointer to null and both numbers of rows and columns to zero 2. A constructor which takes two integer parameters for the numbers of rows and columns in an input file 3. A destructor that properly release the memory allocated to the array 4. A function called readFile to read the elements in from an input file and store them in your 2D dynamic array. This function will take the ifstream variable as a parameter (assume the variable already has an associated file open- I have open/closed the file in main/unit tests, so you will not need to worry about that.). 5. A function called max with empty argument list that returns the value of the maximum element in the array 6. A function called min with empty argument list that returns the value of minimum element in the array.
6. A function called min with empty argument list that returns the value of minimum element in the array. 7. A function called sort with empty argument list which sorts each row in the array (as in, each individual row will be sorted from smallest to largest, with each element staying in its original row and each row staying in its original position) row should be separated by spaces, and each row should be on a new line (just like in the input file) file called ‘output.txit 8. A function called print with empty argument list which prints/cout’s the contents of the 2D dynamic array to the display. Elements in a 9. A function called save ToFile with empty argument list which outputs the contents of the 2D dynamic array, formatted as above, to a In addition to writing the above SpecialArray class, you will need to modify the main.cpp to achieve the following. You will fill in the code for the measureLines and measureElementsPerLine functions(which count the number of rows in the file and the number of elements per row, respectively). You may assume that all rows will have the same number of elements, and that the ifstream variable will be associated with an open file already when it is passed to these two functions Add throw clause in the above two functions. In particular, if a file associated with an ifstream variable passed to the above two functions does not exist, they will throw a run_time error which says “File does not exist. If these functions are passed an ifstream variable for an empty file, they will throw a run time error which says File is empty. Add try-catch construct in the main0 as indicated. Do not alter main outside of the areas which are commented for you Please Note Code that does not compile will receive ZERO points. Your code will be graded based on test cases (5 test cases available plus 5 more test cases hidden from students) provided in zybooks
Expert Answer
Answer to Included Files: main.cpp: #include “SpecialArray.h” #include #include #include using namespace std; int measureElementsP… . . .
OR

