网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

●试题六

阅读以下说明和C++程序,将应填入(n)处的语句写在答题纸的对应栏内。

【说明】

以下程序的功能是计算三角形、矩形和正方形的面积并输出。

程序由4个类组成:类Triangle、Rectangle和Square分别表示三角形、矩形和正方形;抽象类Figure提供了一个纯虚拟函数getArea(),作为计算上述3种图形面积的通用接口

【C++程序】

#include<iostream.h>

#include<math.h>

class Figure{

public:

virtual double getArea()=0:∥纯虚拟函数

};

class Rectangle: (1) {

protected:

double height;

double width;

public:

Rectangle(){};

Rectangle(double height,double width){

this->height=height;

this->width=width;

}

double getArea(){

return (2) ;

}

};

class Square: (3) {

public:

Square(double width){

(4) ;

}

};

class Triangle: (5) {

double la;

double Ib;

double lc;

public:

Triangle(double la,double lb,double lc){

This->la=la;this->lb=lb;this->lc=lc;

}

double getArea(){

double s=(la+lb+±c)/2.0;

return sqrt(s*(s-1a)*(s-1b)*(s-1c));

}

};

void main(){

Figure*figures[3]={

new Triangle(2,3,3),new Rectangle(5,8),new SqUare (5) );

for (int i=0;i<3;i++){

cout<<"figures["<<i<<"]area="<<(figures[i])->getArea()<<endl;

}

}


参考答案

更多 “ ●试题六阅读以下说明和C++程序,将应填入(n)处的语句写在答题纸的对应栏内。【说明】以下程序的功能是计算三角形、矩形和正方形的面积并输出。程序由4个类组成:类Triangle、Rectangle和Square分别表示三角形、矩形和正方形;抽象类Figure提供了一个纯虚拟函数getArea(),作为计算上述3种图形面积的通用接口【C++程序】#includeiostream.h#includemath.hclass Figure{public:virtual double getArea()=0:∥纯虚拟函数};class Rectangle: (1) {protected:double height;double width;public:Rectangle(){};Rectangle(double height,double width){this-height=height;this-width=width;}double getArea(){return (2) ;}};class Square: (3) {public:Square(double width){(4) ;}};class Triangle: (5) {double la;double Ib;double lc;public:Triangle(double la,double lb,double lc){This-la=la;this-lb=lb;this-lc=lc;}double getArea(){double s=(la+lb+±c)/2.0;return sqrt(s*(s-1a)*(s-1b)*(s-1c));}};void main(){Figure*figures[3]={new Triangle(2,3,3),new Rectangle(5,8),new SqUare (5) );for (int i=0;i3;i++){cout"figures["i"]area="(figures[i])-getArea()endl;}} ” 相关考题
考题 ●试题八阅读以下说明和Java代码,将解答写入答题纸的对应栏内。【说明】下面的程序是从命令行输入3个数传递到public static void main(String args[])方法中(如 java IsTriangle 3 4 5),并判断这3个数能否构成三角形的3条边,并显示相应的结果。请在程序的每条横线处填入适当的语句,使程序的功能完整。注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。public class IsTriangle{public static void main(String args[]){int a[]=new (1) [args. (2) ];for(int i=0;i3; (3) ){a[i]= (4)}if( (5) )System.out.println(a[0]+ ","+a[1]+ ","+a[2]"能构成三角形的3条边");elseSystem.out.println(a[0]+ ","+a[1]+ ","+a[2] "不能构成三角形的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);}}

考题 阅读以下说明和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));}}

考题 阅读以下说明和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;}}

考题 ( 12 ) “ 图形 ” 类 Shape 中定义了纯虚函数 CalArea() ,“ 三角形 ” 类 Triangle 继承了类Shape ,请 将Triangle 类中的 CalArea 函数补充完整。class Shape{public:virtual int CalArea()=0;}class Triangle: public Shape{public:Triangle{int s, int h}: side(s),height(h) {}【 12 】 { return side*height/2 ; }private:int side;int height;};

