首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #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
119
问题
有如下程序:
#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://www.kaotiyun.com/show/vNNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
在重载一个运算符时,如果其参数表中有一个参数,则说明该运算符是
以下程序的输出结果是#include<iostream.h>voidmain(){intx=1,y=3;cout<<x++<<",";{intx
在面向对象方法中,属性与操作相似的一组对象称为【】。
下列叙述中正确的是
已知二叉树后序遍历序列是dabec,中序遍历序列是debac,它的前序遍历序列是
在公有派生情况下,有关派生类对象和基类对象的关系,下列叙述不正确的是
下列有关内联函数的叙述中,正确的是
下列对队列的叙述正确的是
下列语句中错误的是( )。
具有3个结点的二叉树有
随机试题
关于能力,下列说法正确的是()。
首次使用“政治经济学”一词的是()
下图所示对称结构只有水平梁受力。()
一青年农民,32岁,吸烟史8年,每天10支左右,否认慢性咳嗽、咳痰史。近1年来出现间断低热,伴咳嗽、憋气,无咯血及盗汗,胸片示双肺中下野弥漫性、细小、边缘模糊的结节状阴影。体检:无杵状指,呼吸频率16次/分。如果患者曾养鸽子两年,纤维支气管镜活检发现肺
存货清查中,盘盈的存货,若不是发货方多发的,应()。
伊斯兰敦最基本的经典是()。
,()
定义一个函数名为fun,返回值为int,没有参数的纯虚函数的定义是______。
—MayIopen______bag,Madam?—Ofcourse,butit’sfullof______dirtyclothes.
A、Becausewomendomuchworkthanmen.B、Becausepeoplethinkwomenweakerthanmen.C、Becausesportiseasierformenthanfor
最新回复
(
0
)