next up previous
Next: About this document ...

ESC 251 HW 10 Due: Sep. 26

Remember to indent the bodies if your IF-THEN statements.



1)
(5 pts) The program segment below should warn the user of high temeperature readings. Determine if this segement works as intended (note, don't write a program to test this, just mentally trace through the logic using a few different values for temp.) Does the program segment work as intended?

If the program segment does not work as intended, re-write the IF-THEN block so that it works properly, then write a complete script. Test your program using values for temp that will ensure that each branch of the IF-THEN block is being accounted for.

         if(temp < 97.5) 
             disp('Temperature below normal')
         elseif(temp > 97.5) 
             disp('Temperature normal')
         elseif(temp > 99.5) 
             disp('Temperature slightly high')
         elseif(temp > 103.0) 
             disp('Temperature dangerously high')
         end
2)
(4 pts) The cost to ship a package depends on the weight according to the table below.
Weight (lbs) Cost ($)
0.00 - 2.00 $10
2.01 - 5.00 $20
5.01 - 10.00 $40
10.01 - 20.00 $60
20.01 - 40.00 $80
40.01 - 75.00 $100
> 75.01 Can't be shipped

Write a MATLAB script that will ask the user to input a weight, then print out the shipping cost. Select your own test cases that will ensure each branch is working correctly.

3)
(8 pts) Write a MATLAB script that will ask the user to input values of x,y and z. These values represent the coordinates of a point P(x,y,z) in 3-dimensional space.



If the point P(x,y,z) is inside the sphere with center (2,3,-5) and radius 1.1, the program should display the message 'Inside Sphere 1'



If the point P(x,y,z) is inside the sphere with center (3,1,-4) and radius 0.5, the program should display the message 'Inside Sphere 2'



For any other case, the program should display the message 'Point not in any sphere'



Test your program using the points (3.25,1.1,-3.9), (2.1,3.1,-4.8) and (10,10,-10). You can assume that a point can only be in one of the spheres.




next up previous
Next: About this document ...
2018-09-24