Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Main Driver File: #define INSTRUCTOR_FILE #ifdef INSTRUCTOR_FILE #include #include #include #include C2A4E2_StorageMap5D.h #define D_A 2 #define D_B 3 #define D_C 4 #define D_D 5 #define
Main Driver File:
#define INSTRUCTOR_FILE
#ifdef INSTRUCTOR_FILE
#include
#include
#include
#include "C2A4E2_StorageMap5D.h"
#define D_A 2
#define D_B 3
#define D_C 4
#define D_D 5
#define D_E 6
int main(void)
{
int ix0, ix1, ix2, ix3, ix4;
int foo[D_A][D_B][D_C][D_D][D_E];
double bar[D_A][D_B][D_C][D_D][D_E];
long big[D_E][D_D][D_C][D_B][D_A];
float deal[D_E][D_D][D_C][D_B][D_A];
// seed random # generator
srand((unsigned)time(NULL));
// store all values before testing any
for (ix0 = 0; ix0
for (ix1 = 0; ix1
for (ix2 = 0; ix2
for (ix3 = 0; ix3
for (ix4 = 0; ix4
{
foo[ix0][ix1][ix2][ix3][ix4] = rand();
bar[ix0][ix1][ix2][ix3][ix4] = rand() + rand() / 321.0;
}
for (ix0 = 0; ix0
for (ix1 = 0; ix1
for (ix2 = 0; ix2
for (ix3 = 0; ix3
for (ix4 = 0; ix4
{
big[ix0][ix1][ix2][ix3][ix4] = rand();
deal[ix0][ix1][ix2][ix3][ix4] = rand() + rand() / 123.0F;
}
// Test all stored values.
for (ix0 = 0; ix0
for (ix1 = 0; ix1
for (ix2 = 0; ix2
for (ix3 = 0; ix3
for (ix4 = 0; ix4
{
if (StorageMap5D((int *)foo, ix0, ix1, ix2, ix3, ix4,
D_B, D_C, D_D, D_E) != foo[ix0][ix1][ix2][ix3][ix4])
{
fprintf(stderr, "Error: foo[%d][%d][%d][%d][%d] ",
ix0, ix1, ix2, ix3, ix4);
return EXIT_FAILURE;
}
if (StorageMap5D((double *)bar, ix0, ix1, ix2, ix3, ix4,
D_B, D_C, D_D, D_E) != bar[ix0][ix1][ix2][ix3][ix4])
{
fprintf(stderr, "Error: bar[%d][%d][%d][%d][%d] ",
ix0, ix1, ix2, ix3, ix4);
return EXIT_FAILURE;
}
}
for (ix0 = 0; ix0
for (ix1 = 0; ix1
for (ix2 = 0; ix2
for (ix3 = 0; ix3
file C2A4E2 (6 points - Program) Fichida any existing source code files that may already be in your IDE project and add a new one. and it will use the code you write. C2A4E2_main-Driver.c. Do not wife a main function main already exists in the instructor-supplied file File C2A4E2_StorageMap5D.h must contain a macro named StorageMap50. StorageMap5D syntax (never actually prototype a macro): StorageMaps (ptr, idxe, idx1, 1dx2, idx3, idxa, dimi, dim2, dim3, dime) Parameters: ptr-pointer to the first element of a block of memory to be used as a 5-dimensional arroy idxe, idxi. idx2. idx3. idx4 - the indices of the desired element of the ortay dimi, dim2, dim3, dimd - the rightmost 4 dimensions of the array (dime isn't needed) Synopsis: implements the storage map equation for a 5-dimensional array of arbitrary type having arbitrary dimension values. It may be used to access the elements of any existing 5-dimensional array of any type and sufficient size, or in the general case may be used to access any arbitrary block of memory of sufficient size as if it were a 5-dimensional artay. Value: the element specified by the macro's 2nd through 6th arguments. Example: For an arbitrary array of any type originally declared as type test[SZ_A][SZ_B][sz_c][SZ_D][SZ_E]; or any block of dynamic memory allocated by type *test (type *)malloc((SZ_A . SZ_B. sz_CSZ_DSZ_E) sizeof(type) the expression StorageMapD((type *)test, 68, 73, 22, 58, 49, SZ_B, sz_C, SZ_D, SZ_E) would access the following element of the array or the dynamically-allocated memory block. [68][73][22][58] [49] if you get any assignment checker errors/warnings regarding instructor-supplied file C2A4E2_main-Driver.c it is because there is a problem in your macro, Submitting your solution Send both source code files to the assignment checker with the subject line C2A4E2ID. 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: A typical procedure for testing any storage map equation is to first declare a standard array having the same type and dimension sizes as the storage map equation and store a different value in each element, then point the storage map equation to that array and verify that it accesses the expected values. That is what the instructor-supplied source code file for this exercise does for (ix4 = 0; ix4
{
if (StorageMap5D((long *)big, ix0, ix1, ix2, ix3, ix4,
D_D, D_C, D_B, D_A) != big[ix0][ix1][ix2][ix3][ix4])
{
fprintf(stderr, "Error: big[%d][%d][%d][%d][%d] ",
ix0, ix1, ix2, ix3, ix4);
return EXIT_FAILURE;
}
if (StorageMap5D((float *)deal, ix0, ix1, ix2, ix3, ix4,
D_D, D_C, D_B, D_A) != deal[ix0][ix1][ix2][ix3][ix4])
{
fprintf(stderr, "Error: deal[%d][%d][%d][%d][%d] ",
ix0, ix1, ix2, ix3, ix4);
return EXIT_FAILURE;
}
}
--ix0;
--ix1;
--ix2;
--ix3;
--ix4;
if (StorageMap5D((long *)big, ix0 + 1 - 1, ix1 + 2 - 2, ix2 + 3 - 3,
ix3 + 4 - 4, ix4 + 5 - 5, D_D + 4 - 4, D_C + 3 - 3, D_B + 2 - 2,
D_A + 1 - 1) !=
big[ix0][ix1][ix2][ix3][ix4])
{
fprintf(stderr, "Error 2: big[%d][%d][%d][%d][%d] ",
ix0, ix1, ix2, ix3, ix4);
return EXIT_FAILURE;
}
printf("Assignment 4 Exercise 2: No errors detected! ");
return EXIT_SUCCESS;
}
#endif
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