考题 阅读以下说明和C++代码,将应填入(n)处的字句写在对应栏内。【说明】以下C++程序的功能是计算三角形、矩形和正方形的面积并输出。程序由4个类组成:类 Triangle、Rectangle和Square分别表示三角形、矩形和正方形:抽象类Figure提供了一个纯虚函数getAxea(),作为计算上述3种图形面积的通用接口。【C++代码】include<iostream>include<cmath>using namespace std;class Figure{public:virtual double getArea()=0;//纯虚函数};class Rectangle : (1) {protected:double height;double width;public:Rectangle(){}Rectangle(double height, double width){this->height=height;this->width=width;}double getArea(){return (2);}};class Square: (3) {public:Square(double width){(4);}};class Triangle: (5) {private:double la,lb,lc;public:Triangle(double la,double lb,double lc){this->la=la;this->1b=1b;this->lc=lc;}double getArea(){double s=(la+lb+lc)/2.0;return sqrt(s*(s-la)*(s-lb)*(s-lc));}int main(){Figure *figures[3]={new Triangle(2,3,3),new Rectangle(5,8), new Square(5)};for(int i=0;i<3;i++){cout<<"figures["<<i<<"]area="<<(figures[i])->getArea()<<endl;}return 0;}

考题 阅读以下说明和C++代码,填入(n)处。[说明]以下C++代码使用虚函数实现了同一基类shape派生出来的Class rectangle、Class triangle、Class circle实现了计算矩形、圆形面积的计算。仔细阅读以下代码,将(n)处语句补充完整。[代码5-1]include<iostream.h>define PI 3.14159class shape {//基类protected:(1);public:(2);(3);};[代码5-2]class rectangle: public shape {public:rectangle (int x2,int y2,int r2): (4) {};double area ( ) {return x*y; };};class circle: public shape {public:circle (int x3,int y3,int r3):(5){};double area ( ) {return r*r*PI; };};[代码5-3]void main ( ){rectangle r (10,20,0);circle c (0,0,30);shape (6);cout<<"长方形面积="<<s1->area ( ) <<endl;cout<<"圆形面积="<<s2->area ( ) <<endl;}[运行结果]长方形面积=200圆形面积=2827.43

考题 使用VC6打开考生文件夹下的工程test3_3,此工程包含一个源程序文件test3_3.cpp,其中建立了普通的基类base用于存储边的信息,建立派生类triangle和square,用于存储三角形和正方形的信息。按要求完成下列操作,将类定义补充完整。(1)定义基类base的保护数据成员x和y用于记录边的长度,它们都是int型的数据。请在注释“//**1**”之后添加适当的语句。(2)完成基类base默认构造函数的定义,把数据成员x和y分别初始化为参数a和b的值,要求使用作用域符“::”。请在注释“//**2**”之后添加适当的语句。(3)完成派生类triangle函数disp的定义,使其以“三角形面积:”的格式将三角形的面积输出到屏幕上。请在注释“//**3**”之后添加适当的语句。(4)添写派生类square的默认构造函数的定义,使其调用基类的构造函数,记录下正方形的边长信息a,其缺省值为0。请在注释“//** 4 **”之后添加适当的语句。输出结果如下:三角形面积:200正方形面积:400注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。源程序文件test3_3.cpp清单如下:include<iostream.h>class base{protected://** 1 **public:base(int a,int b){//** 2 **}virtual void disp(){cout<<"调用base基类"<<endl;)};class triangle:public base{public:triangle(int a,int b):base(a,b){};void disp(){//** 3 **}};class square:public base{public://** 4 **void disp(){cout<<"正方形面积:"<<x*y<<endl;}};void main(){base *p;triangle t(20,20);square s(20);p=t;p—>disp();p=S;p->disp();}

考题 阅读以下说明及C++程序代码,将应填入(n)处的语句写在对应栏内。【说明】本程序的功能是根据矩形左上角和右下角顶点坐标生成一个矩形对象,然后输出该矩形4个顶点的坐标,计算并输出该矩形的面积。【C++代码】include<iostream>using namespace std;class MyPoint( //表示平面坐标系中的点的类double x;double y;public:MyPoint (double x,double y){this->x=x;this->y=y;}double getX()const{(1);}double getY()const{ return y;}void show()const{ cout<<'('<<x<<','<<y<<')';}};class MyRectangle{ //表示矩形的类MyPoint upleft; //矩形的左上角顶点MyPoint down right; //矩形的右下角顶点public:MyRectangle(MyPoint upleft,MyPoint downright);MyPoint getUpLeft()const{return up_left;} //返回左上角坐标MyPoint getDownRight()const{return down_right;} //返回右下角坐标MyPoint getUpRight()const; //返回右上角坐标MyPoint getDownLeft()const; //返回左下角坐标double area()const; //返回矩形的面积};MyRectangle:: MyRectangle((2)):up left(p1),down_right(p2){}MyPoint MyRectangle::getUpRight()const{return MyPoint(down_right.getX(),up_left.getY());}MyPoint MyRectangle::getDownLeft()const{return MyPeint((3));}double (4) ::area()const{return (getUpLeft(),getX()-getDownRight().getX())*(getDownRight().getY()-getUpLeft().getY());}int main( ){MyRectangle r(MyPoint(0,2),MyPoint(2,0));r.getUpLeft(),show();r.getUpRight().show();r.getDown Right().show();(5);cout<<r.area()<<end1;return 0;}

考题 阅读以下说明和C++程序,将应填入(n)处的语句写在的对应栏内。【说明】以下程序的功能是计算三角形、矩形和正方形的面积并输出。程序由4个类组成:类Triangle、Rectangle和Square分别表示三角形、矩形和正方形;抽象类Figure提供了一个纯虚拟函数getArea(),作为计算上述3种图形面积的通用接口。【C++程序】include<iostream.h>include<math.h>class Figure {public:virtual double getArea()=0; //纯虚拟函数};class Rectangle:(1){protected:double height;double width;public:Rectangle() {};Rectangle(double height,double width) {this->height=height;this->width=width;}double getArea() {return (2);}};class Square:(3){public:Square(double width){(4);}};class Triangle:(5){double la;double lb;double lc;Public:Triangle(double la, double lb, double lc) {This->la=la; this->lb=lb; this->lc=lc;}double getArea() {double s = (la+lb+±c)/2.0;return sqrt(s,(s-la)*(s-lb)*(s-Ic));}};void main() {Figure*figures[3]={new Triangle(2,3,3), new Rectangle(5,8), new SqUare(5));for(int i=0;i<3;i++){cout<<"figures["<<i<<"]area="<<(figures[i])->getArea()<<endl;}}

考题 阅读下列C++程序和程序说明,将应填入(n)处的字句写在对应栏内。【说明】以下C++程序的功能是计算三角形、矩形和正方形的面积并输出。程序由4个类组成:类Triangle、Rectangle和Square分别表示三角形、矩形和正方形;抽象类Figure提供了一个纯虚拟函数getArea(),作为计算上述3种图形面积的通用接口。include<iostream.b>include<math.h>class Figure{public:virtual double getArea0=0; //纯虚拟函数};class Rectangle: (1) {protected:double height;double width;public:Rectangle(){};Rectangle(double height, double width){This->height=height;This->width=width;}double getarea(){return (2);}};class Square: (3) {public:Square(double width){(4);}};class Triangle: (5) {double la;double lb;double lc;public:Triangle(double la, double lb, double lc){this->la=la; this->lb; this->lc;}double getArea(){double s=(la+lb+lc)/2.0;return sqrt(s*(s-la)**(s-lb)*(s-lc));}};viod main(){Figure* figures[3]={new Triangle(2,3,3), new Rectangle(5,8), new Square(5));for(int i=0;i<3;i++){cout<<"figures["<<i<<"]area="<<(figures[i])->getarea()<<endl;}}

考题 阅读以下说明和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));}}

考题 阅读以下说明和C++程序,将应填入(n)处的字句写在答题纸的对应栏内。说明以下程序的功能是计算三角形、矩形和正方形的面积并输出。程序由4个类组成:类Triangle、Rectangle和Square分别表示三角形、矩形和正方形;抽象类Figure提供了一个纯虚拟函数getArea(),作为计算上述三种图形面积的通用接口。c++程序include <iostream.h>inclule <math.h>class Figure {public:virtual double getArea()= 0; // 纯虚拟函数};class Rectangle: (1) {protected:double height;double width;public:Rectangle() { };Rectangle(double height, double width) {this->height = height;this->width = width;}double getArea() {return (2) ;}class Square: (3) {public:Square(double width) {(4) ;}};class Triangle: (5) {double la;double lb;double lc;public:Triangle(double la, double lb, double lc) {this->la = la; this->lb ='lb; this->lc = lc;}double getArea() {double s = (la+lb+lc)/2.0;return sqrt(s*(s-la)*(s-lb)*(s-lc));} }; void main() {Figure* figures[3] = {new Triangle(2,3,3), new Rectangle(5,8), new Square(5)};for (int i = 0; i < 3; i++) {com << "figures[" << i << "] area =" << (figures[i])->getArea0 << endl;}

考题 阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【说明】以下程序的功能是计算正方体、球体和圆柱体的表面积和体积并输出。程序由4个类组成:类cube、sphere和cylinder分别表示正方体、球体和圆柱体;抽象类 container为抽象类,提供了两个纯虚拟函数surface_area()和volum(),作为通用接口。【C++程序】include<iostream.h>define pi 3.1416class 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;}

考题 阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【说明】下面程序的功能是计算并输出某年某月的天数,函数IsLeap Year()能够判断是否是闰年。【C++程序】include < iostream >using namespace std;(1) Month {Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec };class Date {public:Date( int year, Month m_ month) {this→year = year;if( (2) ) month: Jan;else month = m_ month;};~Date(){};bool IsLeap Year( ) {return ((year%4= =0 year% 100 ! =0)|| year%400= =0);};int CaculateDays( ) {switch(m_month ) {case (3) ;{if (4) return 29;else return 28;}case Jan: case Mar: case May: case Jul: case Aug: case Oct: case Dec: return 31;case Apr: case Jun: case Sop: case Nov: return 30;}}private:int year;Month month;};void main( ) {Date day(2000,Feb);cout < <day. (5) ( );}

考题 阅读下列程序说明和C++程序,把应填入其中(n)处的字句,写在对应栏内。【说明】阅读下面几段C++程序回答相应问题。比较下面两段程序的优缺点。①for (i=0; i<N; i++ ){if (condition)//DoSomething…else//DoOtherthing…}②if (condition) {for (i =0; i<N; i++ )//DoSomething}else {for (i=0; i <N; i++ )//DoOtherthing…}

考题 阅读以下说明和JAVA 2代码,将应填入(n)处的字句写在对应栏内。[说明]以下程序为类类型的变量应用实例,通过异常处理检验了类CCircle的变量的合法性,即参数半径应为非负值。仔细阅读代码和相关注释,将程序补充完整。[JAVA代码]//定义自己的异常类class CCircleException extends Exception{}// 定义类 CCircleclass CCircle{private double radius;public void setRadius ( double r ) (1){if ( r<0 ) {(2)}else(3)}Public void show ( ) {System. out. println ( "area="+3.14*radius*radius );}}public class ciusample{public static void main ( String args[] ){CCircle cir=new CCircle( );(4) {cir. setRadius ( -2.0 )}(5){System. out. println ( e+" throwed" ) ;}cir. show( ) ;}}

考题 阅读以下说明和C++代码。[说明]已知类SubClass的getSum方法返回其父类成员与类SubClass成员j的和,类 SuperClass中的getSum为纯虚拟函数。程序中的第23行有错误,请修改该错误并给出修改后的完整结果,然后完善程序中的空缺,分析程序运行到第15行且尚未执行第15行的语句时成员变量j的值,最后给出程序运行后的输出结果。[C++代码]

考题 阅读下列程序说明和C程序,将应填入(n)处的字句写在对应栏内。[函数2.1说明]下面程序的功能是计算x和y的最小公倍数。[函数2.1]main(){ int m,n,d,r;seanf("%d %d",m,n);if(m<n) {r=m;m=n;n=r;}(1);while (d%n! =0) (2);printf("%d\n",d);}[函数2.2说明]下述程序接收键盘输入,直到句点“.”时结束。输入的字符被原样输出,但连续的空格输入将转换成一个空格。[函数2.2]include <stdio.h>main(){ char c,preChar='\0';c = getchar();while(c! = '.'){if((3)) putchar(c);else if(preChar! =' ') putchar(c);(4);c=(5);}}

考题 ●试题二阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】该程序运行后,输出下面的数字金字塔【程序】includestdio.hmain (){char max,next;int i;for(max=′1′;max=′9′;max++){for(i=1;i=20- (1) ;++i)printf(" ");for(next= (2) ;next= (3) ;next++)printf("%c",next);for(next= (4) ;next= (5) ;next--)printf("%c",next);printf("\n");}}

考题 试题三(共 15 分)阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。

考题 从下列2道试题(试题五至试题六)中任选 1道解答。如果解答的试题数超过1道,则题号小的1道解答有效。试题五(共15分)阅读以下说明、图和C++代码,填补C++代码中的空缺(1)~(5),将解答写在答题纸的对应栏内。【说明】已知对某几何图形绘制工具进行类建模的结果如图5.1所示,其中Shape为抽象类(应至少包含一个纯虚拟( virtual)函数),表示通用图形,Box表示矩形,Ellipse表示椭圆,Circle表示圆(即特殊的椭圆),Line表示线条。下面的C++代码用于实现图5-1所给出的设计思路,将其空缺处填充完整并编译运行,输出结果为:EllipseCircleEllipseCE【C++代码】include stringinclude iostreamusing namespace std;class Shape{public:Shape(const string name){m_name= name;}~Shape(){}(1) void paint() = 0;stringgetName()const {retumm name;}Private:string m_name;};//Box和 Line类的定义与 Ellipse类似,其代码略classEllipse (2) {public:Ellipse(const string name) : Shape(name){ cout"Ellipse" endl; }Voidpaint() { coutgetName()endl;}};classCircle (3) {public:Circle(const string name) : Ellipse(name){ cout"Circl"endl; }};class Diagram {public:void drawAShap(Shape* shape){ shape-paint(); }void drawShapes() {shapes[0] = new Circle("C");shapes[l] = new Ellipse("E");for (int i=O;i2; ++1) {drawAShap(shapes[i]);}}void close (){ /*删除形状,代码略 */ }private:Shape* shapes[2];};int main( ){Diagram* diagram = (4)diagram-drawShapes();diagram-close ();(5) diagram;}

考题 阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内[说明]以下程序的功能是计算三角形、矩形和正方形的面积并输出。程序由4个类组成:类Triangle,Rectangle和Square分别表示三角形、矩形和正方形;抽象类Figure提供了一个纯虚拟函数getArea(),作为计算上述三种图形面积的通用接口。[C++程序]include<iostream.h>include<math.h>class Figure{public:virtual double getArea()=0; //纯虚拟函数};class Rectangle: (1) {protected:double height;double width;public:Rectangle(){};Rectangle(double height,double width){This->height=height;This->width=width;}double getarea(){return (2);}};class Square: (3)public:square(double width){(4);}};class triangle: (5) {double la;double lb;double lc;public:triangle(double la,double lb,double lc){this->la=la;thiS->ib;this->lc;}double getArea(){double s=(la+lb+lc)/2.0;return sqrt(s*(s-la)**(s-lb)*(s-lc));}};viod main(){figure*figures[3]={new triangle(2,3,3),new Rectangle(5,8),new Square(5)};for(int i=0; i<3;i++){cout<<"figures["<<i<<"]area="<<(figures)->getarea()<<endl;}}};

考题 ()阅读下列说明和C语言程序,将应填入 (n)处的语句写在答题纸的对应栏内。[说明]下面程序是一个带参数的主函数,其功能是显示在命令行中输入的文本文件内容。[C语言函数]#include"stdio.h"main(argc,argv) int argc; char *argv[]; { (1) ; if((fp=fopen(argv[1],”r’’))== (2) ) { printf(”file not open!\n”);exit(0);} while( (3) ) putchar( (4) ); (5); }

考题 阅读以下说明和C++程序代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】在下面的C++代码中,类SalesTicket能够完成打印票据正文的功能,类HeadDec- orator与FootDecorator分别能够完成打印票据的台头和脚注的功能。已知该程序运行后的输出结果如下所示,请填补该程序代码中的空缺。这是票据的台头!这是票据正文!这是票据的脚注!---------------这是票据的台头!这是票据的脚注!【C++程序代码】#includeusing namespace std;class SalesTicket {public:(1) printTicket() { cout " 是票据正文!" endl;}class Decorator : public SalesTicket{SalesTicket *ticket;public:Decorator(SalesTicket *t){ ticket = t; }void printTicket(){if(ticket != NULL)ticket->printTicket();}};class HeadDecorator : public Decorator{public:HeadDecorator(SalesTicket *t): (2) { }void printTicket() {sour "这是票据的台头!" endl;Decorator::printTicket();}};class FootDecorator :public Decorator{public:FootDecorator(SalesTicket *t): (3)void printTicket() {Decorator::printTicket();cout "这是票据的脚注!" endl;}};void main(void) {SalesTicket t;FootDecorator f(t);HeadDecorator h( (4) );h.printTicket();cout "-------------------------" endl;FootDecorator a(NULL);HeadDecorator b( (5) );b.printTicket();}

考题 阅读下列说明和C++-代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。 【C++代码】 #include using namespace std; class invoice{ public: (1){ cout

考题 阅读下列说明和?C++代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 阅读下列说明和?Java代码,将应填入?(n)?处的字句写在答题纸的对应栏内。 【说明】 某快餐厅主要制作并出售儿童套餐,一般包括主餐(各类比萨)、饮料和玩具,其餐品种 类可能不同,但其制作过程相同。前台服务员?(Waiter)?调度厨师制作套餐。现采用生成器?(Builder)?模式实现制作过程,得到如图?6-1?所示的类图。