Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Main Driver File: #define INSTRUCTOR_FILE #ifdef INSTRUCTOR_FILE //#define DEBUG #include #include using std::cout; #ifdef DEBUG #include #endif const int MIDPOINT = RAND_MAX / 2; const

image text in transcribed
image text in transcribed
Main Driver File:
#define INSTRUCTOR_FILE
#ifdef INSTRUCTOR_FILE
//#define DEBUG
#include
#include
using std::cout;
#ifdef DEBUG
#include
#endif
const int MIDPOINT = RAND_MAX / 2;
const int MAX_DEVIATION = int(MIDPOINT * 0.065);
const int MAXIMUM = MIDPOINT + MAX_DEVIATION;
const int MINIMUM = MIDPOINT - MAX_DEVIATION;
void WorkerFunction(float *nestedAvg, float *linearAvg);
int main()
{
#ifdef DEBUG
float greatestPositiveDeviation = 0, greatestNegativeDeviation = 0;
time_t current, previous = time(0);
#endif
float nestedAvg = 123456e16F, linearAvg = -678421e2F;
#ifdef DEBUG
for (;;)
{
while ((current = time(0)) == previous)
;
previous = current;
#endif
WorkerFunction(&nestedAvg, &linearAvg);
cout
cout
#ifdef DEBUG
if (nestedAvg > MIDPOINT)
{
float deviation = nestedAvg - MIDPOINT;
if (deviation > greatestPositiveDeviation)
greatestPositiveDeviation = deviation;
}
else if (nestedAvg
{
float deviation = MIDPOINT - nestedAvg;
if (deviation > greatestNegativeDeviation)
greatestNegativeDeviation = deviation;
}
cout
cout
greatestPositiveDeviation
#endif
if (nestedAvg != linearAvg)
cout
else
{
if (nestedAvg MAXIMUM)
cout
"are out of the expected range. ";
else
cout
"are within the expected range. ";
}
#ifdef DEBUG
}
#endif
return EXIT_SUCCESS;
}
#endif
add C2A4E1 (8 points - C++ program) Exclude any existing source code files that may already be in your IDE project and add four new ones. naming them C2A4E1 Array Size.h. C2A4E1 Workerfunction.cpp, C2A4E1_Randomize Array.cpp. and code file C2A4E1_Compute Averages.cpp, source Also instructor-supplied C2A4E1_main-Driver.cpp. Do not write a main function! main already exists in the instructor-supplied file and it will use the code you write. File C2A4E1_Arraysize.h must contain: 1. the definitions of four const int variables that represent a 4-dimensional array's dimension sizes, which left-to-right must be 10. 7. 6. and 8. Do not specify these values anywhere else in your code. 2. a 5th const int variable that represents the array's total element count. its value must be expressed only in terms of the four previous dimension size variables - not as a literal numeric value. Do not calculate the total element count anywhere else in your code. You must include this header file and use these variables in any files that need this information. File C2A4E1 Workerfunction.cpp must contain a function named WorkerFunction Worker Function syntax: void WorkerFunction(float #nestedAvg, float 'linearAvg): Parameters: nestedAvg-a pointer to a type float object in the instructor-supplied driver file linearAvg-a pointer to another type float object in the instructor-supplied driver file Synopsis: Does only the following three things. In order: 1. declares a local, automatic, 4-dimensional array of float named testArray whose dimension sizes are specified by the variables in file C2A4E1 Array Size.h 2. makes the exact function call RandomizeArray(testArray) 3. makes the exact function call ComputeAverages(testArray, nestedAvg, linearAvg) Retur: void File C2A4E1_ RandomizeArray.cpp must contain a function named RandomizeArray. RandomizeArray syntax void RandomizeArray(--One parameter; see the parameter description below--) Parameter: You must design the appropriate parameter based upon the call to RandomizeArray shown in the synopsis of WorkerFunction above. The parameter may not be a C++ "reference" type (note 5.9). Synopsis: 1. seeds the random number generator with the value of the real time clock (RTC) using the standard library srand and time functions: 2. initializes each element of the 4D array represented by the function's parameter with the unaltered values returned from repeated calls to the library rand function: do not normalize or restrict the range of those values in any way: Return: vold File C2A4E1_Compute Averages.cpp must contain a function named ComputeAverages. ComputeAverages syntax: void ComputeAverages (--Three parameters; see the parameter description below--) Parameters: You must design the appropriate parameters based upon the call to ComputeAverages shown in the synopsis of WorkerFunction above. The parameters may not be C++ "reference" types (note 5.9). Synopsis: 1. computes the average of all elements in the 4D array represented by the function's 1st parameter accessing them in order using nested "for loops and 4D indexing: the result is stored in the address specified by the function's 2nd parameter. Ignore the potential for overflow or loss of precision when adding the element values. 2. computes the average of all elements in the 4D array represented by the function's 1st parameter, accessing them in order linearly using compact pointer operations: the result is stored in the address specified by the function's 3rd parameter. Ignore the potential for overflow or loss of precision when adding the element values. Return: void Do not declare/create any arrays other than testArray. Manually re-run your program several times: the average value should be different every time. If they're not something is wrong. Look up the description of the rand function and note the range of values it returns. Your average values should be approximately midway in this range. Submitting your solution Send all five source code files to the assignment checker with the subject line C2A4E1_ID, where ID is your 9-character UCSD student ID. See the course document titled "How to Prepare and Submit Assignments" for additional exercise formatting, submission, and assignment checker requirements. Hints: Use the decayed Right-Left rule to make sure you know the data type of the first parameter being passed to RandomizeArray and ComputeAverages. Beware of the pitfall discussed in note 13.19. If you place the call to the srand function inside the same loop that calls the rand function your results will be meaningless (Do you know why?). add C2A4E1 (8 points - C++ program) Exclude any existing source code files that may already be in your IDE project and add four new ones. naming them C2A4E1 Array Size.h. C2A4E1 Workerfunction.cpp, C2A4E1_Randomize Array.cpp. and code file C2A4E1_Compute Averages.cpp, source Also instructor-supplied C2A4E1_main-Driver.cpp. Do not write a main function! main already exists in the instructor-supplied file and it will use the code you write. File C2A4E1_Arraysize.h must contain: 1. the definitions of four const int variables that represent a 4-dimensional array's dimension sizes, which left-to-right must be 10. 7. 6. and 8. Do not specify these values anywhere else in your code. 2. a 5th const int variable that represents the array's total element count. its value must be expressed only in terms of the four previous dimension size variables - not as a literal numeric value. Do not calculate the total element count anywhere else in your code. You must include this header file and use these variables in any files that need this information. File C2A4E1 Workerfunction.cpp must contain a function named WorkerFunction Worker Function syntax: void WorkerFunction(float #nestedAvg, float 'linearAvg): Parameters: nestedAvg-a pointer to a type float object in the instructor-supplied driver file linearAvg-a pointer to another type float object in the instructor-supplied driver file Synopsis: Does only the following three things. In order: 1. declares a local, automatic, 4-dimensional array of float named testArray whose dimension sizes are specified by the variables in file C2A4E1 Array Size.h 2. makes the exact function call RandomizeArray(testArray) 3. makes the exact function call ComputeAverages(testArray, nestedAvg, linearAvg) Retur: void File C2A4E1_ RandomizeArray.cpp must contain a function named RandomizeArray. RandomizeArray syntax void RandomizeArray(--One parameter; see the parameter description below--) Parameter: You must design the appropriate parameter based upon the call to RandomizeArray shown in the synopsis of WorkerFunction above. The parameter may not be a C++ "reference" type (note 5.9). Synopsis: 1. seeds the random number generator with the value of the real time clock (RTC) using the standard library srand and time functions: 2. initializes each element of the 4D array represented by the function's parameter with the unaltered values returned from repeated calls to the library rand function: do not normalize or restrict the range of those values in any way: Return: vold File C2A4E1_Compute Averages.cpp must contain a function named ComputeAverages. ComputeAverages syntax: void ComputeAverages (--Three parameters; see the parameter description below--) Parameters: You must design the appropriate parameters based upon the call to ComputeAverages shown in the synopsis of WorkerFunction above. The parameters may not be C++ "reference" types (note 5.9). Synopsis: 1. computes the average of all elements in the 4D array represented by the function's 1st parameter accessing them in order using nested "for loops and 4D indexing: the result is stored in the address specified by the function's 2nd parameter. Ignore the potential for overflow or loss of precision when adding the element values. 2. computes the average of all elements in the 4D array represented by the function's 1st parameter, accessing them in order linearly using compact pointer operations: the result is stored in the address specified by the function's 3rd parameter. Ignore the potential for overflow or loss of precision when adding the element values. Return: void Do not declare/create any arrays other than testArray. Manually re-run your program several times: the average value should be different every time. If they're not something is wrong. Look up the description of the rand function and note the range of values it returns. Your average values should be approximately midway in this range. Submitting your solution Send all five source code files to the assignment checker with the subject line C2A4E1_ID, where ID is your 9-character UCSD student ID. See the course document titled "How to Prepare and Submit Assignments" for additional exercise formatting, submission, and assignment checker requirements. Hints: Use the decayed Right-Left rule to make sure you know the data type of the first parameter being passed to RandomizeArray and ComputeAverages. Beware of the pitfall discussed in note 13.19. If you place the call to the srand function inside the same loop that calls the rand function your results will be meaningless (Do you know why?)

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

Data Infrastructure For Medical Research In Databases

Authors: Thomas Heinis ,Anastasia Ailamaki

1st Edition

1680833480, 978-1680833485

More Books

Students also viewed these Databases questions

Question

Comment on the pH value of lattice solutions of salts.

Answered: 1 week ago