CS FundamentalsVery hardProduct-company placement · GATE CS
Counting one decision for each loop, if, else-if, && or || operator, case label (not default) and catch clause, what is the cyclomatic complexity of this fragment?
Counting one decision for each loop, if, else-if, && or || operator, case label (not default) and catch clause, what is the cyclomatic complexity of this fragment?
for (i = 0; i < n; i++) {
if (a[i] > 0 && b[i] > 0) p++;
else if (a[i] < 0) q++;
}
switch (k) {
case 1: case 2: x = 1; break;
case 3: x = 2; break;
default: x = 0;
}
try { r = risky(); }
catch (IOException e) { r = -1; }
catch (ParseException e) { r = -2; }- A. 11
- B. 7
- C. 10
- D. 4
Correct answer: C. 10
Decisions: for 1, if 1, && 1, else-if 1, case labels 1, 2 and 3 (3), two catches 2: total 9, so V(G) = 10. Counting default gives 11, ignoring the && and the catches gives 7, and 4 counts each statement (for, if, switch, try) once.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- For the decision (A or B) and C, which test set (written as A, B, C) achieves MC/DC with only four tests?
- A leap-year function follows the Gregorian rule (divisible by 4, except centuries, unless divisible by 400). Which test set has one year…
- On main, git revert HEAD~3..HEAD is run with no conflicts. What happens?
- main receives feature work only through merge commits (git merge --no-ff), plus a few direct hotfix commits. What does git log…
- What does this code print (lines joined by ' / ')? python handlers = {'+': lambda a, b: a + b} def fallback(): print('fallback') return…
- A Python app keeps a shared Settings object at module level in settings.py as a singleton. Most code imports it as app.settings, but one…