首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include using namespace std; class Sample{ friend long fun(Sample s); public: Sample(long a){x=a;} private: long x; }; l
有如下程序: #include using namespace std; class Sample{ friend long fun(Sample s); public: Sample(long a){x=a;} private: long x; }; l
admin
2019-08-23
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<
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/SD8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
已知数组a中的元素个数为n,下列语句的作用是将下标为i的元素移动到下标为 i-1的单元,其中1≤i<n。例如,当n=4,a中原有数据为1,2,3,4时,则移动后a中元素变为2,3,4,4。请将语句补充完整:for(int i=0;i<n-1;i++)
下列程序运行时的输出结果是______。#include<iostream>usingnamespacestd;intXfun(int*a,intn);intmain()intb[6]={-2,6,
源程序文档化要求程序应加注释。注释一般分为序言性注释和【】
下列程序的输出结果是#inClUde<iostream>usingnamespacestd;intmain(){Chara[]="HellO,World";Char*ptr=a;while(
下列关于this指针的叙述中,正确的是______。
重载的流运算符函数经常定义为类的【】函数。
下列关于运算符重载的描述中,()是正确的。
关系数据库管理系统能实现的专门关系运算包括( )。
下面描述中,不属于软件危机表现的是
当使用关键字______作为函数返回类型时,该函数不返回任何值。
随机试题
IP多媒体子系统简称(),是3GPP在R5版本中提出的,支持会话类和非会话类多媒体业务,是未来多媒体应用通用的业务使用平台。
下列关于软件测试的步骤说法错误的是()
鹰嘴滑囊炎又称
A公司因无出口自营权,便委托B外贸公司代理出口其产品,B外贸公司以自己的名义与国外买方订立了出口合同,并且未向买方透露代理关系。下列表述正确的是()。
施工单位应由()主持编制投标施工方案。
行政监察机关拥有检查权,可以对公安机关及其人民警察贯彻执行法律、法规和政策的情况及职务活动中的行为实施检查。()
设可微函数f(x,y)在点(x0,y0)处取得极小值,则下列结论正确的是().
Whenisthefilmfestivalscheduledtostart?
Transistors(exhibit)ahighamplificationfactor,operatewithout(distorted)overa(widefrequency)range,andcanbemade(e
ThereisnobettertimetogetaquotefromyourlocalAAInsuranceagent.Getagreatrate—withapersonaltouch.Ifyo
最新回复
(
0
)