Create a module called Stats that can represent a file on the hard disk containing commaseparated numbers. This module should be able to load the numbers and perform the following tasks. - A Stats object should be able to display the numbers in a tabular format on ostream in a specified number of columns, column width and precision. - A Stats object should be able to display the numbers that fall within a specific range and the number of their occurrence. - A Stats object should be able to sort the numbers in an ascending or descending order. - Copying a Stats object should be done safely and doing so it should also copy the data file on the hard disk. The new file name should be the same as the original file with an added "c_" prefix. - Assigning a Stats object to another should be done safely and the content of the target file should also be overwritten by the source file. - A Stats object should also make the numbers available to the user program by indexing like an array. . A Stats object should be able to receive the data file name from the istream and load the data from the file on the hard drive. Required public functionalities construction 3 Argument Constructor Stats(unsigned columnlrlidth = 15, unsigned noOfColumns = 4, unsigned precision = 2); - columnWidth: width of each column in characters - noOfCqumns: number of columns to display the numbers in - precision: number of digits after the decimal point for each number In this case, the "Stats" object is not tied to any file on the hard drive and is empty. 4 Argument Constructor 4 Argument Constructor Stats(const char: filename, unsigned columnwidth = 1 unsigned nonColumns = 4 unsigned precision = 2); 5 , . Same as the previous constructor, but in this case, if the filename argument is not null and is successfully opened, the numbers in the file will be loaded into the Stats object. Copy Constructor Copying a Stats object should be done safely and doing so it should also copy the data file on the hard disk. The new file name should be the same as the original file with an added \"C_" prefix. Operator overloads Copy assignment Assigning a Stats object to another should be done safely and the content of the target file should also be overwritten by the source file; Index operator overloads doub1e& operatorI] (unsigned idx); Returns the reference of the number at idx index. If the index exceeds the size of the array, it should loop back to the beginning. For example, if the array size is 10, index 10 will be the reference of the element at index 0 and index 11 will be the reference of the element at index 1. If the Stats object is empty, it should return the reference of a dummy double member variable. double ope rator (unsigned idx) const; Returns the value of the number at idx index. If the index exceeds the size of the array, it should loop back to the beginning. For example, if Returns the value of the number at idx index. If the index exceeds the size of the array, it should loop back to the beginning. For example, if the array size is 10, index 10 will be the value of the element at index 0 and index 11 will be the value of the element at index 1. If the Stats object is empty, it should return zero. Boolean type conversion overload If Stats is casted to boolean, it should return true only if it is not empty. Otherwise, it should return false. Methods (Member variables) sort() void sort ( bool ascending); Sorts the numbers in ascending or descending order. size() unsigned sizel ) const; returns the number of numbers in the Stats object. nameO const cha r* name( )const; returns the name of the file tied to the Stats object. occurrenceo unsigned occurrence(double min, double max, std::ostream& ostr = std::cout); displays the numbers that fall within a specific range and the number of their occurrence on ostream. The format of the printout should be the same as printing all the numbers. helper implementations ostream insertion operator> Stats object should be able to receive the data file name from ostream (cin) using operator>>. After receiving the name, if the data file is open successfully, the numbers should be loaded into the Stats object. The tester program: Modify the tester program to test all the different circumstances/cases of the application if desired and note that the professor's tester may have many more samples than the tester program here. / / Workshop 6-diy: / / Version: 0.9 / / Date: 2021/02/20 // Author: Fardad Soleimanloo // Description: // This file tests the diy section of your workshop #include
#include #include #include "Stats.h" using namespace sdds; using namespace std; void twentyNumbers (Stats T) ; void badIndex (const Stats& T); void Copy (const string& dest, const string& source); void Dump (const string& filename) ; int main( ) { Copy ( "numLtl. csv", "numbersLtlOriginal. csv"); Copy ( "numbers. csv", "numbersOriginal. csv") ; Stats L(10, 7, 0); Stats S("numLtl. csv"), Empty, BadFilename ("badFilename" ) ; cout > L; cout >> 20 numbers of : " >>"