以下程序段的执行结果是(). double x;x=218.82

题目

以下程序段的执行结果是(). double x;x=218.82631; printf("%-6.2f/n",x);

  • A、输出格式描述符的域宽不够,不能输出
  • B、输出为21.38e+01
  • C、输出为218.83
  • D、输出为218.82631
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

下面程序的输出结果是【】。include include class point{double x; double y;

下面程序的输出结果是【 】。

include <iostream.h>

include <math.h>

class point

{

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) );

}

void main()

{

point p1(1,2);

point p2(5,2);

cout<<distance(p1,p2)<<end1;

}


正确答案:4
4 解析:本题考核友元函数的应用。分析程序:类point中定义了两个私有成员x和y,以及一个友元函数distance。从而,函数 distance可以访问类point中的任何成员。在函数 distance中,返回值为sqrt((a. x-b. x)*(a. x-b. x)+ (a. y-b. y)*(a. y-b. y))。由此可知,函数distance的功能是计算a、b两点之间的距离。在土函数main中,先定义两点:p1(1,2)和p2(5,1)。然后调用函数distance计算两点之间的距离为4,所以程序最后输出为4。

第2题:

有以下程序 include typedef struct { int num;double s; }REC; void funl(REC *x) { x

有以下程序 include<stdio.h> typedef struct { int num;double s; }REC; void funl(REC *x) { x->num=23;x->s=88.5; } void main() { REC a={16,90.0}; fun1(&A); printf("%d\n",a.num); } 程序运行后的输出结果是( )。


正确答案:23
23

第3题:

(15)程序段:int x=12; double y=3.141593; printf(“%d%8.6f”,x,y);的输出结果是

A)123.141593 B)12 3.141593 C)12,3.141593 D)123.141593


正确答案:A

第4题:

有以下程序段:include define MIN(x,y)(x)<(y)?(x):(y) void main() { int i,j,K; i

有以下程序段:

include<iostream.h>

define MIN(x,y) (x)<(y)?(x):(y)

void main()

{

int i,j,K;

i=10;j=15;

k=10*MIN (i,j);

cout<<k<<endl;

}

程序执行后的输出结果是______。


正确答案:15
15

第5题:

下列程序运行后的输出结果是( )。

#include

using namespace std;

int fun(int x) { return x*x; }

double fun(double x,int y=2) { return x*y; }

int main()

{

int a=5;

double b= 1.2;

cout

}

A. 27.4

B.26.44

C. 12.4

D.程序有误


参考答案:A

第6题:

有以下程序include using namespace std;class sample{private:int x;public:sample(

有以下程序#include <iostream>using namespace std;class sample{private: int x;public: sample(int a) { x=a; } friend double square(sample s);};double square(sample s){ return s. x*s. x;}int main(){ sample s1(20),s2(30); cout<<square(s2)<<end1; return 0;}执行结果是( )。

A.20

B.30

C.900

D.400


正确答案:C

第7题:

分析以下程序执行结果【】。 include int f (int x, int y){return x,y; } double f (d

分析以下程序执行结果【 】。

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;

}


正确答案:24 19.24
24, 19.24

第8题:

以下程序的输出结果是______。 include int add(int x, int y) { return x+y; } doub

以下程序的输出结果是______。

include<iostream.h>

int add(int x, int y)

{

return x+y;

}

double add(double x, double y)

{

return x+y;

}

void main()

{

int a=3, b=3;

double c=6.5, d=1.5;

cout<<add(a, b)<<","<<add(c, d)<<end1;

}


正确答案:68
6,8

第9题:

以下程序的执行结果是 ( )。include using namespace std;class sample{private: int

以下程序的执行结果是 ( )。 #include <iostream> using namespace std; class sample { private: int x; public: sample (int A) { x=a; } friend double square(sample s); }; double square(sample s) {

A.20

B.30

C.900

D.400


正确答案:C
解析:本题考核友元函数的应用。程序中函数square()是类sample的一个友元函数,它可以直接访问类sample的所有成员。它的功能是返回类sample的私有数据成员x的平方。所以程序的执行结果是:900。注意:友元函数不是类的成员函数,在类外定义时不要加上类名及其作用域运算符(::)。友元函数的调用与一般函数的调用的方式和原理一致,可以在程序的任何地方调用它。

第10题:

有以下程序include using namespace std; class sample { private: int x; public:

有以下程序 #include <iostream> using namespace std; class sample { private: int x; public: sample(int a) { x=a; } friend double square(sample s); }; double square(sample s) { return s.x*s.x; } int main() { sample s1 (20),s2(30); cout<<square(s2)<<end1; return 0; } 执行结果是

A.20

B.30

C.900

D.400


正确答案:C
解析:本题考核友元函数的应用。程序中函数square是类sample的一个友元函数,它可以直接访问类sample的所有成员。它的功能是返回类sample的私有数据成员x的平方。所以程序的执行结果是:900。注意:友元函数不是类的成员函数,在类外定义时不要加上类名及其作用域运算符(::)。友元函数的调用与一般函数的调用的方式和原理一致,可以在程序的任何地方调用它。

更多相关问题