首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include using namespace std; class Sample { friend long fun(Sample s); public: Sample(long a) { x = a; } private: long
有如下程序: #include using namespace std; class Sample { friend long fun(Sample s); public: Sample(long a) { x = a; } private: long
admin
2015-07-22
30
问题
有如下程序:
#include
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 sum = 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
解析
本题考查默认构造函数,当i=0、1时,fun(Sample(i))为1;当i=2时,fun(Sample(i))为2;当i=3时,fun(Sample(i))为6;当i=4时,fun(Sample(i))为24;当i=5时,fun(Sample(i))为120。所以总和为154。
转载请注明原文地址:https://kaotiyun.com/show/AwNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序:#include<iostream>usingnamespacestd;classPet{charname[10];public:Pet(char*name){st
补充完整下面的类定义:constdoublePI=3.14;classCircle{//圆形物体的抽象基类protected:doubler;//半径public:Circle(doubleradius=0):r(radius
下列叙述中正确的是
在类中定义和实现的函数称为()。
有以下类定义:classPoint{public:Point(intx=0,inty=0){_x=x;_y=y;}voidMove(intxOff,intyOff){_x+=xOff
在公有派生的情况下,派生类中定义的成员函数只能访问原基类的______。
数据流图的类型有【】和事务型。
设树T的度为4,其中度为1,2,3,4的结点个数分别为4,2,1,1。则T中的叶子结点数为
若按层次顺序将一棵有n个节点的完全二叉树的所有节点从1到n编号,那么当i为偶数且小于n时,节点i的右兄弟是节点【】,否则节点i没有右兄弟。
数据结构中,与所使用的计算机无关的是数据的
随机试题
毛泽东在探索中国社会主义建设道路过程中提出,社会主义的发展阶段可能分为()
建筑石膏的特性包括()。
监理单位对其验收合格项目的施工质量负()。
金砖四国
目前主要的运营网络有电信网、______和计算机网。
Ifyouintendusinghumorinyourtalktomakepeoplesmile,youmustknowhowtoidentifysharedexperiencesandproblems.Your
In1919Britainexperienceditslargesteverreductioninindustrialworkinghours,to48perweek.InDowie’sviewthe48-hour
1 Peoplehavebeenpaintingpicturesforatleast30,000years.Theearliestpictureswerepaintedbypeoplewhohuntedanimals
It’snouse_______menottoworry.
Underproperconditions,soundwaveswillbereflectedfromahillsideorothersuchobstruction.Soundtravelsattherateofa
最新回复
(
0
)