COMP 5710 ASSIGNMENT 1 SOLVED

$35.00

Category: Tags: , , , , You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (5 votes)

(15 pts) 1. Draw the program graph. You must use line numbers to label all nodes in the
graph. Do not use the statements or statement fragments themselves as nodes labels.
(5 pts) 2. Compute the cyclomatic number using each of the three methods discussed in
class. Show your work.
(5 pts) 3. Calculate the P* using the given conditions under each problem. Show your work.
Hint:
1 if (C1 && C2)
2 S1;
3 else
4 S2;
For the program slice above, the program graph should be drawn as below:
Problem 1:
1 void Q1(){
2 S1;
3 if(C1){
4 S2;
5 if(C2){
6 S3;
7 }
8 else{
9 S4;
10 }
11 }
12 else if(C3&C4){
13 S5;
14 }
15 else{
16 S6;
17 }
18 S8;
19 }
Problem 2:
1 void Q2(){
2 S1;
3 if(C1) {
4 if(C2 && C3) {
5 S2;
6 If(C4){
7 S3;
8 }
9 } else {
10 S4;
11 }
12 } else {
13 do{
14 S5;
15 if(C5) {
16 S6;
17 }
18 } while(C6)
19 }
20 S7;
21 }
For P*, suppose the do loop (line 13) executed exactly 4 times.
Problem 3:
1 void Q2(){
2 S1;
3 if(C1 && C2){
4 S2;
5 }
6 else{
7 for(S3;C3;S4){
8 S5;
9 if(C4){
10 S6;
11 }
12 }
13 }
14 if(C5){
15 for(S7;C6;S8){
16 S9;
17 }
18 }
19 else{
20 S10;
21 }
22 S11;
23 }
For P*, suppose the for loop defined by Line 7 may be executed anywhere from 0 to 3 times,
the for loop defined by Line 15 is executed exactly 3 times.
Problem 4:
1 void Q4(){
2 S1;
3 while(C1){
4 if(C2 && C3){
5 S2;
6 }
7 else{
8 S3;
9 }
10 while(C4){
11 S4;
12 if(C5&C6){
13 S5;
14 }
15 while(C7){
16 S6;
17 }
18 }
19 S7;
20 }
21 S8;
22 }
For P*, suppose the while loop in line 3, 10, and 15 are executed exactly 2, 2, and 3 times.