首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #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-06-27
52
问题
有如下程序:
#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/yRNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
在下面程序中,编译出现错误的语句是______。classB{public:B(){f();}virtualvoidf()=0;};
请找出下列程序中错误之处______。#include<iostream.h>classA{private:intx1;protected:intx2;
下列静态数据成员的特性中,错误的是______。
在下面程序运行后,输出结果为______。#include<iostream.h>voidcount(intx[],intn,int&y){intk;y=0;for(k=0:k<n;k++)
已知:doubleA(doubleA){return++a;}和intA(inta){return++a;)是一个函数模板的两个实例,则该函数模板定义为【】。
下面叙述错误的是()。
C++流中重载的运算符“>>”是一个()。
已知枚举类型定义语句为: enum Token{NAMB,NUMBER,PLUS=5,MINUS,PRINT=10}; 则下列叙述中错误的是
有一种只在循环语句或switch语句中使用的流程控制语句,表示该语句的关键字是【 】。
当使用ofstream流类定义一个流对象并打开一个磁盘文件时,文件的默认打开方式为( )。
随机试题
社会惰化
JK触发器的输入J和K都接高电平上,如果现态为Qn=0,则其次态为_________。
在班集体建设中,最关键的因素是()
空腹时血糖浓度为
下列哪项不是心脏呼吸骤停的临床表现
A.祛暑解表,化湿和中B.祛暑解表,清热化湿C.清暑解热,化气利湿D.清暑化湿,理气和中E.祛暑化湿,健脾和中香薷散的功用是
A.seetheworldB.alientoC.atrandomD.liveinA.residentsinthesecommunitieswerephoned【T13】______andaskedthe
《刑法》第81条第2款规定:“对累犯以及因故意杀人、强奸、抢劫、绑架、放火、爆炸、投放危险物质或者有组织的暴力性犯罪被判处十年以上有期徒刑、无期徒刑的犯罪分子,不得假释。”问题:请对该条款进行分析。
[*]
________peoplediedinthepowerfulstorm.
最新回复
(
0
)