多选题Given: Which five methods, inserted independently at line 5, will compile?()Aprotected int blipvert(long x) { return 0; }Bprotected long blipvert(int x) { return 0; }Cprivate int blipvert(long x) { return 0; }Dprivate int blipvert(int x) { return 0; }E

题目
多选题
Given: Which five methods, inserted independently at line 5, will compile?()
A

protected int blipvert(long x) { return 0; }

B

protected long blipvert(int x) { return 0; }

C

private int blipvert(long x) { return 0; }

D

private int blipvert(int x) { return 0; }

E

public int blipvert(int x) { return 0; }

F

protected long blipvert(long x) { return 0; }

G

protected long blipvert(int x, int y) { return 0; }

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

有以下程序:includeint f(int x){int y;if(x==0||x==1)return(3);y=x*x-f(x-2);return

有以下程序: #include<stdio.h> int f(int x) {int y; if(x==0||x==1)return(3); y=x*x-f(x-2); return y; } main() {int z; z=f(3);printf("%d\n",z); } 程序的运行结果是( )。

A.0

B.9

C.6

D.8


正确答案:C
解析:本题主要考查函数的递归调用。当x=0或者x=1时返回值为3,即f(0)=3,f(1)=3;否则返回值为x*x-f(x-2)。f(3)=3*3-f(1)=9-3=6。

第2题:

有如下程序: include using namespace std; class Sample { frien

有如下程序: #include <iostream> using namespace std; class Sample { friend long fun(Sample s); public: Sample(long a) {x=a;} private: long x; }; long fun(Sample s) { if(s.x < 2) return 1; return s.x * fun(Sample(s.x-1)); } int main() { int stun = 0; for (int i=0; i<6; i++) {sum += fun(Sample(i));} cout << sum; return 0; }运行时输出的结果是

A.120

B.16

C.154

D.34


正确答案:C
解析:本题考查的知识点是:友元函数、递归函数。友元函数不是当前类的成员函数,而是独立于当前类的外部函数,但它可以访问该类的所有对象的成员,包括私有成员、保护成员和公有成员。本题中的fun函数就被声明为Sample类的友元函数了。因此,在fun函数中可以直接访问Sample类对象的私有成员x。主函数中通过一个for循环依次以临时构造的Sample类对象为参数,调用fun函数,构造参数依次为0~5。如果一个函数在其函数体内直接或间接地调用了自己,该函数就称为递归函数。本题中的fun()函数直接调用了自身,所以它又是递归函数,不难分析其递归性质如下:

因为Sample类的构造函数只是简单的将构造参数a赋给成员x,故可省略不看。通过上述递归定义不难看出,n取0~5时,fun(n)的值依次为:1,1,2,6,24,120。累加之后结果为154,故本题应该选择C。

第3题:

以下程序的输出结果是 【 17 】 。

int fun(int *x,int n)

{ if(n==0) return x[0];

else return x[0]+fun(x+1,n-1);

}

main( )

{ int a[]={1,2,3,4,5,6,7}; printf("%d\n",fun(a,3));}


正确答案:

第4题:

下列程序的输出结果是()。 include int fun(int x) {int a;if(x==0‖x==1) return 3;els

下列程序的输出结果是( )。 #include<stdio.h> int fun(int x) { int a; if(x==0‖x==1) return 3; else a=x-fun(x-2); return a; } void main() { printf("%d",fun(7)); }

A.2

B.8

C.9

D.5


正确答案:A
解析:本题考查函数的递归调用。在函数递归调用时,fun(7):a=7-fon(5)→fun(5):a=5-fon(3)→fun3:a=3-fun(1)→fun(1):a=3,反推回去 fun(3):a=3-3=0→fun(5):a=5-0=5→fun(7):a=7-5-2,最后的计算结果为2。

第5题:

Given:Which code, inserted at line 15, allows the class Sprite to compile?()

A.Foo { public int bar() { return 1; }

B.new Foo { public int bar() { return 1; }

C.new Foo() { public int bar() { return 1; }

D.new class Foo { public int bar() { return 1; }


参考答案:C

第6题:

如下程序的输出结果是______。 include using namespace std; int funl(int x){retu

如下程序的输出结果是______。

include<iostream>

using namespace std;

int funl(int x){return++x;}

int fun2(int&x){return++x;}

int main( ){

int x:1,y=2;

Y=funl(fun2(x));

cout<<x<<','<<y;

return 0;

}


正确答案:23
2,3

第7题:

下面函数的作用是【 】。

int index(int x,int a[],int n)

{

for(int i=0;i<n;i++)

{

if(a[i]==x)

return i;

}

return i;

}


正确答案:数组a中查找x若有则返回第一个x的下标若没有则返回n
数组a中查找x,若有则返回第一个x的下标,若没有则返回n 解析:函数的作用是通过变量数组,在数组中查找x,若找到则显示下标i。

第8题:

以下程序的输出结果是______

nt fun(int*x,int n)

{if(n==0)

return x[0];

else return x[0]+fun(x+1,n-1);

}

main()

{int a[]={1,2,3,4,5,6,7};

printf(“%d\n”,fun(a,3));

}


正确答案:

10

第9题:

下列程序的输出结果是()。 include int fun(int x) {int a; if(x==0‖x==1) return 3;

下列程序的输出结果是( )。

#include<stdio.h>

int fun(int x)

{ int a;

if(x==0‖x==1)

return 3;

else

a=x-fun(x-2) ;

return a;

}

void main()

{ printf("%d",fun(7) );

}

A.2

B.8

C.9

D.5


正确答案:A
解析:本题考查函数的递归调用。在函数递归调用时,fun(7):a=7-fun(5)→fun(5):a=5-fun(3)→ fun3:a=3-fun(1)→fun(1):a=3,反推回去fun(3):a=3-3=0→ fun(5):a=5-0=5→fun(7):a=7-5=2,最后的计算结果为2。

第10题:

下列程序的运行结果是______。includelong func(int x){ long p;if(x==O‖x==1)return(1)

下列程序的运行结果是______。

include<stdio.h>

long func(int x)

{ long p;

if(x==O‖x==1)

return(1);

p=x*func(x-1);

return(p);

}

main()

{ printf("%d\n",func(4));

}


正确答案:

本题考查函数的循环调用。p=x*func(x-1),当x=4时,不满足if语句的条件,p=4*func(3), x=3也不满足条件,则func(3)=3*func(2),func(2)=2*func(1),x=1满足条件return(1),则输出结果为 4*3*2*1=24。

更多相关问题