请编写一个函数inline long sum(int n),用递归函数完成运算:sum(n)=1*1+2*2+…n*n,递归表达式为 sum(n)=sum(n-1)+n2。
注意:部分源程序已存在文件test10_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数sum的花括号中填写若干语句。
文件test10_2.cpp的内容如下:
include<iostream.h>
inline long sum(int n)
{
}
void main()
{
int n;
cout<<"输入n:";
cin>>n;
cout<<"结果为:"<<sum(n)<<endl;
}
第1题
根据变量定义“static int x[5],y[2][3]={9,6,3,1,4,7};”,x[4]=【 】,y[1][2]=【 】。
第2题
类clasg one在声明func成员函数时发生错误,出错原因是______。
class one
private:
int a;
public:
void func(two&);
};
class two
{
private:
int b;
friend vold one::func(two&);
};
void one::func(two&r)
{
a=r.b;
}
第4题
下列程序的运行结果是【 】。
include <iostream. h>
class test
{
private:
int num;
public:
test()
int TEST() {return num+100;}
~test()
};
test::test(){num=0;}
test::~test(){cout<<"Destructor is active"<<endl;}
void main()
{
test x[3]
cout<<x[1]. TEST()<<endl;
}
第5题
下列程序的执行结果是【 】。
include <iostream. h>
int a;
int sum_a(void)
{
a=a+5;
return a;
}
void main(void)
{
a = a+sum_a();
cout<<a<<endl;
}
第6题
下面的类中定义了一个枚举类型,请完成下面的程序。
class Base {
public:
enum Week {Sum, Mon,Tue, Wed, Thu, Fri, Sat};
Week a;
}
void fun(Base &B) {
【 】 = 【 】; //将对象的a赋值为所定义的枚举类型值为的枚举量
}
第8题
数值返回。例如:n为1000时,函数值应为s=153.909064。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <conio.h>
include <math.h>
include <stdio.h>
double fun(int n)
{
}
main()
{
clrscr();
printf("s=%f\n", fun(1000));
}
第10题
在C++中,下列程序段的输出结果是【 】。
int x, a[10];
cout<<sizeof(x)<<“”<<sizeof(a)<<“”<<sizeof(float)<<end1
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!