Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include #include #include #include const int ARRAY _ SIZE = 1 0 0 0 ; int * createArray ( int length ) { int *
#include
#include
#include
#include
const int ARRAYSIZE ;
int createArrayint length
int array new intlength;
for int i ; i length; i
arrayi rand; Random numbers between and inclusive
return array;
void writeBinaryint values, int length
std::ofstream outputFilebinarydat", std::ios::binary;
if outputFile
std::cerr "Error opening binary file for writing." std::endl;
return;
outputFile.writereinterpretcast&length sizeoflength;
for int i ; i length; i
outputFile.writereinterpretcast&valuesi sizeofvaluesi;
outputFile.close;
int readBinaryint& length
std::ifstream inputFilebinarydat", std::ios::binary;
if inputFile
std::cerr "Error opening binary file for reading." std::endl;
return nullptr;
inputFile.readreinterpretcast&length sizeoflength;
int array new intlength;
for int i ; i length; i
inputFile.readreinterpretcast&arrayi sizeofarrayi;
inputFile.close;
return array;
int main
srandstaticcasttimenullptr;
Module
int arrayLength ARRAYSIZE;
int dynamicArray createArrayarrayLength;
writeBinarydynamicArray arrayLength;
delete dynamicArray;
dynamicArray nullptr;
int localLength;
int localArray readBinarylocalLength;
for int i ; i localLength; i
std::cout localArrayi;
std::cout std::endl;
delete localArray;
return ;
Please look at module first before answering module because it is connected the link is attached on top Module Recommended Implementation Details
This second part of the signature assignment will rework the code to create the binary file. Then,
you will develop classes for reading and analyzing the binary data read from the file.
Write a function named createBinaryFile, which takes the name of a file as its first
parameter and the size of the data as the second parameter and returns nothing. Copy the code
from the createArray function for creating the array of random values into this function.
Modify writeBinary to take an additional string parameter; it is the file name. Add a call to
the existing writeBinary function and pass three parameters. When this code works
correctly, eliminate the createArray function since it is no longer needed.
Write a class called BinaryReader. It should have instance variables of an integer pointer
and an integer. The pointer will point to an array of integers; named values. The integer will
hold the arrays size, named size. Add a constructor that takes a single parameter, a constant
string reference to a file name. Add a private method called readValues with one parameter,
the name of the input file. Copy the code from the readBinary function to open the file, input
the array size into the size instance variable, and create the dynamic array using the values
instance variable. Now, read the values from the file into the array. Eliminate the existing
readBinary function. The constructor should call the readValues method to populate the
array and size instance variables. Add a destructor to delete the integer array. Finally, add
getValues and getSize as public methods that return the instance variables.
Write a second class called Analyzer. This class has two instance variables: an integer pointer
representing an array of integers named values and an integer representing the arrays size
named size. Add a constructor with two parameters: an integer pointer and an integer. Add a
private cloneValues method that creates an integer array, copies the values from the array
parameter into its elements, copies the size, and returns nothing. The constructor should call the
cloneValues method, passing it the two parameter values. Add a destructor to delete the
dynamic array. Add an analyze method that determines the mean mathematical average
minimum value, and maximum value from the values in the array. Be certain to return a double
value for the mean value. Return a string that holds this statistical information.
Update the main function to call create binary file, passing the name as binarydat.
Create a BinaryReader instance and write a loop that iterates over the values from the
instance to ensure it works correctly. After it is working, the loop should be removed. Next,
create an instance of the Analyzer class, passing its constructor the values and size using the
BinaryReaders get methods for its values and size. Call the analyze method and print out
the results.
Use these func
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started