首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #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
49
问题
有如下程序:
#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全国计算机二级
相关试题推荐
以下程序段的输出结果是______。#include<iostream.h>voidmain(){intx[]二{9,7,5,3,1),y=0,j,*p=&x[2];for(j=0;i<3;j+
下面是一个栈类的模板,其中push函数将元素i压入栈顶,pop函数弹出栈顶元素。栈初始为空,top值为0,栈顶元素在stack[top-1)中,在下面横线处填上适当语句,完成栈类模板的定义。template<classT>class
有如下表达式19/30*.sqrt(4.0)/5,则该表达式值数据类型为______。
C++语言中while循环和do-while循环的主要区别是()。
关于链式存储结构和顺序存储结构的说法正确的是______。
结构程序设计的3种结构是______.
下面叙述错误的是()。
下面叙述错误的是______。
下列叙述中正确的是
在关系数据库中,用来表示实体之间联系的是【 】。
随机试题
用于基坑边坡支护的喷射混凝土的主要外加剂是()。
我国的民族自治地方可以使用民族文字做会计记录。()
按照中国证券业协会发布的有关管理办法规定,下列各项属于代办股份转让主办券商主办的有( )。
发行人计划实施超额配售选择权的,应当提请监事会批准,因行使超额配售选择权而发行的新股为本次发行的一部分。()
下列属于公司进行跨国经营的动机的有()。
政府在对公共物品制定价格进行管理时,应遵循的原则是()。
在如图所示初中物理“测量小灯泡功率”的实验电路中,闭合开关,当滑动变阻器的滑片向A端移动时()。
A、B、C、D、C
Thenatureofworkischanging.Recenttechnologicaladvances,ashiftfrommanufacturingtoservice-basedorganizations,incr
Itcanneverbeproved,butitisasafeassumptionthatthefirsttimefivethousandmalehumanbeingswereevergatheredtoge
最新回复
(
0
)