【分录题】定义类Block和类Demo,运行Demo的输出结果是()。 class Block{ {//代码1 System.out.prin
A、取值是-1,0,1,2中的一个
B、取值是0,1,2,3中的一个
C、取值是1,2,3,4中的一个
D、任意整数
【说明】
源程序中定义了Circle类与Money类,Circle类可对半径为r的圆进行周长与面积的计算,而Money类用于计算一圆形游泳池的造价。游泳池四周有原形过道,过道外围上栅栏,过道宽度为3米,根据键入的游泳池半径,每米栅栏价格及每平方米过道价格,即可计算出游泳池的造价。请按要求完成下列操作,将程序补充完整。
①定义符号常量PI(值为3.14159f)与WIDTH(值为3.00f),分别用于表示圆周率与过道的固定宽度。
②定义Circle类默认构造函数,把私有成员radius初始化为参数r的值。
③完成Money类默认构造函数的定义,把私有成员FencePrice(每米栅栏的价格)、ConcretePrice(每平方米过道的价格)初始化为参数f,c的值。
④完成Money类成员函数float Money::TotalMoney(float fencelen,float conarea)的定义,根据参数fencelen(栅栏的长度)和conarea(过道的面积),返回栅栏与过道的总造价。
注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。
源程序文件test4.cpp清单如下:
include<iostream.h>
(1)
class Circle
{
private:
float radius;
public:
(2)
float Circumference(){return 2 * P| * radius;}
float Area(){return P|*radius * radius;}
};
class Money
{
private:
float FencePrice;
float ConcretePrice;
public:
Money(float f,float c);
float Tota|Money(float fencelen, float conarea);
};
Money::Money(float f,float c)
{
(3)
}
float Money::Tota|Money(float fencelen, float conarea)
{
(4)
}
void main()
{
float radius, fence, concrete;
cout. setf(ios:: 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 () - Pool.
Area () ) );
cout << "The total money is RMB" << totalmoney << end|;
}
B、t->display();
C、p-> num = 10101;
D、(*p)-> display();
【说明】
在下面的C++代码中,类SalesTicket能够完成打印票据正文的功能,类HeadDec- orator与FootDecorator分别能够完成打印票据的台头和脚注的功能。
已知该程序运行后的输出结果如下所示,请填补该程序代码中的空缺。
这是票据的台头!
这是票据正文!
这是票据的脚注!
---------------
这是票据的台头!
这是票据的脚注!
【C++程序代码】
#include
using namespace std;
class SalesTicket {
public:
(1) printTicket() { cout $amp; 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 $amp; Decorator::printTicket();
}
};
class FootDecorator :public Decorator{
public:
FootDecorator(SalesTicket *t): (3)
void printTicket() {
Decorator::printTicket();
cout $amp; }
};
void main(void) {
SalesTicket t;
FootDecorator f(&t);
HeadDecorator h((4) );
h.printTicket();
cout $amp; FootDecorator a(NULL);
HeadDecorator b((5) );
b.printTicket();
}
下述程序中语句完全不正确的一组语句是() class automover { int wheels; float weight; public: void initialize(int, float); int get_wheels(); float get_weight(){return weight;} }; void automover::initialize(int in_wheels, float in_weight) { wheels=in_wheels; weight=in_weight;} int automover::get_wheels(void){ return wheels; } void main() { automover car; automover.initialize(4, 3000.0); //① car.wheels=4; //② car.weight=3000.0; //③ car.initialize(4, 3000.0); //④ cout<<"\nthe car has> <<" wheels."; ⑤ car weighs> <<" pounds."; ⑥ car has> <<" wheels."; ⑦ car weighs> <<" pounds."; ⑧ }> A、①、②、③、④、⑤
B、①、②、③、⑤、⑥
C、②、③、④、⑤、⑥
D、①、②、④、⑦、⑧
为了保护您的账号安全,请在“简答题”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!