4
8
12
16
18
第1题:
阅读以下说明和Java源程序,将应填入(n)处的字句写在对应栏内。
【说明】
以下程序能够计算三角形、矩形和正方形的周长并输出。
程序由5个类组成:AreaTest是主类,类Triangle、Rectangle和Square分别表示三角形、矩形和正方形,抽象类Figure提供了一个计算周长的抽象方法。
【程序】
public class girthTest{
public static void main (String args[]){
Figure[]figures={
new Triangle (2,3,3),new Rectangle(5,8),new Square(5)
};
for(int i=0;i<figures.length;i++){
System.out.println(figures[i]+"girth="+figures[i].getGirth());
}
}
}
public abstract class Figure{
public abstract double getGirth();
}
public class Rectangle extends (1) {
double height;
double width;
public Rectangle(double height,double width){
this.height=height;
this.width=width;
}
public String toString(){
return "Rectangle:height="+height+",width="+width+":";
}
public double getGirth(){
return (2);
}
}
public class Square extends (3) {
public Square(double width){
(4);
}
public Stdng toString(){
return "Square:width='+width+":";
}
}
public class Triangle extends (5) {
double la;
double lb;
double lc;
public Triangle(double la,double lb,double lc){
this.la=la;this.lb=lb;this.lc=lc;
}
public String toString(){
return "Triangle:sides=" +la+"," +lb+"," +lc+":";
}
public double getGirth(){
return la+lab+lc;
}
}
第2题:
What is length (width, depth) of Hold No.1?
第3题:
阅读下列程序说明和C代码,把应填入其中n处的字句写在对应栏内。
【说明】
下面的程序能够计算不同图形的面积。程序中把每个图形的数据定义成结构类型,利用共同体类型描述2种图形的数据。程序根据输入参数代表的图形类型,求出图形的面积并输出。
【程序】
struct Circle
{
float x,y; /*圆心位置*/
float r; /*圆半径*/
};
struct Rectangle
{
float width; /*矩形宽*/
float length; /*矩形长*/
};
union shape
{
struct Circle circle;/*圆数据结构*/
struct Rectangle rectangle;/*矩形数据结构*/
};
main()
{
union shape a;
float area;
int i;
printf(“input number: 1circle,2rectangle,3 end\n”);
scanf("%d",&i);
while (1) /*循环接收输入,并计算输出*/
{
switch(i)
{
case 1:printf(“input radius:\n”);
scanf(“%f”, (2);/*共同体类型变量接收输入*/
area=3.1415926* (3);
printf(“the area of circle=%f\n”,area);
break;
case 2:printf(“input width and length :\n”);
seanf(“%f,%f”, (4);/*共同体类型变量接收输入*/。
area=(5);
printf(“the area of rectangle=%f\n”,area);
break;
}
printf(“input number:1 circle,2 rectangle,3 end\n”);
scanf(“%d”,&i);
}
}
第4题:
有以下程序: #include <iostream> using namespace std; class A { private: int x,y; public: void set (int i,int j) { x=i; y=j; } int get_y() { return y; } }; class box { private: int length,width; A label; public: void set(int 1,int w, int s,int p) { length=1; width=w; label.set(s,p); } int get_area() { return length*width; } }; int main() { box small; small.set(2,4,1,35); cout<<small.get_area()<<end1; return 0; } 运行后的输出结果是( )。
A.8
B.4
C.35
D.70
第5题:
阅读以下说明和Java源程序,将应填入(n)处的字句写在答题纸的对应栏内。
说明
以下程序的功能是计算三角形、矩形和正方形的面积并输出。
程序由5个类组成:AreaTest是主类,类Triangle、Rectangle和Square分别表示三角形、矩形和正方形,抽象类Figure提供了一个计算面积的抽象方法。
程序
public class AreaTest{
public static void main(String args[]){
Figure[]figures={
new Triangle(2,3,3),new Rectangle(5,8), new Square(5)
};
for(int i=0;i<figures.1ength;i++){
System.out.println(figures[i]+"area="+figures[i].getArea());
}
}
}
public abstract class Figure{
public abstract double SetAJea();
public class Rectangle extends (1) {
double height;
double width;
public Rectangle(double height,double width){
this.height=height;
this.width=width;
}
public String toString(){
return "Rectangle:height="+height+",width="+width+":";
}
public double getArea() { return (2);
} } public class Square extends (3) {
public Square(double width) {
(4);
}
public String toString() {
return "Square:width="+width+":";
} } public class Triangle extends (5). {
double la;
double lb;
double lc;
public Triangle(double la,double lb,double lc) {
this.la=la; this.lb=lb; this.lc=lc;
public String toString(){
return "Triangle: sides="+la+","+lb+","+lc+":";
public double getArea() {
double s=(la+lb+lc)/2.0;
return Math.sqrt(s*(s-la)*(s-lb)*(s?1c));
}
}
第6题:
下面程序运行时输出结果为______。
include<iostream.h>
include
class Rect
{
public:
Rect(int l, int w){length=l; width=w;)
void Print(){cout<<"Area:"<<length*width<<end1;}
void operator delete(void*p){free(p);}
private:
int length, width;
};
void main()
{
Rect *p;
p=new Rect(5, 4);
p->Print();
delete p;
}
第7题:
下面程序运行时输出结果为【 】。
include<iostream.h>
include<malloc.h>
class Rect
{
public:
Rect(int1,int w)(length=1;width=w;)
void Print(){cout<<"Area:"<<length *width<<endl;)
void *operator new(size-t size){return malloc(size);}
void operator delete(void *p){free(p)
private:
int length,width;
};
void main()
{
Rect*p;
p=new Rect(5,4);
p->Print();
delete p;
}
第8题:
阅读以下说明和Java程序,将应填入(n)处的字句写在对应栏内
[说明]
以下程序的功能时三角形、矩形和正方形的面积输出。
程序由5个类组成:areatest是主类,类Triangle,Rectangle和Square分别表示三角形、矩形和正方形,抽象类Figure提供了一个计算面积的抽象方法。
[Java程序]
public class areatest {
public static viod main(string args[]){
Figure[]Figures={
New triangle(2,3,3),new rectangle(5,8),new square(5)
};
for(int i=0; i<Figures.length;i++){
system.out.println(Figures+"area="+Figures.getarea());
}
}
}
public abstract class figure {
public abstract double getarea();
}
public class rectangle extends (1) {
double height;
double width;
public rectangle (double height,double width){
this.height=height;
this.width=width;
}
public string tostring(){
return"rectangle:height="+height+",width="+width+":";
}
public double getarea(){
return (2)
}
}
public class square exends (3)
{
public square(double width){
(4);
}
public string tostring(){
return"square:width="+width":";
}
}
public class triangle entends (5)
{
double la;
double lb;
double lc;
public triangle(double la,double lb,double lc){
this.la=la;this.lb=lb;this.lc=lc;
}
public string tostring()(
return"triangle:sides="+la+","+lb+","+lc+":";
}
public double get area(){
double s=(la+lb+lc)/2.0;
return math.sqrt(s*(s-la)*(s-lb)*(s-lc));
}
}
第9题:
下列程序的执行结果为【 】。
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)
}
第10题:
使用VC6打开考生文件夹下的工程test1_1,此工程包含一个源程序文件test1_1.cpp,但该程序运行有问题,请改正main函数中的错误,使该程序的输出结果如下:
Constructor called.
Default constructor called.
Area is 6
Area is 0
Area is 6
源程序文件test1_1,cpp清单如下:
include<iostream.h>
class RectAngle
{
private:
double ledge,sedge;
public:
RectAngle()
{
cout<<"Default constructor called.";
}
RectAngle(double l,double s)
{
ledge=l;sedge=s;
cout<<"Constructor called.";
}
void Set(double l,double s)
{
ledge=l;sedge=s;
}
void Area()
{
cout<<"Area is"<<ledge*sedge<<endl;
}
};
void main()
{
/***************** found *****************/
RectAngle Rect1(2,3);
RectAngle Rect2(1);
/**************** found *****************/
RectAnglC Rect3;
Rectl.Area();
/***************** found *****************/
RecL2.lodge=0;Rect2.sedge=0;
Reck2.Area();
Rect3.Area();
}