A.x<8 x>12
B.x<12 x>12
C.x<8>
D.x<12 x>12
第2题
A、x= 15, a=7, b=8
B、x= 15, a=6, b=7
C、x= 13, a=7, b=8
D、x= 13, a=6, b=7
第3题
A.8
B.12
C.14
D.16
第4题
阅读以下说明和C++代码,填充代码中的空缺,将解答填入答题纸的对应栏内。
【说明】
下面的程序用来计算并寻找平面坐标系中给定点中最近的点对(若存在多对,则输出其中的一对即可)。程序运行时,先输入点的个数和一组互异的点的坐标,通过计算每对点之间的距离,从而确定出距离最近的点对。例如,在图5-1所示的8个点中,点(1,1)与(2,0.5)是间距最近的点对。
【C++代码】
include <iostream>
include <cmath>
using namespace std;
class GPoint {
private:
double x, y;
public:
void setX(double x) { this->x = x; }
void setY(double y) { this->y = y; }
double getX() { return this->x; }
double getY() { return this->y; }
};
class ComputeDistance {
public:
double distance(GPoint a,GPoint b) {
return sqrt《a.getX() - b.getX())*(a.getX() - b.getX())
+ (a.getY() - b.getY())*(a.getY() - b.getY()));
}
};
int main()
{
int i,j, numberOfPoints=0;
cout<<"输入点的个数:";
cin>>numberOfPoints;
(1) points= neW GPoint[numberOfPoints];//创建保存点坐标的数组
memset(points,0,sizeof(points));
cout <<"输入"<< numberOfPoints<<"个点的坐标:";
for(i=0;i<numberOfPoints; i++){
double tmpx, tmpy;
cin>>tmpx>>tmpy;
points[i].setX(tmpx);
points[i].setY(tmpy);
}
(2) computeDistance= new ComputeDistance();
int p1=0,p2=1;//p1和p2用于表示距离最近的点对在数组中的下标
double shortestDistance= computeDistance->distance(points[p1], points[p2]);
//计算每一对点之间的距离
for(i=0;i<numberOfPoints; i++){
for(j=i+1;j< (3) ;j++){
double tmpDistance=computeDistance-> (4) ;
if ( (5) ) {
p1=i; p2 =j;
shortestDistance= tmpDistance;
}
}
}
cout<<"距离最近的点对是:(";
cout"points[p1].getX()<<","<<points[pl].getY()<<")和(";
cout<<points[p2].getX()<<","<<points[p2].getY()<<")"<<endl;
delete computeDistance;
return 0:
}
第7题
子函数Fun(int a, int b)的功能是,对任意两个整数a和b,返回两者中的最大值。以下程序是通过调用子函数Fun(int a, int b),找到三个整数中的最大值。若程序运行后的输出结果是8,请补充完整空白处缺少的代码。 #include <stdio.h> int Fun(int a, int b) { if(a>b) return_________; else return________; } int main() { int x=3, y=8, z=6, r; r=_______________; // 找到三个整数x,y,z中的最大值 printf("%d", r); return 0; }
A、第4行: a 第5行: b 第11行: Fun(Fun(x,y),z)
B、第4行: b 第5行: a 第11行: Fun(x,y,z)
C、第4行: 1 第5行: 0 第11行: Fun(x,y,z)
D、第4行: 0 第5行: 1 第11行: Fun(Fun(x,y),z)
第8题
子函数Fun(char x , char y)的功能是对任意两个字符x和y,如果x为真,则函数返回y的值,否则返回x的值。若使以下程序运行后的输出结果是7,请补充完整空白处缺少的代码。#include <stdio.h> char Fun(char x , char y) { if(__________) return y; else return x; } int main( ) { char a='9',b='8',c='7'; printf("____",Fun(_______________)); return 0; }
A、第4行: x 第11行:%c Fun(a,b),Fun(b,c)
B、第4行: x=0 第11行:%d Fun(b,c),Fun(a,b)
C、第4行: x==0 第11行:%c Fun(b,a),Fun(c,b)
D、第4行: x!=0 第11行:%d Fun(c,b),Fun(b,a)
第9题
A、7
B、8
C、10
D、15
第10题
8、设有如下代码 switch (x) { case 1 : System.out.println("Test1"); case 2 : case 3 : System.out.println("Test2"); break; } System.out.println("Test3"); } x为哪些数时输出内容中含有 "Test2" ?
A、0
B、1
C、2
D、3
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!