首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中声明的DataList类,是一个用于表示数据表的类。DataList的重载运算符函数operator+,其功能是求当前数据表与另一个相同长度的数据表之和;即它返回一个数据表,其每
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中声明的DataList类,是一个用于表示数据表的类。DataList的重载运算符函数operator+,其功能是求当前数据表与另一个相同长度的数据表之和;即它返回一个数据表,其每
admin
2020-06-29
115
问题
请使用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
#inc!udc<iostream>
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 writeToFile(char * ,const DataList&);
//main.cpp
#include"DataList.h"
DataList∷DataList(int len,double data[]):len(len){
d=new double[len];
for(int i=0;i<len;i++)
d
=(data==NULL?0.0:data
i);
}
DataList∷DataList(DataList&data):len(data.len){
d=new double[len];
for(int i=0;i<len;i++)
d
=data.d
;
}
DataList DataList∷operator+(const DataList&list)const{//两个数据表求和
double * dd=New double[list.length()];
//********333********
//********666********
return DataList(list.length(),dd);
}
void DataList∷show()const{//显示数据表
flor(int i=0;i<len-1;i++)
cout<<d
<<",";
cout<<d[len-1]<<end1;
}
int main(){
double s1[]={1,2,3,4,5,6};
double s2[]={3,4,5,6,7,8};
DataList list1(6,s1),list2(6,s2);//定义两个数据表对象
cout<<"两个数据表:"<<end1;
list1.show();
list2.show();
cout<<end1<<"两个数据表之和:"<<end1;
(list1+list2).show();
writeToFile(" ",list1+list2);
return 0;
}
选项
答案
for(int i=0;i<len;++i) //遍历对象list中的数组和d数组,把对应的值相加后放到数组dd中。 dd[i]=d[i]+list.d[i];
解析
主要考查考生对重载运算符的掌握,题目要求对两个数据表求和。程序已经定义了动态数组dd,并已经分配好了空间,接下来只要运用循环语句完成元素相加并进行赋值即可。
转载请注明原文地址:https://kaotiyun.com/show/8a8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
在数据库设计中,将E-R图转换为关系模式的过程属于()。
下列程序的输出结果为2,请将程序补充完整。#inelude<iostream.h>usingnamespacestd;classBase{public:______voidfun(){cout<<
有如下程序:#include<iostream>using namespace std;class A{public: static int a; void init(){a=1;} A(int a=2){init();a++;}};int A::a
下列程序的输出结果是【】。#include<iostream>usingnamespacestd;classA{inta;public:A():a(9){}virtu
对于浯句cout<<end1<<x;中的各个组成部分,下列叙述中错误的是()。
关于continue语句叙述不正确的是
下列关于成员函数特征的描述中,错误的是()。
检查软件产品是否符合需求定义的过程称为()。
随机试题
A、(2465)B、(2467)C、(3575)D、(3577)B自然连接要求被连接的两个关系有若干相同的属性名。本题R和S相同属性名是B。公共属性出现一次,把字段B中具有相同值的记录连接起来,所以结
根据《建设工程安全生产管理条例》,建筑施工企业的管理人员和作业人员每()应至少进行一次安全教育培训并考核合格。
律师工作报告是发行人律师对股份有限公司在发行准备阶段的审查工作依法作出的结论性意见。()
下列各项属于适应性现场培训程序的有()。
柏拉图在《理想国》中提出的四种美德是()。
下列选项中,属于狭义的法律适用的是()。
下面不属于软件需求分析阶段工作的是
Picasso’s______abilitywasapparentinhisearlyyouthwhenhestarteddrawingsketches.
Scientiststhinklaser(be)______oneofthemostusefultoolstoday.
Thispartistotestyourabilitytodopracticalwriting.Youarerequiredtowriteabusinessletteraccordingtothefollowin
最新回复
(
0
)