阅读以下说明和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)处的字句写在对应栏内

[说明]

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

程序由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 include 阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【C++程序】include < stdio. h >include < string. h >define Max 1000class Bank{int index;char date [Max] [10]; // 记录交易日iht amount[Max]; // 记录每次交易金额,以符号区分存钱和取钱int rest[ Max]; // 记录每次交易后余额static iht sum; // 账户累计余额public:Bank( ) {index =0;}void deposit( char d[ ] , int m) //存入交易{strcpy ( date [ index ], d);amount[ index] = m;(1);rest[ index] = sum;index++;}void withdraw (char d[ ], int m) //取出交易{strcpy( date[ index] ,d);(2);(3);rest[ index] = sum;index++;}void display( );};int Bank:: sum = 0;void Bank:: display ( ) //输出流水{int i;printf("日期 存入 取出 余额\n");for (4){printf(" %8s" ,date[i] );if (5)printf(" %6d" , -amount[i] );elseprintf( "%6d ",amount[i] );printf( "% 6d\n" ,rest[i] );} }void main( ){Bank object;object. deposit ( "2006.2.5", 1 00 );object. deposit( "2006.3.2" , 200);object. withdraw( "2006.4.1", 50);object. withdraw( "2006.4.5", 80);object. display ( );}本程序的执行结果如下:日期 存入 取出 余额 2006.2.5 100 1002006.3.2 200 3002006.4.1 50 2502006.4.5 80 170

阅读下列程序说明和c代码,将应填入(n)处的字句写在对应栏内。[说明]下面的程序利用递归算法计算x和y的最大公约数。[函数2.1]main ( ){ int x,y,k,t;scanf(" % d% d" , x, y);if(x>y) { t=x;x=y; y=t;}(1);while(k! =0){y=x;(2);k=y%x;}prinff( "% d" ,x); }[函数2.2说明]函数fun(char *str,char *substr的功能是计算子串sugbstr在串str中出现的次数。[函数2.2]fun(ehar * str, char * substr){ int x,y,z;(3);for(x=0;str[ x] ! = '\O';x + + )for(y=x,z=0;sabstr[z] = =str[y];(4),y+ +)if((5)= ='\0') {num + +;break;}return(num);}

阅读以下说明和流程图,将应填入(n)处的字句写在对应栏内。【说明】已知头指针分别为La和lb的有序单链表,其数据元素都是按值非递减排列。现要归并La和Lb得到单链表Lc,使得Lc中的元素按值非递减排列。程序流程图如下所示:

阅读以下说明及Visual Basic程序代码,将应填入(n)处的字句写在对应栏内。【说明】以下程序为求行列式X(5,5)的值S。【Visual Basic代码】Private Function col ( byval x ( 5,5 ) as integer ) as longdim fesult as longdim temp as longdim I as integerdim j as integerdim k as imegerresult = 0for I = to 5(1)for j = 1 to 5if I+j>6 thenk= ( 1+j ) mod 5elsek=1endiftemp=temp*x ( k,j )(2)result=(3)(4)(5)End function

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。[说明]本程序中预设了若干个用户名和口令。用户输入正确的用户名后,可以查找对应的口令,一旦输入结束标记“end”,程序结束。[C++程序]include <iostream. h>include <string. h>class User{ protected:char user[10];char pass[7];public:User(char[ ],char[]);(1) {return user;}(2) {return pass;}};User::User(char u[],char p[]){ strcpy(user,u);strcpy(pass,p); }void main(){ User ua[]={User("Li","123456"),User("wang","654321"),User("Song","666666")char name[10];while(1)cout< < "输入用户名:";cin> >name;if((3)= =0) break;for(int i=0;i<3;i+ +)if(strcmp(name,ua[i].getuser()) = =0){cout< <"密码:" < < ua[i].getpass() < <endl;(4);if((5))cout< <"该用户不存在!" < <endl;}}

阅读以下说明和C语言函数,将应填入(n)处的字句写在对应栏内。[说明]完成以下中序线索化二叉树的算法。[函数]Typedef int datatype;Typedef struct node {Int ltag, rtag;Datatype data;*lchild,* rchild;}bithptr;bithptr pre;void inthread ( p );{if{inthread ( p->lchild );if ( p->lchild==unll ) (1);if ( P->RCHILD=NULL) p->rtag=1;if (2){if (3) pre->rchild=p;if ( p->1tag==1 )(4);}INTHREAD ( P->RCHILD );(5);}}

阅读以下说明和流程图,将应填入(n)处的字句写在对应栏内。[说明]设学生某次考试的成绩按学号顺序逐行存放于某文件中,文件以单行句点“.”为结束符。下面的流程图读取该文件,统计出全部成绩中的最高分max和最低分min。

阅读以下说明和C++ 程序,将应填入(n)处的字句写在对应栏内。[说明]试从含有n个int 型数的数组中删去若干个成分,使剩下的全部成分构成一个不减的子序列。设计算法和编写程序求出数组的不减子序列的长。[C++ 程序]include<stdio.h>define N 100int b[]={9,8,5,4,3,2,7,6,8,7,5,3,4,5,9,1};int a [N];define n sizeofb/sizeofb[0]void main ( ){kit k,i,j;(1)(2)for (i=1;i<n; i++ ){for ( j=k;(3); j--);(4); /*长为 j+1 的子序列的终元素存储在 a[j+1]*/if ((5)k++; /*最长不减子序列长 k 增1*/}printf ( "K = %d\n ",k );}

阅读下列说明和流程图,将应填入(n)的字句写在对应栏内。【说明】下列流程图(如图4所示)用泰勒(Taylor)展开式sinx=x-x3/3!+x5/5!-x7/7!+…+(-1)n×x2n+1/(2n+1)!+…【流程图】计算并打印sinx的近似值。其中用ε(>0)表示误差要求。

阅读以下说明和c++码,将应填入(n)处的字名写在的对应栏内。[说明] 以下函数完成求表达式的值,请填空使之完成此功能。float sum ( float x ){ float s=0.0;int sign = 1;(1);for(inti=1;(2); i+ +){t=t*x;s=s+(3);sign = - sign;(4);}

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。[说明]下面程序实现十进制向其它进制的转换。[C++程序]include"ioStream.h"include"math.h"includetypedef struct node {int data;node*next;}Node;Class Transform.{DUDlic:void Trans(int d,int i); //d为数字;i为进制void print();private:Node*top;};void Transform.:Trans(int d,int i){int m,n=0;Node*P;while(d>0){(1);d=d/i;p=new Node;if(!n){p->data=m;(2);(3);n++;}else{p->data=m;(4);(5);}}}void Transform.:print(){Node*P;while(top!=NULL){p=top;if(p->data>9)cout<<data+55;elsecout<<data;top=p->next;delete p;}}

阅读下列说明和流程图,将应填入(n)处的语句写在对应栏内。【说明】下列流程图用泰勒(Taylor)展开式y=ex=1+x+x2/2!+x3/3!+…+xn/n!+…计算并打印ex的近似值,其中用ε(>0)表示误差要求。【流程图】

阅读以下说明,以及用C++在开发过程中所编写的程序代码,将应填入(n)处的字句写在对应栏内。【说明】在下面函数横线处填上适当的字句,使其输出结果为:构造函数.构造函数.1,25,6析构函数析构函数.【C++代码】include "iostream.h"class AA{ public;AA(int i,int j){A=i; B=j;cout<<"构造函数.\n";}~AA(){(1);}void print();private:int A, B;};void AA∷print(){cout<<A<<","<<B<<endl;}void main(){AA *a1, *a2;(2)=new AA(1, 2);a2=new AA(5, 6);(3);a2->print();(4) a1;(5) a2;}

阅读以下说明和Java程序,将应填入(n)处的字句写在对应栏内。[说明]下面程序实现十进制向其它进制的转换。[Java程序]ClasS Node{int data;Node next;}class Transform{private Node top;public void print(){Node p;while(top!=null){P=top;if(P.data>9)System.out.print((char)(P.data+55));elseSystem.out.print(p.data);top=p.next;}}public void Trans(int d,int i){//d为数字;i为进制int m;(1) n=false;Node p;while(d>0){(2);d=d/i;p=new Node();if( (3) ){p.data=m;(4);top=P;n=true;}else{p.data=m;(5);top=P;}}}}

阅读以下说明和C++抖程序,将应填入(n)处的字句写在答题纸的对应栏内。【说明】下面程序的功能是计算并输出某年某月的天数。【C++程序】include<iostream>using namespace std;(1) Month{Jan,Feb,Mar,Art,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec};class Date{public:Date(int year,Month m_month){(2) =year;if (m_month<Jan‖m_month>Dec) month=Jan;else month=m_month;};~Date(){};bool IsLeapYear(){return ((year%4==0 year%1001!=0)‖year%400==0);};int CaculateDays(){switch( (3) ){case Feb:{if( (4) )return29;e1Se return 28;}case Jan:case Mar:case May:case Jul:case AUg:case Oct:case Dec:retllrn 31;case Apr:case Jun:Case Sep:case Nov:roturu30;}};private:int year;Month month;};void main(){Date day(2000,Feb);tout<<day. (5) ();}

阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。【程序2.1说明】求所有满足如下条件的三位数:它除以11得的商等于它各位数字的平方和。例如 550,除以11商为50,50=52+52+02。【程序2.1】void main(){int i, j,n,s;for(i=100;i<=999;i++){n=i;j=n/11;s=0;while((1)){(2)n/=10;}if((3))printf("%d\t",i);}}【程序2.2说明】本程序输入一字符串,将其中的大写字母改变成小写字母。【程序2.2】void main(){int i=0;char s[120];scanf("%s",s);while((4)){if((5))s[i]=s[i]- 'A'+'a';i++;}printf("%s\n",s);}

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

阅读下列程序说明和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);}}

阅读以下说明,回答问题1~2,将解答填入对应的解答栏内。[说明] 某程序的功能是输入三个正整数作为边长,判断三条边构成的三角形是否等边、等腰或是一般三角形。通过该程序的算法用等价类设计测试用例,检查逻辑覆盖标准。

阅读以下说明和流程图,将应填入(n)处的字句写在对应栏内。[说明]下面的流程图用于计算一个英文句子中最长单词的长度(即单词中字母个数)MAX。假设该英文句子中只含字母、空格和句点“.”,其中句点表示结尾,空格之间连续的字母串称为单词。[流程图]

●试题二阅读下列函数说明和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) 处的字句写在答题纸的对应栏内。

(a)智能网概念模型中分布功能平面模型如下图所示,请根据此图将应填入(n)处的 字句写在答题纸的对应栏内。

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

阅读下列说明和C++代码,回答问题,将解答填入答题纸的对应栏内。【说明】某航空公司的会员积分系统将其会员划分为:普卡 (Basic)、银卡(Silver)和金卡 (Gold) 三个等级。非会员 (NonMember) 可以申请成为普卡会员。会员的等级根据其一年内累积 的里程数进行调整。描述会员等级调整的状态图如图 5-1 所示。现采用状态 (State) 模式实现上述场景,得到如图 5-2 所示的类图。【问题1】(15分)阅读上述说明和C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。

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