题目内容

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

查看答案
更多问题

Window98所支持的设备驱动程序主要有三种:实模式DOS驱动程序、______和保护模式Windows驱动程序。

请补充main函数,该函数的功能是:计算三名学生学科的平均成绩。
例如,当score[N][M]={{83.5,82,86,65,67},{80,91.5,84, 99,95},{90,95,86,95,97}时,五门学科的平均分为:84.5 89.5 85.3 86.3 86.3。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio, h>
define N 3
define M 5
main ()
{
int i,j;
static float score [N] [M]= { {83.5, 82,86,
65,67}, {80,91.5,84,99,95},
{90, 95, 86, 95, 97} };
static float bb[N];
clrscr ();
for (i=0; i<M; i++)
bb[i]=0.0;
for(i=0;i<【 】;i++)
{
for(j=0;j<【 】;j++)
bb [j]+=score [i] [j];
}
for (i=0; i<M; i++)
print f (" \nsubject%d\taverage=%5.1 f",
i+1,【 】);
return 0;
}

德国心理学家艾宾浩斯的遗忘曲线表明:遗忘的进程是______,遗忘的速度是______。

对于财务现金流量不能全面、真实地反映其经济价值的项目,应进行经济影响分析。()

答案查题题库