This program is in C Instructions In this assignment you wil

This program is in C++.

Instructions:

In this assignment, you will create a 3-dimensional array of numbers of size 10x10x10 (1000 elements), and populate each element of the 3D array with a randomly generated value from 0-999. The user will enter a seed value for the random number generator (use srand() and rand() functions). Populate the array in the following order: begin at (x,y,z) = (0,0,0) and progress down the x axis with y=z=0. After a line of 10 values in the x-direction is filled, advance to the next row in the y direction. After a (x,y) plane of values are filled, advance in the z-direction. The diagram shows in blue the first 13 blocks that would be populated. The 101st block will be at location (x,y,z)=(0,0,1). Next the user will enter a specific (x, y, z) location. Error check that the location occurs within the 3D vector and issue an error statement if it does not. Otherwise, compute the sum of all the values extending from the location perpendicular to the far edge of the cube in each of the 3-directions; as shown by the red blocks in the figure. Finally, output the sum of all these values.

Your program must have the following:

A 3-dimensional array of unsigned int values.

A 3 level nested loop to populate the 3-D array in the correct order.

The rand() function to generate random pseudo numbers

Error statement and early exit if an invalid index value is entered.

Sample Output:

Enter a seed: 42

Enter an index for x, y, z (0-9): 3 6 8

The sum of the perpendicular directions of x y and z is 6367.

Solution

Please Provide the Cube diagram or sum calculations. Here is the Program For Summation.

#include<iostream>
#include <stdlib.h> /* srand, rand */
#define Z_MAX 10
#define Y_MAX 10
#define X_MAX 10
using namespace std;
int main()
{
unsigned int arr1[10][10][10];
int seed;
int x_loc,y_loc,z_loc;
cout<<\"Enter a Seed: \";
cin>>seed;
srand(seed);
for (int k=0;k<Z_MAX;k++) // For z coordinate
{
for (int j=0;j<Y_MAX;j++) // For y coordinate
{
for(int i=0;i<X_MAX;i++) // For x coordinate
{
arr1[i][j][k]=rand()%1000;
}
}
}
cout<<\"Enter an index for x, y, z (0-9): \";
cin>>x_loc;
cin>>y_loc;
cin>>z_loc;
int sum=0;
if(x_loc<0 && x_loc>X_MAX && y_loc<0 && y_loc>Y_MAX && z_loc<0 && z_loc>Z_MAX)
{
cout<<\"Wrong Location Coordinates\";
exit(1);
}
else
{
if(x_loc<X_MAX/2)
{
for (int i=x_loc;i>=0;i--)
{
sum=sum+arr1[i][y_loc][z_loc];
//cout<<arr1[i][y_loc][z_loc]<<\" \";
//cout<<i<<\" \";
}
//cout<<endl;
}
else
{
for (int i=x_loc;i<X_MAX;i++)
{
sum=sum+arr1[i][y_loc][z_loc];
//cout<<arr1[i][y_loc][z_loc]<<\" \";
//cout<<i<<\" \";
}
// cout<<endl;
}
if(y_loc<Y_MAX/2)
{
for (int j=y_loc;j>=0;j--)
{
sum=sum+arr1[x_loc][j][z_loc];
// cout<<arr1[x_loc][j][z_loc]<<\" \";
// cout<<j<<\" \";
}
// cout<<endl;
}
else
{
for (int j=y_loc;j<Y_MAX;j++)
{
sum=sum+arr1[x_loc][j][z_loc];
// cout<<arr1[x_loc][j][z_loc]<<\" \";
// cout<<j<<\" \";
}
// cout<<endl;
}
if(z_loc<Z_MAX/2)
{
for (int k=z_loc;k>=0;k--)
{
sum=sum+arr1[x_loc][y_loc][k];
// cout<<arr1[x_loc][y_loc][k]<<\" \";
// cout<<k<<\" \";
}
// cout<<endl;
}
else
{
for (int k=z_loc;k<Z_MAX;k++)
{
sum=sum+arr1[x_loc][y_loc][k];
// cout<<arr1[x_loc][y_loc][k]<<\" \";
// cout<<k<<\" \";
}
// cout<<endl;
}
cout<<\"The sum of the perpendicular directions of x y and z is \"<<sum;
}
return 0;
}

This program is in C++. Instructions: In this assignment, you will create a 3-dimensional array of numbers of size 10x10x10 (1000 elements), and populate each e
This program is in C++. Instructions: In this assignment, you will create a 3-dimensional array of numbers of size 10x10x10 (1000 elements), and populate each e
This program is in C++. Instructions: In this assignment, you will create a 3-dimensional array of numbers of size 10x10x10 (1000 elements), and populate each e

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site