A large rectangular packaging container holds n columns by m rows by k stack of
ID: 3565294 • Letter: A
Question
A large rectangular packaging container holds n columns by m rows by k stack of cube shaped packages as shown below. Each box can hold maximum 7 items.
1. Develop a program which will perform the following: a. Accept from the user the values for n, m and k in the following range 3<=n<=6, 2<=m<=5 and 3<=k<=6
b. Define a 3D array n by m by k which represents the container.
c. Fill the array with random numbers that represents the number of items in each box.
d. Calculate upon request one of the following:
a. The total number of items in a certain stack of boxes.
b. The total number of items in a certain raw (m)
c. The number of items in a certain box
d. How many boxes have a certain number of items (e.g. how many boxes have 4 items in them)
e. Total number of items stored in the container.
Print the corresponding results
Allow the user to request answers without the need to rerun the program
A large rectangular packaging container holds n columns by m rows by k stack of cube shaped packages as shown below. Each box can hold maximum 7 items. 1. Develop a program which will perform the following: a. Accept from the user the values for n, m and k in the following range 3Explanation / Answer
clear all
clc
while(1)
m=input('Enter the number of rows ie value of m in between 2 to 5 ');
if m<=5 && m>=2
break;
else
disp('Incorrect value, re enter');
end
end
while(1)
n=input('Enter the number of column ie value of n in between 3 to 6 ');
if n<=6 && n>=3
break;
else
disp('Incorrect value, re enter');
end
end
while(1)
k=input('Enter the number of stack ie value of ink between 3 to 6 ');
if k<=6 && k>=3
break;
else
disp('Incorrect value, re enter');
end
end
box=randi([0 7],m,n,k);
while(1)
choice=input('What do you want to do? Enter a,b,c,d,e to choose an option any other to exit a.The total number of items in a certain stack of boxes. b. The total number of items in a certain raw (m) c. The number of items in a certain box d. How many boxes have a certain number of items e. Total number of items stored in the container. ','s');
if choice=='a'
item_stack=input('Number of items in which stack do you want to know? ');
if item_stack<=k
sum_stack=0;
for i=1:m
for j=1:n
sum_stack= sum_stack+ box(i,j,item_stack);
end
end
fprintf('Number of items %d ',sum_stack);
else
disp('Wrong Input ');
end
elseif choice=='b'
item_row=input('Number of items in which row do you want to know? ');
if item_row<=m
sum_row=0;
for i=1:k
for j=1:n
sum_row= sum_row+ box(item_row,j,i);
end
end
fprintf('Number of items %d ',sum_row);
else
disp('Wrong Input ');
end
elseif choice=='c'
disp('Number of items in which box do you want to know?');
item_r=input('Input row number ');
item_c=input('Input column number ');
item_s=input('Input stack number ');
if item_r<=m && item_c<=n&&item_s<=k
fprintf('Number of items %d ',box(item_r,item_c,item_s));
else
disp('Wrong Input ');
end
elseif choice=='d'
item=input('Number of items ');
if item<=7&&item>=0
no_items=0;
match=box==item;
for i=1:m
for j=1:n
for s=1:k
no_items= no_items+ (match(i,j,s));
end
end
end
fprintf('Number of boxes %d ',no_items);
else
disp('Wrong Input ');
end
elseif choice=='e'
total=0;
for i=1:m
for j=1:n
for s=1:k
total= total+ (box(i,j,s));
end
end
end
fprintf('Number of items %d ',total);
else
disp('Exiting');
break;
end
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.