tutorial04 - CS1010E Programming Methodology Semester 1...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS1010E Programming Methodology Semester 1 2011/2012 Week of 12 – 16 September 2011 Tutorial 4 Control Flow Statements 1. In Lecture #4, several alternative algorithms were introduced to find the maximum of three numbers. (a) The following is yet another version. if (num1 > num2) if (num1 > num3) max = num1; else max = num3; else if (num2 > num3) max = num2; else max = num3; As you can see, depending on the exact values of num1 , num2 and num3 , there are four possible logical paths through the above nested if..else construct. Very often we are required to test selection control constructs by performing complete path testing, i.e. devising sets of values of variables ( num1 , num2 and num3 ) such that all possible paths are tested to be correct ( max ). Give examples of test cases that can be used for complete path testing. Is the algorithm above general? Does it satisfy all possible integer inputs? (b) Suppose you are given the function to find the maximum of two numbers. int max2(int a, int b) { if (a > b) return a; else return b; } Write a program fragment that uses the max2 function defined above to find the maximum of three numbers num1 , num2 and num3 and assign the maximum to the variable max . 1 2. The severity of an earthquake is classified using the Richter Magnitude Scale according to the following table. Richter Scale Classification magnitude < 4 . minor 4 . ≤ magnitude < 6 . 0) moderate 6 . ≤ magnitude < 6 . 9) strong magnitude ≥ 6 . 9 major (a) Define four integer constants MINOR , MODERATE , STRONG and MAJOR with appropri- ate integer values. In the remaining questions below, you should only use theseate integer values....
View Full Document

Page1 / 5

tutorial04 - CS1010E Programming Methodology Semester 1...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online