请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中声明的DataList类,是一个用于表示数据表的类。DataList的重载运算符函数0perator+,其功能是求当前数据表与另一个相同长度的数据表之和;即它返回一个数据表,其每个元素等于相应两个数据表对应元素之和。请编写这个operator+函数。程序的正确输出应该是: 两个数据表: 1,2,3,4,5,6 3,4,5,6,7,8 两个数据表之和: 4,6,8,10,12,14 要求: 补充编制的内容写在“//********333********”与“//********666********”之间,不得修改程序 的其他部分。 注意:程序最后将结果输出到文件。ut.dat中。输出函数writeToFile已经编译为。bj文件,并且在本程序中调用。 //DataList.h inClude<iostream> using namespaCe std; ClaSS DataList{//数据表类 intfen; double*d; publiC: DataList(int len,double data[]=NULL); DataList(DataList&data); int lengthConst{retum len;} double getElement(int i)Constt return d[i];} DataList operator+(Const DataList&list)Const;//两个数据表求和 void showConst;//显示数据表 }; void writeToFile(Char$,Const DataList&); //main.Cpp inClude”DataList.h” DataList::DataList(int len,double data[]):len(ien){ d=new double[1en]; for(int i=0;i<len;i++) d㈨i=(data==NULL?0.0:data[i]); } DataList::DataList(DataList&data):len(data.1en){ d=new double[1en]; for(int i=0;i<len;i++) d[i]=data.d[i]; DataList DataList::0perator+(Con8t DataList&list,)Const{//两个数据表求和 double*dd=new double[1ist.1ensth]; //********333******** //********666******** return DataList(1ist.1ength,dd); } void DataList::showConst{//显示数据表 fr(int。i=0;i<len-1;i++) eout<<d[i]<<”,”; Cout<<d[1en-1]<<endl; int main{ double sl[]={1,2,3,4,5,6}; double s2[]={3,4,5,6,7,8}; DataList list1(6,sl),list2(6,s2);//定义两个数据表对象 eout<<”两个数据表:”<<endl: listl.show: list2.show; eout<<endl<<”两个数据表之和:”<<endl: (1istl+list2).show; writeToFile(””,listl+list2); return 0:
第1题:
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehiele类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将Vehicle作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:
80
150
100
1
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
include<iostream.h>
class vehicle
{
private:
int MaxSpeed;
int Weight;
public:
//*************found************
vehicle(int maxspeed,int weight):——
~vehicle{};
int getMaxSpeed{return MaxSpeed;}
int getWeight{retum Weight;}
};
//****************found************
class bicycle:——public vehicle
{
private:
int Height;
public:
bicycle(int maxspeed,int weight,int height):vehicle(maxspeed,weight),Height(height){}
int getHeight{retum Height;};
};
//*******************found**************
class motorcar:——public vehicle
{
private:
int SeatNum;
public:
motorcar(int maxspeed。int weight,int seatnum):vehicle(maxspeed,weight),SeatNum(seatnum){}
int getSeatNum{return SeatNum;};
};
//*****************found***************
class motorcycle:——
{
public:
motorcycle(int maxspeed,int weight,int height):vehicle(maxspeed,weight),bicycle(maxspeed,weight,
height),motorcar(maxspeed,weight,1){}
};
void main
{
motorcycle a(80,150,100);
cout<<a.getMaxSpeed<<endl;
cout<<a.getWeight<<endl;
cout<<a.getHeight<<endl;
cout<<a.getSeatNum<<endl;
}
(1)MaxSpeed(maxspeed),Weight(weight){f;
(2)virtual
(3)virtua1
(4)public bicycle,public motorcar
第2题:
请使用【答题】菜单命令或直接用VC6打开考生文件夹下的工程prog3,其中声明了ValArray类,该类在内部维护一个动态分配的整型数组。ValArray类的复制构造函数应实现对象的深层复制。请编写ValArray类的复制构造函数。在main函数中给出了一组测试数据,此种情况下程序的输出应该是: ValArray vl={1,2,3,4,5} ValArray v2={1,2,3,4,5} 要求: 补充编制的内容写在“//*********333*********”与“//*********666*********”之间,不得修改程序的其他部分。 注意:程序最后将结果输出到文件out.dat中。输出函数write To File已经编译为boj文件,并且在本程序中调用。 //ValArray.h include<iostream> using namespace std; class ValArray{ int *v: int size; public: ValArray(const int * P,int n):size(n) { v=new int[size]; for(int i=0;i<size;i++) v[i]=P[i];
size=othe].size;
v=liew int[size]:
for(int i=0;i<size;i++)
setAtTay(i,other.v[ij);
第3题:
首先打开考生文件夹下的数据库stsc,然后使用表单向导制作一个表单,要求选择student表中所有字段,表单样式为阴影式,按钮类型为图片按钮,排序字段选择学号(升序),表单标题为“学生信息数据输入维护”,最后将表单存放在考生文件夹中,表单文件名为st_form。
(2)在考生文件夹下有一个数据库stsc,其中数据库表student存放学生信息,使用菜单设计器制作一个名为smenu1的菜单,菜单包括“数据维护”和“文件”两个菜单栏。每个菜单栏都包括一个子菜单。菜单结构如下;
数据维护
数据表格式输入
文件
退出
其中,数据表格式输入菜单项对应的过程包括下列4条命令:打开数据库stsc的命令,打开表student的命令,BROWSE命令,关闭数据库的命令。
退出菜单项对应的命令为SET SYSMENU TO DEFAULT,用于返回到系统菜单。
第4题:
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中声明的CDeepCopy是一个用于表示矩阵的类。请编写这个类的赋值运算符成员函数0perator=,以实现深层复制。 要求: 补充编制的内容写在“//************333************”与“//****************666*************”之间。不得修改程序的其他部分。 注意:程序最后将结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件,并且在本程序中调用。 //CDeepCopy.h include <iostream> include<string> using namespace std; class CDeepCopy { public: int n;//动态数组的元素个数 int *p;//动态数组首地址 CDeepCopy(int); ~CDeepCopy; CDeepCopy&operator=(const CDeepCopy&r);//赋值运算符函数 }; void writeToFile(char}); //main.cpp include”CDeepCopy.h” CDeepCopy::一CDeepCopy{delete[]P;} CDeepCopy::CDeepCopy(int k){n=k;p=new int[n];}//构造函数实现 CDeepCopy&CDeepCopy::0perator=(const CDeepCopy&r)//赋值运算符函数实现 { //***********333********* //***********666*********** } int main { CDeepCopy a(2),d(3); a.p[O]=1;d.p[O]=666;//对象a,d数组元素的赋值 { CDeepCopy b(3);//调用赋值运算符函数 a.p[O]=88;b=a; cout<<b.p[O];//显示内层局部对象的数组元素 } cout<<d.p[O];//显示d数组元素a.p[O]的值 cout<<”d fade away;\n”; cout<<a.p[O];//显示a数组元素a.p[O]的值 writeToFile(””); return 0; }
lq=r.n;//把对象r字符长度赋值给n
delete[]P;//删除动态数组P
P=new int[n];//给动态数组P分配空间为n
for(int i=0;i<n;i++)
//遍历对象r中的数组P
P[i]=r.P[i];//把r.P[i]赋值给P[i]
retum*this://返回被赋值的对象
第5题:
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件 main.cpp,其中有类CPolygon(“多边形”)、CRectangle(“矩形”)、CTriangle(“三角形”)的定义。请在横线处填写适当的代码并删除横线,以实现上述类定义。该程序的正确输出结果应为: 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。 include<lostream> {tout<<——<<endl;} class CRectangle:public CPolygon{ CRe&angle(int w,int h):width(w),height(h){} 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=&rect; ppoly2=&trgl; ppolyl->printarea; ppoly2->printarea; retun 0;
(1)virtual int area(void)=0;
(2)area
(3)length*height
(4)CPolygon