Write an mfile script called tempRangem that will prompt the

Write an m-file script called tempRange.m that will prompt the user for a vector of a week\'s worth of high temperatures (a single prompt expecting a vector of 7 numbers). The script displays a message with the range (difference of the highest and lowest) of the high temperatures for that week. Create a test table (use at least 4 meaningful test cases and explain why each test case was chosen) and write an m-file script solve the problem. Make sure to format the output if necessary. Design will be done in lecture or lab.

Solution

% Test case selection is explained in the test case table. The matlab code is given below.

% MATLAB CODE (tempRange.m)

% User Input
vec = input(\'Enter vector of a week\'\'s worth of high temperatures: \ \');

highTemp = max(vec); % Highest temperature of the week
lowTemp = min(vec); % Lowest temperature of the week

range = highTemp - lowTemp; % Range (highest temp - lowest temp)
disp(\'\');
disp(\'Range of the highest temperature of the week: \');
fprintf(\'%.2f\ \', range); % format to print upto 2 decimal points

---------------------------------------------------

SAMPLE OUTPUT (Note: we need to have square brackets (i.e. [ ] )at the beginning and at the end of the input vector).

Enter vector of a week\'s worth of high temperatures:
[1 2.2 3.3 1.0 0 4.5 5.0]
Range of the highest temperature of the week:
5.00

---------------------------------------------------

Test case table:

Yes

Test Case Sample Data Expected Result (Manually Calculated) Verified?
1. This test case was chosen to operate on positive whole numbers. 0, 3 , 2, 4, 5, 2, 1 5-0 = 5 Yes
2. This test case was chosen to operate on positive decimal numbers. 2.2, 4.3, 1.2, 6.5, 3.3, 5.4, 9.9 9.9-1.2=8.7 Yes
3. This test case was chosen to operate on negative non-decimal numbers. -1, -2, -3, -5, -9, -2, -6 -1-(-9)=8 Yes
4. This test case was chosen to operate on both negative and positive decimal numbers. -2.3, -4.3, 5.4, 3.2, -6.0, -7.3, 2.1 5.4-(-7.3)=12.7 Yes
5. This test case was chosen to operate on both positive and negative non-decimal numbers. -1, -3, -9, 0, 4, 5, 8 8-(-9)=17

Yes

 Write an m-file script called tempRange.m that will prompt the user for a vector of a week\'s worth of high temperatures (a single prompt expecting a vector of

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site