下列说法中错误的是( )。
以下程序设计功能是:将结构体变量time 中的内容写到文件中。
#include <iostream>
using namespace std;
struct date
{
int year;
int month;
int day;
}
int main ( )
{
date time = { 2005, 1, 1 };
ofstream outdate;
outdate.open( "d:\\date.txt", ios :: binary );
outdate.write(____________, sizeof( tt ) );
outdate.close();
return 0;
}
则程序中空白处应该填入的语句为【 】。
使用VC6打开考生文件夹下的工程test21_3,此工程包含一个源程序文件test21_3.cpp,其中定义了用于表示长方形的类CRectangle,但类CRectangle的定义并不完整。请按要求完成下列操作,将类CRectangle的定义补充完整。
(1)定义CRectangle的构造函数,函数含参数dx,dy,da和db,它们都是double型的数据,请将类数据成员x,y, a和b初始化,并输出“CRectangle Constructed.”(另起一行输出该文字)。请在注释“//**1**之后添加适当的语句。
(2)完成类CRectangle的成员函数getperimeter()的定义,将以a和b为边的矩形周长的值返回,请在注释“//**2**”之后添加适当的语句。
(3)完成类CRectangle的成员函数getarea()的定义,将以a和b为边的矩形面积的值返回,请在注释“//**3**”之后添加适当的语句。
(4)完成类CRectangle的友元函数friend double dist(CRectangle& rt)的定义,先定义两个double型的临时变量tx和ty,然后将参数对象rt的数据成员x与a的一半相加,y与b的一半相加,分别赋值给tx和ty,最后求出tx与ty的平方和的值之后将它的平方根返回,将请在注释“//**4**”之后添加适当的语句。
输出结果如下:
CRectangle Constructed.
Down_Left corner point is:(100,50)
a=1200,b=700
Perimeter of this rectangle is:3800
Area of this rectangle is:840000
The Distance is:806.226
CRectangle Constructed.
Down_Left corner point is:(200,150)
a=2000,b=800
Perimeter of this rectangle is:5600
Area of this rectangle is:1.6e+006
The Distance is:1320.04
CRectangle Destructed.
CRectangle Destructed.
注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。
源程序文件test21_3.cpp清单如下:
#include<iostream.h>
#include<math.h>
class CRectangle
{
private:
double x;
double y;
double a;
double b;
public:
CRectangle()
{
cout<<"\nCRectangle Constructed."<<endl;
}
CRectangle(double dx, double dy, double da, double db)
{
//**1**
a=da;
b=db;
cout<<"\nCRectangle Constructed."<<endl;
}
~CRectangle ( )
{
cout<<"CRectangle Destructed."<<endl;
}
void putxy(double dx, double dy){ x=dx; y=dy;}
void putab(double da, double db)( a=da; b=db;}
double getx(){ return x;}
double gety(){ return y;}
double geta(){ return a;}
double getb(){ return b;}
double getperimeter()
{
//**2**
}
double getarea()
{
//**3**
}
friend double dist(CRectangle& rt);
};
double dist(CRectangle& rt)
{
//**4**
ty=rt.y+rt.b/2.0;
return sqrt(tx*tx+ty*ty);
}
void main()
{
CRectangle rect;
rect.putxy(100.0, 50.0);
rect.putab(1200.0, 700.0);
cout<<"Down_Left corner point is: ("<<rect.getx() <<", "<<rect.gety()<<")" <<endl;
cout<<"a= "<<rect.geta()<<", b="<<rect.getb() <<endl;
cout<<"Perimeter of this rectangle is: "<<rect.getperimeter()<<endl;
cout<<"Area of this rectangle is:"<<rect.getarea()<<endl;
cout<<"
下列说法中错误的是( )。
下面的函数模板定义中错误的是( )。
有关构造函数的说法不正确的是( )。
软件需求分析阶段的工作,可以分为四个方面:需求获取,需求分析,编写需求规格说明书,以及
关系模型允许定义3类数据约束,下列不属于数据约束的是
while和do-while循环的主要区别是
建立一个有成员对象的派生类对象时,各构造函数体的执行次序为( )。
算法的空间复杂度是指
高级经济师考试试题精选练习(1)
高级经济师考试模拟练习题之单选题(1
高级经济师考试试题精选练习(2)
高级经济师考试试题精选练习(3)
高级经济师考试试题:经济法案例试题精
高级经济师考试模拟试题及答案
高级经济师考试试题及答案:单选练习题
高级经济师考试试题:经济法案例试题精
高级经济师考试模拟题及答案练习(1)
高级经济师考试模拟题及答案练习(2)