请把下面程序补充完整,正确答案是( )。 main( ) { float radius,length,area,volume; printf("Input a radius:"); Scanf("%f",&radius); length=2.0*PI*radius; /*引用无参宏求周长*/area=PI*radius*redius; /*引用无参宏求而积*/ volume=PI*radius*radius*radius*3/4; /*引用无参宏求体积*/ printf("length=%.2f,area=%.2f,volume=%.2f\n",length,area,volume); }
A.PI=3.1415926
B.Const PI=3.14159
C.#define PI3.1415926
D.Float PI=3.14159
第1题:
有以下程序 #include <stdio.h> main() { int n,*p=NULL; *p=&n; printf("Input n:");scanf("%d",&p);printf("output n:");printf("%d\n",p); } 该程序试图通过指针p为变量n读入数据并输出,但程序有多处错误,以下语句正确的是
A.int n,*p=NULL;
B.*p=&n;
C.scanf("%d",&p)
D.printf("%d\n",p);
第2题:
有以下程序: #inlucde<stdio.h> main()D)2 3 3 {int n,*P=NULL; *p=&n; printf("input n:");scanf("%d",&p);printf("output n:");printf("%d\n",p); } 该程序试图通过指针P为变量n读入数据并输出,但程序有多处错误,以下语句正确的是( )。
A.int n,*P=NULL;
B.*P=&n;
C.scanf(“%d",&p)
D.printf("%d\n",p);
第3题:
以下程序的运行结果是( )。 define A 4 define B(x)A*x/2 main() {float c,a=8.0; c=B(A; printf("%f\n",C); }
第4题:
使用VC6打开考生文件夹下的工程test9_3,此工程包含一个源程序文件test9_3.cpp,其中定义了Circle类与Money类, Circle类可对半径为r的圆进行周长与面积的计算,而Money类用于计算一圆形游泳池的造价。游泳池四周有原形过道,过道外围上栅栏,过道宽度为3米,根据键入的游泳池半径,每米栅栏价格及每平方米过道价格,即可计算出游泳池的造价。请按要求完成下列操作,将程序补充完整。
(1)定义符号常量PI(值为3.14159f)与WIDTH(值为3.00f),分别用于表示圆周率与过道的固定宽度。请在注释“//**1**”之后添加适当的语句。
(2)定义Circle类默认构造函数,把私有成员radius初始化为参数r的值。请在注释 “//**2**” 后添加适当的语句。
(3)完成Money类默认构造函数的定义,把私有成员FencePrice(每米栅栏的价格)、ConcretePrice(每平方米过道的价格)初始化为参数f,c的值。请在注释“//**3**”之后添加适当的语句。
(4)完成Money类成员函数floatMoney::TotalMoney(noat fencelen,float conarea)的定义,根据参数fencelen(栅栏的长度)和conarea(过道的面积),返回栅栏与过道的总造价。请在注释“//**4**”之后添加适当的语句。
注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。
源程序文件test9_3.cpp清单如下:
include<iostream.h>
//**1**
class Circle
{
private:
float radius;
public:
//**2**
float Circumference(){return 2 * PI * radius;)
float Area(){return PI * radius * radius;)
};
class Money
{
private:
float FencePrice;
float ConcretePrice;
public:
Money(float f,float c);
float TotalMoney(float fencelen, float conarea);
};
Money::Money(float f,float c)
{
//**3**
}
float Money::TotalMoney(float fencelen,float conarea)
{
//**4**
}
void main()
{
float radius,fence,concrete;
cout.setf(10s::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"Enter the radius of the pool:";
cin>>radius;
cout<< "Enter the FencePrice:";
cin>>fence;
cout<<"Enter the ConcretePrice:";
cin>>concrete;
Circle Pool(radius);
Circle PoolRim(radius + WIDTH);
Money mon(fence,concrete);
float totalmoney=mon.TotalMoney(PoolRim.Circumference(),(PoolRim.Area() - P00l.Area()));
cout<<"The total money is RMB"<<totalmoney<<endl;
}
第5题:
有如下程序 main() { float x=2.0,y; if(x<0.0)y=0.0; else if(x>10.0)y=1.O/x; else y=1.0; printf("%f\n",y);} 该程序的输出结果是
A.0
B.0.25
C.0.5
D.1
第6题:
阅读以下说明和JAVA 2代码,填入(n)处的。
[说明]
以下JAVA程序实现了在接口interface iShape2D的定义和应用,仔细阅读代码和相关注释,将程序补充完整。
[代码6-1]
interface iShape2D //定义接口
{
(1)
(2)
}
(3)//实现CRectangle类
{
int width, height;
(4) CRectangle (int w,int h) {
width=w;
height=h;
}
public void area ( ){ //定义area( )的处理方式
System. out.println ("area="+width*height);
}
}
(5)//实现CCircle类
{
double radius;
(6) CCircle (double r) {
radius=r;
}
public void area ( ) { //定义area( )的处理方式
System.out.println ("area="+pi*radius*radius);
}
}
[代码6-2]
public class app10_4
{
public static void main(String args[])
{
CRectangle rect=new CRectangle (5,10);
rect.area ( ); //调用CRectangle类里的area ( ) method
CCircle cir=new CCircle (2.0);
cir.area ( ); //调用CCircl类里的area ( ) method
}
}
第7题:
执行下面程序的正确结果是 ( ) main() {float a=1.9 switch(A) { case 0:printf("0000"); case 1:printf("1111"); case 2:printf("3333"); } printf("%f",A) ; }
A.1.900000
B.111133331.900000
C.33331.900000
D.00001111233331.900000
第8题:
Interrupts are an important part of embedded
systems. Consequently, many compiler vendors
offer an extension to standard C to support interrupts.
Typically, the keyword is __interrupt. The following
code uses __interrupt to define an interrupt service
routine (ISR). Point out problems in the code.
__interrupt double compute_area (double radius)
{
double area = PI * radius * radius;
printf("\nArea = %f", area);
return area;
}
第9题:
下列程序中,正确的为______。
A.main() { int *pb=&b; float 1>=15.25; print f("%d\n" ,*pb); }
B.amin() { int a,*pa; a=10; *pa=a; prinffC%d",*pa); }
C.main() { char s[20]; char *ps=&s; scanf("%s",*p); printf("%s",*p); }
D.main() { char str[10]; int *ps=str[0]; str="abcdefg"; printf("%s",*p); }
第10题:
()阅读下列说明和C语言程序,将应填入 (n)处的语句写在答题纸的对应栏内。[说明]有一个一维数组cj,内放20个学生成绩,求平均成绩。函数ave用来求20个学生的平均成绩。[C语言函数]float ave(float a[20]){ int i;float aver,sum= (1) ;for(i=1;i<20;i++) sum= (2) ;aver= (3) ;return( (4) );}main(){ float cj[20],aver;int i;printf(“input 20 cj:\n”);for(i=0;i<20;i++) scanf(“%f”,&cj[i]);printf(“\n”);aver= (5) ;printf(“average cj is %6.2f”,aver);}
第11题:
请读程序: #include
第12题:
第13题:
main(){ float x=123.456; printf("%-5.2f\n",x);}以上程序输出的结果是______。
A.123.4
B.123.5
C.123.45
D.123.46
第14题:
下列给定程序中,函数fun()的功能是;计算函数 F(x, y ,z)=(x+ y)/(x-y)+(z+ y)/(z-y)的值。其中x和y不相等,z和y不等。例如,当x的值为9,y的值为11,2的值为15时,函数值为-3.50。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main 函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio. h>
include <math. h>
/**************found******************/
define FU(m, n) (m/n)
float fun(float a, float b, float c)
{ float value;
value=FU(a+ b, a-b)+FU(c+ b, c-b);
/*************found******************/
return(Value);
}
main()
{ float x, y, z, sum;
printf ("Input x y z:: ");
scanf("%f%f%f", &x, &y, &z);
printf("x=%f, y=%f, z=%f\n ",x, y, z);
if (x==y||y==z) {printf ("Data error! \n ");
exit (0); }
sum=fun (x, y, z);
printf("The result is:%5. 2f\n ",sum);
}
第15题:
指出下面程序段中的错误,并说明出错原因【 】。
class Location {
int X, Y=20;
protected:
int zeroX, zeroY;
int SetZero(int ZeroX, iht ZeroY);
private:
int length, height;
public:
float radius;
void init(int initX,int initY);
int GetX();
Int GetY();
};
第16题:
有如下程序 main() {float x=2.0,y; if(x<0.0)y=0.0; else if(x>10.0)y=1.0/x; else y=1.0; printf("%f\n",y);} 该程序的输出结果是
A.0.000000
B.0.250000
C.0.500000
D.1.000000
第17题:
以下程序的输出结果是【 】。
include<stdio.h>
main()
{ struct stru
{ int a;
float b;
char d[4];
};
printf("%d\n",sizeof(struct stru));
}
第18题:
下面的程序在编泽时产生错误,其出错原因是( )。 #include<stdio.h> main() {int 1_case;float printF; printf("请输入2个数:"); scanf ("%d%f",&1_case,&printF); printf("%d%f\n",1_case,printF); }
A.定义语句出错,1_case不能作为变量名
B.定义语句出错,printF不能用作用户自定义标识符
C.定义语句无错,scanf不能作为输入函数使用
D.定义语句无错,printf不能输出1_case的值
第19题:
阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。
【说明】
以下程序的功能是计算正方体、球体和圆柱体的表面积和体积并输出。
程序由4个类组成:类cube、sphere和cylinder分别表示正方体、球体和圆柱体;抽象类 container为抽象类,提供了两个纯虚拟函数surface_area()和volum(),作为通用接口。
【C++程序】
include<iostream.h>
define pi 3.1416
class container{
protected:
double radius;
public:
container(double radius) {container::radius=radius;}
virtual double surface_area()=0;
virtual double velum()=0;
};
class cube:(1){ //定义正方体类
public:
cube(double radius):container(radius){};
double surface_area () {return 6 * radius * radius;}
double volum() {return radius * radius * radius;}
};
class sphere:(2){ //定义球体类
public:
sphere(double radius): container(radius){};
double surface_area() { return (3);}
double volum() {return pi * radius * radius * radius * 4/3;}
};
class cylinder:(4){ //定义圆柱体类
double height;
public:
cylinder(double radius,double height):container(radius)
{
container::height=height;
}
double surface_are a () { return 2 * pi * radius * (height+radius); }
double volum () {return (5);}
};
void main()
{
container * p;
cube obj1 (5);
sphere obj2(5);
cylinder obj3(5,5);
p=&obj1;
cout<<“正方体表面积”(<<p->surface_area()<<end1;
cont<<“正方体体积”<<p->volume()<<end1;
p=&obj2;
cout<<“球体表面积”<<p->surface_area()<<end1;
cout<<“球体体积”<<p->volume()<<end1;
p=&obj3;
cout<<“球体表面积”<<p->surface_area()<<end1;
cout<<“球体体积”<<p->volume()<<end1;
}
第20题:
下面程序的运行结果是typedef union student{ char name[10]; long sno; char sex; float score[4];}STU;main(){ STU a[5]; printf("%d\n",sizeof(a));}
第21题:
下面程序的执行结果是( )。 #include<iostream> using namespace std; class building { public: building() {} building(unsigned stories, float breadths, float lengths) { story = stories; breadth = breadths; length = lengths;} void getstory(void) { cout<<"story is:"<<story<<endl;} void getarea(void) { area = length*breadth*story;cout<<"area is:"<<area<<endl;} private: unsigned story; float length; float breadth; float area; }; void main(void) { building b1,b2;building b3(10u,16.6,58.8); b1.getstory(); b1.getarea(); b2.getstory(); b2.getarea(); b3.getstory(); b3.getarea();}
A.story is:0 area is:0 story is:0 area is:0 story is:10 area is:9760.8
B.story is:null area is:null story is:null area is:null story is:10 area is:9760.8
C.前两个对象输出的结果是不定的,后一个对象的结果正确
D.前两个对象没有初值,因此程序编译时出错
第22题:
下面哪个表达式正确使用了math()?
第23题: