niusouti.com

根据源代码请回答以下问题。 void sort( int Num, int Type ){ int x = 0; int y = 0; while (Num > 0) { if( Type = = 0) x = y + 2; else { if( Type = = 1 ) x = y + 5; else x = y + 10; } Num--; } } (1) 请画出控制流图并计算控制流图复杂度V(G) 。 (2) 找出独立路径。 (3) 请使用基本路径测试法设计测试用例。 (4) 根据控制流图,找出变量

题目

根据源代码请回答以下问题。 void sort( int Num, int Type ){ int x = 0; int y = 0; while (Num > 0) { if( Type = = 0) x = y + 2; else { if( Type = = 1 ) x = y + 5; else x = y + 10; } Num--; } } (1) 请画出控制流图并计算控制流图复杂度V(G) 。 (2) 找出独立路径。 (3) 请使用基本路径测试法设计测试用例。 (4) 根据控制流图,找出变量x和y的DU path


相似考题
参考答案和解析
正确答案:
V(G)=4(2)找出独立路径。1-71-2-3-71-2-4-5-71-2-4-6-7(3)请使用基本路径测试法设计测试用例。Num=1Num=1,type=0Num=1,type=1Num=1,type=2(4)根据控制流图,找出变量x和y的DUpathX无DUpathY的DUpath1-2-3-71-2-4-5-71-2-4-6-7
更多“根据源代码请回答以下问题。 void sort( int Num, int Type ){ int x = 0; int y = 0; w ”相关问题
  • 第1题:

    以下程序执行后的输出结果是includeusing namcspace std;void try(int,int,int,int);

    以下程序执行后的输出结果是 #include<iostream> using namcspace std; void try(int,int,int,int); int main() { int x,y,z,r; x=1; y=2; try(x,y,z,r); cout<<r<<end1; return 0; } void try(int x,int y, int z,int r) { z = x+y; x = x*x; y = y*y; r = z+x+y; }

    A.18

    B.9

    C.10

    D.不确定


    正确答案:D
    解析:本题考核函数调用(参数的传递)。本题常见的错误解答是:把x=1,y=2代入到函数try中,逐步计算出r=8。最后得到r的输出值是8。以下是正确解答,根据程序逐步分析:程序中定义了一个名为try的void型函数,即函数try没有任何返回值。而try函数在main函数中是以一条独立语句的方式被调用的,且main函数最后输出变量r的值。但在main函数中,并没有对变量r赋值。在C++语言中,数据只能从实参单向传递给形参,称为按值传递。也就是说,当简单变量作为实参时,用户不能在函数中改变对应实参的值。所以虽然在函数try中,r的值为8,但它并不能传递给实参,当然最终的输出肯定是不确定的随机数了。

  • 第2题:

    以下程序执行后的输出结果是include.using namespace std;void try(int,int,int,int)

    以下程序执行后的输出结果是 #include<iostream>. using namespace std; void try(int,int,int,int); int main() { int x,y,z,r; x=1; y=2; try(x,y,z,r); cout<<r<<end1; return 0; } void try(int x,int y, int z,int r) { z = x+y; x = x*x; y = y*y; r = z+x+y; }

    A.18

    B.9

    C.10

    D.不确定


    正确答案:D
    解析:本题考核函数调用(参数的传递)。本题常见的错误解答是:把x=1,y=2代入到函数try中,逐步计算出r=8。最后得到r的输出值是8。以下是正确解答,根据程序逐步分析:程序中定义了一个名为try的void型函数,即函数try没有任何返回值。而try函数在main函数中是以一条独立语句的方式被调用的,且main函数最后输出变量r的值。但在main函数中,并没有对变量r赋值。在C++语言中,数据只能从实参单向传递给形参,称为按值传递。也就是说,当简单变量作为实参时,用户不能在函数中改变对应实参的值。所以虽然在函数try中,r的值为8,但它并不能传递给实参,当然最终的输出肯定是不确定的随机数了。

  • 第3题:

    10、求y=cos(x)从0到π的积分,正确的命令为_________。

    A.int(y,x,0,pi)

    B.int(x,0,pi)

    C.int(x,y,0,pi)

    D.int(0,pi,x,y)


    int(f(x),x,a,b)

  • 第4题:

    以下程序执行后的输出结果是()。includeusing namespace std;void try(int,int,int,in

    以下程序执行后的输出结果是( )。 #include<iostream> using namespace std; void try(int,int,int,int); int main() { int x,y,z,r; x=1; y=2; try(x,y,z,r); cout<<r<<endl; return 0; } void try(int x,int y, int z,int r) { z = x+y; X = x*x; y = y*y; r = z+x+y; }

    A.18

    B.9

    C.10

    D.不确定


    正确答案:D

  • 第5题:

    求y=cos(x)从0到π的积分,正确的命令为_________。

    A.int(y,x,0,pi)

    B.int(x,0,pi)

    C.int(x,y,0,pi)

    D.int(0,pi,x,y)


    df

  • 第6题:

    5、对于多个输入参数的函数也可以使用递归。下面哪个递归定义是正确的自然数加法?也就是说,对于自然数x,y,plus x y给出x+y。

    A.plus :: Int -> Int -> Int plus 0 y = y plus x y = 1 + plus (x-1) y

    B.plus :: Int -> Int -> Int plus x 0 = x plus x y = 1 + plus x (y-1)

    C.plus :: Int -> Int -> Int plus x y = 1 + plus (x-1) y plus 0 y = y

    D.plus :: Int -> Int -> Int plus 0 y = y plus x y = 1 + plus (x-1) (y-1)


    正确