首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include<iostream> using namespace std; class Sample{ friend long fun(Sample s); public: Sample(long a){x=a;} private: lo
有如下程序: #include<iostream> using namespace std; class Sample{ friend long fun(Sample s); public: Sample(long a){x=a;} private: lo
admin
2017-07-28
36
问题
有如下程序:
#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)return1;
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:
return0;
}
执行这个程序的输出结果是( )。
选项
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/AFAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
符号常量可以用宏定义define和______来表示。
若有下面的说明和定义:structtest{charm2;floatm3;unionuu{charu1[5];floatu2;}u
有以下程序:#include<iostream>usingnamespacestd;intmain(){intx=15;while(x>10&&x<50){
下面程序的输出结果是()。#include<iostream>usingnamespaceStd;intmain(){intx[6]={1,3,5,7,9,11},*k,**s;
for(intx=0,y=0;!x&&y<=5;y++)语句执行循环的次数是()。
函数定义的格式是【 】函数名(形式参数表)函数体。
read函数的功能是从输人流中读取( )。
下列特征中不是面向对象方法的主要特征的是()。
下列输出字符,A,的方法中,()是错误的。
下列是模板声明的开始部分,其中正确的是
随机试题
《素问.五藏生成篇》说“多食咸”可致()(2002年第10题)
Whatdoes"it"refertointhesentence"Ithinkitimportanttoachieveanagreementonthisissue"?
求下列定积分:
维持个体和社会生存与发展的必要事物在人脑中的反映,称之为【】
口腔修复工艺焊接技术中,常用的白合金焊料熔化温度A.350~450℃B.500~600℃C.650~750℃D.800~850℃E.950~1050℃
施工项目质量控制的实施程序不包括( )。
证券交收的实质是依据清算结果实现证券与价款的收付,从而结束整个交易过程。()
2016年1月1日,甲拒绝向乙支付到期租金,乙忙于事务一直未向甲主张权利。2016年6月20日,乙因出差遇险无法行使请求权的时间为20天。根据诉讼时效法律制度的规定,乙请求人民法院保护其权利的诉讼时效期间是()。
刑事裁判涉财产部分,由作出生效裁判的人民法院执行。作出生效裁判的人民法院可以委托财产所在地的同级人民法院执行。()
TheEconomistcalculatesthataroundtheworldalmost290million15-to24-year-oldsareneitherworkingnorstudying:almosta
最新回复
(
0
)