Question

In: Computer Science

Program P1 1) integer A, B; 2) input (A); 3) while (A > 0) 4) {...

Program P1

1) integer A, B;

2) input (A);

3) while (A > 0)

4) {

5) B = 1;

6) if (A < 10)

7) B = 0;

8) if (A < 20 or A > 25)

9) B = A * B;

10) else

11) B = A + B;

12) output (A, B);

13) input (A);

14) }

15) output (“Program ends.”);

16) end;

T = {t1=<1>, t2=<33>, t3=<‐1>} or T = {t1=, t2=, t3=}

1. What is the statement domain for P1? Express as line numbers. Exclude syntactical markers, such as {, }, else, and end.

2. What is the statement coverage of T for P1? Express as an unsimplified fraction.

Solutions

Expert Solution

Answer 1

Statement domain contains all the line sequences which will be executed based on input value of A.

In given program if A <= 0 then program will not enter into while loop and exit simply so statement domain for A<=0 will be (1,2,3)

In given program if A < 10 and A > 0 then program will enter into while loop and both If conditions will be true. statement domain will be (1,2,3,5,6,7,8,9,12,13)

In given program if A >10 and A<20 then program will enter into while loop and second If conditions will be true. statement domain will be (1,2,3,5,6,8,9,12,13)

In given program if A >=20 or A<=25 then program will enter into while loop and both If conditions will be false. statement domain will be (1,2,3,5,6,8,11,12,13)

Similarly statement domain for P1 will be

{ (1,2,3), (1,2,3,5,6,7,8,9,12,13), (1,2,3,5,6,8,9,12,13), (1,2,3,5,6,8,11,12,13) }

Answer 2

t1 = 1

Statement domain for t1=1 will be (1,2,3,5,6,7,8,9,12,13)

So, coverage will be = number of lines covered / total lines = 10/11 = 91%

t2 = 33

Statement domain for t2=33 will be (1,2,3,5,6,8,9,12,13)

So, coverage will be = number of lines covered / total lines = 9/11 = 81%

t3 = -1

Statement domain for t3=-1 will be (1,2,3)

So, coverage will be = number of lines covered / total lines = 3/11 = 27%


Related Solutions

Mystery(y, z: positive integer) 1 x=0 2 while z > 0 3       if z mod 2...
Mystery(y, z: positive integer) 1 x=0 2 while z > 0 3       if z mod 2 ==1 then 4                x = x + y 5       y = 2y 6       z = floor(z/2)           //floor is the rounding down operation 7 return x Simulate this algorithm for y=4 and z=7 and answer the following questions: (3 points) At the end of the first execution of the while loop, x=_____, y=______ and z=_______. (3 points) At the end of the second execution of...
Consider the following program specification: Input: An integer n > 0 and an array A[0..(n –...
Consider the following program specification: Input: An integer n > 0 and an array A[0..(n – 1)] of n integers. Output: The largest index b such that A[b] is the largest value in A[0..(n – 1)]. For example, if n = 10 and A = [ 4, 8, 1, 3, 8, 5, 4, 7, 1, 2 ] (so A[0] = 4, A[1] = 8, etc.), then the program would return 4, since the largest value in A is 8 and...
module traffic(clk, reset, P1, P2, P3, P4, PL); input clk; input reset; output[4:0] P1; output[4:0] P2;...
module traffic(clk, reset, P1, P2, P3, P4, PL); input clk; input reset; output[4:0] P1; output[4:0] P2; output[4:0] P3; // four roads output [4:0] P4; output[3:0] PL; //Pl is pedestrian reg [4:0] P1; reg [4:0] P2; reg [4:0] P3; reg [4:0] P4; reg [3:0] PL; reg [4:0] sig; always @(posedge clk or negedge reset) begin    if(reset == 1'b0)begin        P1 <= 5'b00100;        P2 <= 5'b00100;        P3 <= 5'b00100;        P4 <= 5'b00100;       ...
Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is:
USE Coral Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is:As long as x is greater than 0    Output x % 2 (remainder is either 0 or 1)    x = x / 2Note: The above algorithm outputs the 0's and 1's in reverse order.Ex: If the input is 6, the output is:011(6 in binary is 110; the algorithm outputs the bits in reverse).
Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is:
In Java  Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is:As long as x is greater than 0    Output x % 2 (remainder is either 0 or 1)    x = x / 2Note: The above algorithm outputs the 0's and 1's in reverse order.Ex: If the input is:6the output is:0116 in binary is 110; the algorithm outputs the bits in reverse.
A= 1 2 4 0 1 -2 -1 0 1 2 0 3 8 1 4...
A= 1 2 4 0 1 -2 -1 0 1 2 0 3 8 1 4 . Let W denote the row space for A. (a) Find an orthonormal basis for W and for W⊥. (b) Compute projW⊥(1 1 1 1 1 ).
1.Prompts the user for a positive integer >= 0 2.Validates the user input to ensure it...
1.Prompts the user for a positive integer >= 0 2.Validates the user input to ensure it is a positive integer >= 0 3.Allocate (dynamically) an array big enough for the data. 4.Load the array with random numbers ranging in value from1 to 100 5.Display the elements of the array (unsorted) 6.Display the elements of the array (sorted) 7. Display the average 8.Display the median 9.Display the mode, if none, display appropriate message #include <iostream> #include <stdlib.h> /* srand, rand */...
[C] Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is:
6.19 LAB: Convert to binary - functionsWrite a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is:As long as x is greater than 0    Output x % 2 (remainder is either 0 or 1)    x = x / 2Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string.Ex: If the input is:6the output is:110Your program must define and call the following two functions. The IntegerToReverseBinary function...
(Python) Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is:
In Python8.21 Program: Convert to binary. Sections 2.7, 3.8, 5.2. Functions.Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is:As long as x is greater than 0    Output x % 2 (remainder is either 0 or 1)    x = x // 2Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string.Your program must define and call the following two functions. The function integer_to_reverse_binary() should return...
exampleInput.txt 1 2 3 0 2 3 4 0 1 3 5 0 1 2 6...
exampleInput.txt 1 2 3 0 2 3 4 0 1 3 5 0 1 2 6 1 5 6 8 2 4 6 7 3 4 5 9 10 5 8 9 4 7 9 6 7 8 6 How can I detect when 'cin' starts reading from a new line. The amount of numbers in each row is unknown. I need them in type 'int' to use the data.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT