首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中声明的DataList类,是一个用于表示数据表的类。DataList的重载运算符函数operator+,其功能是求当前数据表与另一个相同长度的数据表之和;即它返回一个数据表,其每
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中声明的DataList类,是一个用于表示数据表的类。DataList的重载运算符函数operator+,其功能是求当前数据表与另一个相同长度的数据表之和;即它返回一个数据表,其每
admin
2018-03-13
78
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中声明的DataList类,是一个用于表示数据表的类。DataList的重载运算符函数operator+,其功能是求当前数据表与另一个相同长度的数据表之和;即它返回一个数据表,其每个元素等于相应两个数据表对应元素之和。请编写这个operator+函数。程序的正确输出应该是:
两个数据表:
1,2,3,4,5,6
3,4,5,6,7,8
两个数据表之和:
4,6,8,10,12,14
要求:
补充编制的内容写在“//**********333**********”与“//**********666**********”之间,不得修改程序的其他部分。
注意:程序最后将结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件,并且在本程序中调用。
//DataList.h
#include
using namespace std;
class DataList{//数据表类
int len;
double * d;
public:
DataList(int len,double data[]
=NULL);
DataList(DataList&data);
int length()const{return
len;}
double getElement(int i)
const(return d
;}
DataList operator+(const
DataList&list)const;//两个数据表求和
void show()const;//显示数据表
};
void writeToFi le(char *,const
DataList&);
//main.cpp
#include"DataList.h"
DataList::DataList(int len,double data[]):fen(1en){
d=new double[len];
for(int i=0;i
d
=(data==NULL?0.0:data
);
}
DataList::DataList(DataList&data):len(data.len)(d=new double[len];
for(int i=0;i
d
=data.d
;
}
DataList DataList::operator+(const DataList&list)const{
//两个数据表求和
double * dd =new double
[1ist.length()];
//**********333**********
//**********666**********
return DataList(list.length(),dd);
}
void DataList::show()const{//显示数据表
for(int i=0;i
cout<
<<",";
cout<
}
int main(){
double s1[]={1,2,3,4,5,6};
double s2[]={3,4,5,6,7,8};
DataList listl(6,s1),list2(6,s2);//定义两个数据表对象
cout<<"两个数据表:"<
listl.show();
1ist2.show();
cout<
(1ist1+list2).show();
writeToFile ("",listl +1ist2);
return 0;
}
选项
答案
for(int i=0;i
解析
主要考查考生对重载运算符的掌握,题目要求对两个数据表求和。程序已经定义了动态数组dd,并已经分配好了空间,接下来只要运用循环语句完成元素相加并进行赋值即可。
转载请注明原文地址:https://kaotiyun.com/show/EVAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列对于软件测试的描述中正确的是()。
在面向对象方法中,属性与操作相似的一组对象称为______。
有以下类定义classPoint{public:Point{intx=0,inty=0){_x=x;_y=y;}voidMoveintxoff,intyoff){_x
下列程序的输出结果是#include<iostream>usingnamespacestd;intmain(){chara[]="Hello,World
若有定义:intk,*q;,则下列各选项中赋值表达式正确的是
下列选项中不属于软件工程3个要素的是()。
下面是复数类complex的定义,其中重载的运算符“+”的功能是返回一个新的复数对象,其实部等于两个操作对象实部之和,其虚部等于两个操作对象虚部之和;请补充完整。classcomplex{doublereal;//实部
在声明派生类时,如果不显式地给出继承方式,缺省的类继承方式是私有继承private。已知有如下类定义:classBase{protected:voidfun(){}};classD
随机试题
Afathersatathisdesklookingathismonthlybillsverycarefullywhenhisyoungsonrushedinandannounced."Dad,【C1】_
进行疾病三间分布综合描述的典型是
A.羧甲基淀粉钠B.碳酸氢钠C.硬脂酸镁D.乙基纤维素E.聚乙二醇可用作泡腾片润滑剂的是()。
关于风险的说法中,正确的是()。
【2014年上】下列选项中,不属于鲁迅作品中的人物形象的是()。
(华东师大2019)自2015年以来我国外汇储备规模持续下降,试分析其原因并给出相应的对策建议。
心理治疗的基本实施过程为_____________、_____________、_____________、_____________和_____________五个阶段。
在某一表单中设计一个“变色”按钮“Cmmand1”,单击该按钮将随机地改变表单的背景颜色,其代码如下:Left=96Height=37Width=121Caption=(67)Name=(68)PROCEDURE(69)Thisform.
WhichofthefollowingisNOTcorrect?
A、Shehadahighfever.B、Shewasingoodhealth.C、Shehascaughtacold.D、Thereissomethingwrongwithherheartandlungs.
最新回复
(
0
)