Uploaded by Kaushik Tallam

Project1

advertisement
Name: Kaushik Tallam
Date: 09/28/2020
NetID: kt540
RUID: 200006130
1. Put your answer in the following box:
For my indicator value, I chose the integer values of 1, 2, 3, & 4. As commented in my
code…
%
%
%
%
1
2
3
4
=
=
=
=
Area of a
Volume of
Volume of
Volume of
Rectangle
a Cylinder
a 4-sided Pyramid with equal sides
a Cone
I decided to use the integer values of 1-4 because they are the first four positive integers in
the number system so they are basic enough for a kindergarten student to understand and
they are easily associated. They are also single digit integers making them very easy to type
when calling the function.
2. Put your answer in the following box:
The conditional statements I used for my code was switch statements. As displayed in my code…
switch (indicator)
case 1
result = var1 * var2;
case 2
result = var1 * pi * (var2^2);
case 3
result = ((var1^2) * var2)/3;
case 4
result = pi * (var2^2) * (var1/3);
otherwise
result = "Enter Correct Indicator Value (1-4)!";
end
The switch statement is the most intuitive conditional statement in this scenario because there
are different operations associated with each of the four indicators. Switch statements also allow
for an error message to be displayed if none of the cases are met. Each branch of the switch
statement was tested by calling the function and inputting the same 2 variables (for example: 2
& 4) but changing the indicator value each time the function was called. If a different result was
outputted, then the indicator was working properly. The validity of the operations of each
branch was checked by doing the calculations by hand first, then calling the operation and cross
checking the output by hand and by the computer.
3. Write your answer in the following box:
Script:
[PyramidVolume1] = Project1(10,10,3);
[PyramidVolume2] = Project1(5,0,3);
[PyramidVolume3] = Project1(-19,12,3);
[PyramidVolume4] = Project1(19,-12,3);
[PyramidVolume5] = Project1(100,2022,3);
PyramidVolume1 is expected to equal 333.3333. The actual value of PyramidVolume1 is
333.3333. PyramidVolume2 is expected to equal 0. The actual value of PyramidVolume2 is 0.
PyramidVolume3 is expected to equal 1444. The actual value of PyramidVolume3 is ““Enter
Positive Values”. PyramidVolume4 is expected to equal -1444. The actual value of
PyramidVolume4 is “Enter Positive Values”. PyramidVolume5 is expected to equal 6740000.
The actual value of PyramidVolume5 is 6740000. These test cases are sufficient because at
least two correct, positive, operations were taken. Also, the function written correctly prompts
the user to enter positive values if a negative value is inputted as val1 or val2 (There cannot be
a negative volume). Also, the program correctly determines the volume to be 0 if val1 or val2 =
0.
Download