试题24
有以下程序
#include <stdio.h>
double f(double x);
main()
{ double a=0; int i;
for(i=0;i<30;i+=10) a+=f((double)i);
printf(“%5.0f\n”, a);
}
double f(double x)
{ return x*x+1;}
程序运行后的输出结果是()
A.503
B.401
C.500
D.1404
第1题:
请补充函数fun(),该函数的功能是:计算N×N维矩阵元素的方差,结果由函数返回。维数N在主函数中输入。例如:

注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio.h>
include <conio.h>
include <stdlib.h>
include <math.h>
define N 20
double fun(【 】,int n)
{
int i,j;
int k;
double s=0.0;
double f=0.0;
double aver=0.0;
double sd=0.0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
s+=a[i][j];
aver=【 】;
for(i=0;i<n;i++)
for(j=0;i<n;j++)
f+=(a[i][j]-aver)*(a[i][j]-aver);
f/(n*n);
sd=【 】;
return sd;
}
main()
{
int a[N][N];
int n;
int i,j;
double s;
clrscr();
printf("***+Input the dimension of
array N*****\n");
scanf("%d",&n);
printf("***** The array *****\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=rand()%50;
while(a[i][j]=0)
a[i][j]=rand()%60;
printf("%4d",a[i][j]);
}
printf("\n\n");
}
s=fun(a,n);
printf("******* THE RESULT *******\n");
printf("%4.3f\n",s);
}
第2题:
有以下程序 #include <iostream> using namespace std; class Complex { public: Complex (double r=0, double i =0 :re(r) ,im (i) {} double real() const {return re;} double imag() const { return im;} Complex operator + (Complex c} const {return Complex(re+c.re, im+c.im);} privane: double re,im; }; int main { Complex a =Complex (1,1)+Complex(5); cout<<a.real()<<'+'<<a.imag() << 'i' <<endl return 0; } 程序执行后的输出结果是
A.6+6i
B.6+1i
C.1+6i
D.1+1i
第3题:
下列给定程序中,函数fun()的功能是:根据整型参数m,计算如下公式的值。
y=1/(100×100)+1/(200×200)+1/(300×300)+…+1/(m×m)
例如,若m=2000,则应输出0.000160。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio.h>
include <stdio. h>
/*************found**************/
fun (int m)
{ double y=0, d;
int i;
/*************found**************/
for (i=100, i<=m, i+=100)
{d= (double) i* (double) i;
y+=l. 0/d;
}
return (y);
}
main ( )
{ int n=2000;
clrscr();
printf("\nThe result is %lf\n",fun(n));
第4题:
有下列程序: int funl(double a){return a*=a;} int fun2(double x,double y) {double a=0,b=0; a=funl(x);b=funl(y);return(int)(a+b); } main( ) {double w;w=fun2(1.1,2.0),……} 程序执行后变量w中的值是( )。 、
A.5.21
B.5
C.5.0
D.0.0
第5题:
下列程序的执行结果为【 】。
include <iostream. h>
class Point
{
public:
Point(double i, double j) { x=i; y=j;}
double Area() const { return 0.0;}
private:
double x, y;
};
class Rectangle: public Point
{
public:
Rectangle(double i, double j, double k, double 1)
double Area() const {return w * h;}
private:
double w, h;
};
Rectangle: :Rectangle(double i, double j, double k. double 1): Point(i,j).
{
w=k, h=1
}
void fun(Point &s)
{
cout<<s. Area()<<end1;
}
void main( )
{
Rectangle rec(3.0, 5.2, 15.0. 25.0);
fun(rec)
}
第6题:
以下函数的功能是:求x的y次方,请填空。double fun(double x,int y){ int i; double z; for(i=1,z=x;i<y;i++) z=z*; return z;}
第7题:
有以下程序: #include <iostream> using namespace std; class Complex { public: Complex(double r=0,double i=0):re(r),im(i){ double zeal() const {return re;} double imag() const {return im;} Complex operator+(Complex c) const { return Complex(re+c.re,im+c.im);} private: double re,im; }; int main() Complex a=Complex(1,1)+Complex(5); cout<<a.real()<<'+'<<a.imag()<<'i'<<end 1; return 0; }程序执行后的输出结果是______。
A.6+6i
B.6+1i
C.1+6i
D.1+1i
第8题:
下列给定程序中,函数fun()的功能是:计算
S=f(-n)+f(-n+1)+…+f(0)+f(1)+f(2)+…f(n)的值。
例如,当n为5时,函数值应为10.407143。f(x)函数定义如下:

请改正程序中的错误,使它能得山正确的结果。
注意:不要改动main 函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio. h>
include <stdio. h>
include <math. h>
/**************found***************/
f (double x)
{
if (x==0.0 || x==2.0)
return 0.0;
else if (x<0.0)
return (x-1) / (x-2);
else
return (x+1) / (x-2);
}
double fun(int n)
{
int i; double s=0.0,y;
for (i=-n; i<=n; i++)
{ y=f(1.0*i); s+=y;}
/**************found**************/
return s
}
main()
{ clrscr();
printf ("%f\n", fun (5));
}
第9题:
有以下程序: #include <iostream> #include <math> using namespace std; class point { private: double x; double y; public: point(double a,double b) { x=a; y=b; } friend double distance(point a,point b) ; }; double distance(point a,point b) { return sqrt ((a.x-b.x)* (a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } int main ( ) { point pl(1,2); point p2 (5, 2); cout<<distance (pl,p2) <<end1; return 0; } 程序运行后的输出结果是( )。
A.1
B.5
C.4
D.6
第10题:
有以下程序; int f1(double A) { return a*a; } int f2(double x,double y) { double a, b; a=n(x); b=f1(y); return a+b; } main() { double w; w=f2(1.1,2.0); ┇ } 变量w中的值是( )
A.5.21
B.5
C.5
D.0
第11题:
如果已经定义了方法int f(bool b, int i),则以下方法中,哪一个不是合法的重载方法()。
第12题:
3.000000
3.141500
0.141500
0.000000
第13题:
请补充函数fun,其功能是:计算并输出给定10个数的方差:

例如,给定的10个数为15.0,19.0,16.0,15.0,18.0,12.0, 15.0,11.0,10.0,16.0,输出为s=2.758623。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<math. h>
double fun (double x[10])
{
int i;
double avg=0.0;
double sum=0.0;
double abs=0.0;
double sd;
for (i=0; i<10; i++)
【 】;
avg=sum/10;
for(i=0;i<10;i++)
【 】;
sd=【 】;
return sd;
}
main()
{
double s,x[10]={15.0,19.0,16.0,15.0,
18.0,12.0,15.0,11.0,10.0,16.0};
int i;
printf("\nThe original data is :\n");
for(i=0;i<10;i++)
printf("%6.1f",x[i]);
printf("\n\n");
s=fun(x);
printf("s=%f\n\n",s);
}
第14题:
有以下程序#include <iostream>using namespace std;class Complex{public: Complex(double r=0,double i=0):re(r),im(i){ double real() const {return re;} double imag() const { return im; } Complex operator+(Complex c) const {return Complex(re+c.re,im+c.im);}private: double re,im;};int main(){ Complex a =Complex(1,1)+ Complex(5); cout<<a.real()<<'+'<<a.imag()<<'i'<<end1; retura 0;}
A.6+6i
B.6+1i
C.1+6i
D.1+1i
第15题:
分析以下程序执行结果【 】。
include<iostream.h>
int f (int x, int y){
return x,y;
}
double f (double x, double y) {
return x,y;
}
void main() {
int a=4, b=6;
double c=2.6, d=7.4;
cout<<f (a, b) <<","<<f (c, d) <<end1;
}
第16题:
有以下程序,输出结果( )。 #include<iostream> using namespace std; class Complex { public: Complex(double r=0,double i=0):re(r),im(i){} double real()const{return re;} double imagoconst{return im;} Complex operator+(Complex C) const {return Complex(re+c.re,im+c.im);} private: double re,im; }; int main() { Complex a=Complex(1,1)+Complex(5); cout<<a.real()<<'+'<<a.imag()<<'i'<<end1; return 0; }
A.6+i
B.2i+5
C.6+1i
D.1i+5
第17题:
有以下程序:int fun1 (double a){ return a * =a;}int fun2 ( double x, double y ){ double a=0,b=0; a = fun1 (x) ;b = fun1 (y); return(int) (a + b);} main() { doublew;w=fun2(1.1,2.0);……} 程序执行后变量w中的值是( )。
A.5.21
B.5
C.5
D.0
第18题:
写出下列程序的运行结果【 】。
include<iostream. h>
void func(double x, int &part1, double &part2){
part1=int(x)+500:
part2=(x+500-part1)*100;
}
void main( ){
int n;
double x, f;
x=1001. 0103;
func (x, n, f):
cout<<"Part 1="<<n<<" , part2="<<f<<end1
}
第19题:
以下程序的输出结果是【 】。
include<iostream.h>
int add(int x,int y)
{
retum X+y;
}
dOuble add(dOUble x,double y)
{
return x+y;
}
void main()
{
int a=4,b=6;
double c=2.6,d=7.4;
cout<<add(a,b)<<",”<<add(C,d)<<endl;
}
第20题:
有以下程序: #include<stdio.h> double f(double x); main( ) {double a=0; int i; for(i=0;i<30;i+=10)a+=f((double)i); printf("%5.of\n",a); } double f(double x) { return x*x+1; } 程序运行后的输出结果是( )。
A.503
B.401
C.500
D.1404
第21题:
有以下程序 int fun1 (double a){return a*=a;} int fun2 (double x,double y) { double a=0,b=0; a=fun1(x);b=fun1(y); return(int)(a+b); } main() {double w;w=fun2(1.1,2.0);......} 程序执行后变量W中的值是______。
A.5.21
B.5
C.5
D.0
第22题:
有以下程序
#include<stdio.h>
double f(double x);
main()
{ double a=0;int i;
for(i=0;i<30;i+=10) a+=f((double)i);
printf("%5.0f\n",a);
}
double f(double x)
{return x*x*i;}
程序运行后的输出结果是
A.503
B.401
C.500
D.1404
第23题:
5
5.00
5.21
0.0