Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Module 2 Recommended Implementation Details This second part of the signature assignment will rework the code to create the binary file. Then, you will develop

Module 2 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 binary.dat.
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 function and class headers:
class Analyzer
void cloneValues(int* values, int size)
Analyzer(int* values, int size)
~Analyzer()
std::string analyze()
class BinaryReader
void readValues(const std::string& name)
BinaryReader(const std::string& name)
~BinaryReader()
int* getValues()
int getSize()
void createBinaryFile(const std::string& name, int length)
void writeBinary(int* values, int length, const std::string&
name)
Example output:
The minimum value is 0
The maximum value is 999
The mean value is 499.495

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

Students also viewed these Databases questions

Question

What are the HRM implications of this type of merger?

Answered: 1 week ago

Question

What is an RPIC, and where was it required?

Answered: 1 week ago