2014年3月计算机二级C++简单应用题及答案(网友版)

牛课网 考试宝典 更新时间:14-04-11

三、简单应用题(24分)

请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件 main.cpp,其中有类CPolygon(“多边形”)、CRectangle(“矩形”)、CTriangle(“三角形”)的定义。请在横线处填写适当的代码并删除横线,以实现上述类定义。该程序的正确输出结果应为: 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。 #include

{tout<<——< int area(void){return(width *height);}

class CTriangle:public CPolygon{

int length;//三角形一边长 int height;//该边上的高

public:

CTriangle(int l,int h):length(1),height(h){}

//*********found*********

int area(void){return(——)/2;}

};

int main(){

CRectangle rect(4,5); CTriangle trgl(4,5);

//*********found********* ______ *ppolyl,* ppoly2; ppolyl=▭

ppoly2=&trgl;

ppolyl->printarea(); ppoly2->printarea(); retun 0;

四、综合应用题(18分)

43、请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中声明的DataList类,是一个用于表示数据表的类。s0rt成员函数的功能是将当前数据表中的元素升序排列。请编写这个sort函数。程序的正确输出应为: .

排序前:7,1,3,11,6,9,12,10,8,4,5,2 排序后:l,2,3,4,5,6,7,8,9,10,11,12

要求:

补充编制的内容写在“//********33********”与“//********666********”两行之问。不得修

改程序的其他部分。

注意:程序最后将结果输出到文件。ut.dat中。输出函数writeToFile已经编译为。obj文件,并且在本程序

调用。

//DataList.h

#inClude using namespaCe std; Class DataList{//数据表类

int len;

double*d: publiC:

DataList(int len,double data[]=NULL);。DataList(){delete[]d;}

int length(Constt retum len;}//数据表长度(即数据元素的个数) double getElement(int i)Const{return d[i];}

void sort();//数据表排序

void show()Const;//显示数据表}.

void writeToFile(Char*,Const DataList&).//main.Cpp

#inClude”DataList.h”

DataList::DataList(int len,double data[]):len(1en){ d=new double[1en];

for(int i_0;i d[i]=(data==NULL?0.0:data[i]);

}

void DataList::sort(){//数据表排序//********333********

//********666********}

void DataList::show()Const{//显示数据表

for(int i=0;i }

int main(){

double S[]={7,1,3,11,6,9,12,10,8,4,5,2}; DataList list(12,S);

Cout<<”排序前:”; list.show();

list.sort();

Cout< writeToFile(””,list); return 0;

点击下载:全新升级版计算机等级考试宝典题库

编辑推荐:

2014年3月计算机等级《一级MSOffice》考试押密题汇总 

2014年计算机等级二级考试(JAVA)冲刺试题汇总

2014年3月计算机等级《二级C++》考试冲试第一套试题汇总

考试宝典安装说明

宝典适用于手机、电脑、平板,您可安装客户端或在浏览器使用。

电脑版

手机版

网页版

考试宝典咨询
服务热线

TEL:029-88699698