试卷详情
-
二级C++机试-132
-
[简答题]请使用“答题”菜单或使用VC6打开考生文件夹proj2下的工程proj2,其中包含抽象类Shape的声明,以及在此基础上派生出的类Rectangle和Circle的声明,二者分别是计算面积的函数GetArea( )和计算对象周长的函数GetPerim( )。程序中位于每个//************found************下的语句行有错,请加以改正。改正后程序的输出应该是:
The area of the Circle is 78.5
The perimeter of the Circle is 31.4
The area of the Rectangle is 24
The perimeter of the Rectangle is 20
注意:只能在画线处填写适当的代码,不要改动程序中的其他内容,也不能删除或移动“//************found************”。
//源程序
#include<iostream>
using namespace std;
class Shape
public:
Shape( )
~Shape( )
//************found************
______float GetArea( )=0;
//************found************
______float GetPerim( )=0;
;
class Circle: public Shape
public:
Circle(float radius):itsRadius(radius)
~Circle( )
float CetArea( ) return 3.14 *itsRadius *itsRadius;
float CetPerim( )return 6.28 *itsRadius;
private:
float itsRadius:
;
class Rectangle: public Shape
public:
//**
-
[简答题]请使用“答题”菜单或使用VC6打开考生文件夹proj2下的工程proj2,其中声明了CDeep-Copy类,它是一个用于表示动态数组的类。请编写其中的复制构造函数。
要求:补充编制的内容写在//********333********与//********666********两行之间,不得修改程序的其他部分。
注意:程序最后已经将结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件,并且在本程序中调用。
//源程序
#include"CDeepCopy.h"
CDeepCopy::~CDeepCopy( )delete[]p;
CDeepCopy::CDeepCopy(int k)n=k; p=new int[n]; //构造函数实现
CDeepCopy::CDeepCopy(const CDeepCopy&r) //复制构造函数
//********333********
//********666********
int main( )
CDeepCopy a(2),d(3);
a.p[0]=1; d.p[0]=666; //对象a、d数组元素的赋值
CDeepCopy b(a);
a.p[0]=88;
cout<<b.p[0]; //显示内层局部对象的数组元素
cout<<d.[0]; //显示d数组元素a.[0]的值
cout<<"d fade away; /n";cout<<a.p[0]; //显示a数组元素a.p[0]的值
//writeToFile("K://bl0//61000101//");
return 0:
-
[多项选择]请使用“答题”菜单或使用VC6打开考生文件夹proj1下的工程proj1。程序中位于每个//ERROR************found************下的语句行有错,请加以改正。改正后程序的输出应该是:
Name:Smith Age:21 ID:99999 CourseNum:12 Record:970
注意:只能修改每个//ERROR************found************下的那一行,不要改动程序中的其他内容。
//源程序
#include<iostream>
using namespace std;
class StudentInfo
protected:
//ERROR************found************
char Name[];
int Age;
int ID;
int CourseNum;
float Record:
public:
//ERROR************found************
void StudentInfo(char*name, int age, int ID, int courseNum,float record);
//ERROR************found************
void~StudentInfo( )delete[]Name;
float AverageRecord( )
return Record/CourseNum:
void show( ) consL;
;
StudentInfo::StudentInfo(char*name, int age, int ID, int courseNum, float record)
Name=strdup(name);