Question: Encapsulate an array of doubles in a class FloatArray. Make a .h file that has all the code for FloatArray. The idea is that arrays
Encapsulate an array of doubles in a class FloatArray. Make a .h file that has all the code for FloatArray. The idea is that arrays are "evil" and need to be wrapped in some type of container that makes them behave better with respect to C++ ideals. So have a dynamically allocated representation that can be resized smaller or larger, has a [] operator for accessing elements, and a size() method so a floatarray knows it size. Also make the thing a concrete data type, that is having appropriate constructor, destructor, copy constructor and assigment operator. Also write a resize method for your FloatArray, that will resize the thing to a new given size. Have it be able to go up or down, preserving all of the old array elements that it can. Obviously if the array is size 10 and you downsize it to 5, you can only preserve 5 of the original values.
Then write a main program as follows (say, testarray.cpp). This should have a function meanstd() that takes two parameters, a FloatArray and a double by reference, and returns its double average and also returns the standard deviation in the 2nd parameter. Then in main, do the following:
Generate a FloatArray of n items (you input n); have them randomly generated as real numbers in [0,1]. Find the average and standard deviation and print these out. Then, resize the array to size 10, and calculate and print the new average and standard deviation; also print out the array that now is size 10. (Your original array size should be more than 10).
To get randomly generated doubles in the range [0,1] you do double x = double(rand()) / RAND_MAX; being sure to #include < cstdlib > for the prototype for rand() and definition of RAND_MAX.
(You can use pointers in FloatArry)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
