Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Integer Division Algorithm and Code Complexity, Exercises of Computer Engineering and Programming

Two problems related to integer division using repeated subtraction and code complexity. Problem 1 asks to define a robust algorithm for integer division and implement it in ada95 with exception handling. Problem 2 focuses on calculating the cyclomatic complexity of a code fragment and determining the minimum number of test cases needed. Hints are provided for each problem.

Typology: Exercises

2011/2012

Uploaded on 07/20/2012

savitri_85
savitri_85 🇮🇳

4

(5)

74 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
C13-14
The problems in this problem set cover lectures C13 and C14
1.
a. Define a robust algorithm to carry out integer division using repeated subtraction.
Your algorithm accepts two integers and returns the quotient and the remainder.
Hint: What are the preconditions and postconditions of your algorithm?
b. Implement your algorithm as an Ada95 program, using exception handling to
provide robustness.
Turn in a hard copy of your algorithm and code listing, and an electronic copy of your
code.
2.
a. What is the cyclomatic complexity of the code fragment shown below?
loop
exit when Flag := True;
if A < 100 and B > 200 then
if A > 50 then
Sum := Sum +2;
else
Sum := Sum +1;
end if;
else
if B < 300 then
Sum:= Sum -1;
else
Sum := Sum -2;
end if;
end if;
end loop;
Hint: Draw the control flow graph
b. What is the minimum number of test cases needed to test the fragment of code
shown below? Justify your answer.
if A < 100 and B > 200 then
if A > 50 then
Sum := Sum +2;
else
Sum := Sum +1;
end if;
else
if B < 300 then
Sum:= Sum -1;
else
Sum := Sum -2;
end if;
docsity.com
pf2

Partial preview of the text

Download Integer Division Algorithm and Code Complexity and more Exercises Computer Engineering and Programming in PDF only on Docsity!

C13-

The problems in this problem set cover lectures C13 and C

a. Define a robust algorithm to carry out integer division using repeated subtraction.

Your algorithm accepts two integers and returns the quotient and the remainder.

Hint : What are the preconditions and postconditions of your algorithm?

b. Implement your algorithm as an Ada95 program, using exception handling to

provide robustness.

Turn in a hard copy of your algorithm and code listing, and an electronic copy of your

code.

a. What is the cyclomatic complexity of the code fragment shown below?

loop exit when Flag := True; if A < 100 and B > 200 then if A > 50 then Sum := Sum +2; else Sum := Sum +1; end if; else if B < 300 then Sum:= Sum -1; else Sum := Sum -2; end if; end if; end loop;

Hint : Draw the control flow graph

b. What is the minimum number of test cases needed to test the fragment of code

shown below? Justify your answer.

if A < 100 and B > 200 then if A > 50 then Sum := Sum +2; else Sum := Sum +1; end if; else if B < 300 then Sum:= Sum -1; else Sum := Sum -2; end if;

docsity.com

end if;

docsity.com