使用VC6打开考生文件夹下的工程proj3,其中包含主程序文件main.cpp和用户定义的头文件Array.h,整个程序包含有XArray类的定义和main主函数的定义。请把主程序文件中的XArray类的成员函数sum()的定义补充完整,补充的内容填写在"/./**********333**********"与"//**********666**********”两行之间。经修改后运行程序,得到的输出为: 10 d=43 注意:只允许在”//**********333**********"//**********666**********"两行之间填写内容,不允许修改其他任何地方的内容。//Array.h#includeiostream#includecstdlibusing namespace std;class XArray{//数组类 int*a; int size;public: XArray(int b[],int len):size(len)//构造函数 { if(size2){cout"参数不合适!"endl;exit(1);} a=new int[size]; for(int i=0;isize;i++)a[i]=b[i]; } int sum();//返回数组a[size]中的最大值与最小值之和 int length()const{return size;)//返回数组长度 ~XArray(){delete[]a;}};void writeToFile(const char*);//不用考虑此语句的作用//main.cpp#include"Array.h"//返回数组a[size]中的最大值与最小值之和int XArray::sum(){/补充函数体 //**********333********** //**********666**********}void main(){ int s1[10]={23,15,19,13,26,33,18,30,20,10}; XArray x(s1,10); int d=x.sum(); coutx.length()endl; cout"d="dendl; writeToFile("c:\\test\\");//不用考虑此语句的作用}
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,此工程包含有一个源程序文件proj2.cpp。其中定义了Base1类、Base2类和Derived类。 Bausel是一个抽象类,其类体中声明了纯虚函数Show。Base2类的构造函数负责动态分配一个字符数组,并将形参指向的字符串复制到该数组中,复制功能要求通过调用strcpy函数来实现。Derived类以公有继承方式继承Base1类,以私有继承方式继承Base2类。在Derived类的构造函数的成员初始化列表中调用Base类的构造函数。 请在程序中的横线处填写适当的代码,然后删除横线,以完成Base1、Base2和Derived类的功能。此程序的正确输出结果应为: I'm a derived class. 注意:只在指定位置编写适当代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。//proj2.cpp#includeiostream#includecstringusing namespace std;class Base1 {public://*********found********* 下列语句需要声明纯虚函数Show________;};class Base2{protected: char*_p, Base2(const char*s) { p=new char[strlen(s)+1];//*********found********* 下列语句将形参指向的字符串常量复制到该类的字符数组中_________;}~Base2(){delete[]_p;} }; //*********found********* Derived类公有继承Base1,私有继承Base2类 class Derived:________{ public: //*********found********* 以下构造函数调用Base2类构造函数 Derived(const char *s):__________ { } void Show() {cout_pendl;} }; int main() { Base1*pb=new Derived ("I’m a derived class."); pb一Show(); delete pb; return 0; }
请打开考生文件夹下的解决方案文件proj3,其中声日月的DataList类,是一个用于表示数据表的类。sort成员函数的功能是将当前数据表中的元素升序排列。请编写这个sod函数。程序的正确输出应为: 排序前:7,1,3,11.6,9,12,10,8,4,5,2 排序后:1,2,3,4,5,6,7,8,9,10,11,12 要求: 补充编制的内容写在“//********333********”与“//********666********”两行之间。不得修改程序的其他部分。 注意:程序最后将结果输出到文件out.dat中。输出函数writeToFile已经编泽为obj文件,并且在本程序调用。//DataList.h#includeiostreamusing namespace std;class DataList { //数据表类 int len ; double *d;public: DataList(int len,double data[]=NULL); ~DataList(){delete[]d;) int length()const{return 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(len){ d:new double[len]; for(int i=0;ilen ; i++) d[i]=(data==NULL?0.0:data[i]);}void DataLi st::sort(){//数据表排序//*********333*********//*********666*********}void DataList::show()const{//显示数据表 for(int i=0;ilen-1;i++)coutd[i]","; coutd[len-1]endl ;}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(); coutendl"排序后:"; list.show(); writeToFile(" ",list); return 0;}
使用VC6打开考生文件夹下的源程序文件modi1.cpp,但该程序运行时有错,请改正程序中的错误,使程序输出的结果为: m=-10 n=-10 p=0 q=-10 z=A 注意:错误的语句在//******error******的下面,修改该语句即可。1 #include2 void main()3 {4 double m=10;5 float n=10;6 bool p=1;7 int q=1 0,8 char z='a';9 m=-m;10 //******error******11 n=-n;12 //******error******13 p=-P;14 //******error******15 q=-q,16 z=z-32;17 cout18 cout19 cout20 cout21 cout22 return;23 }
请使用VC6或使用【答题】菜单打开考生文件夹projl下的工程proj1。该工程中包含程序文件main.cpp,其中有类CDate(“日期”)和主函数main的定义。程序中位于每个“//ERROR****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: 原日期:2005—9—25 更新后的日期:2006—4—1 注意:只修改每个“//ERROR****found****”下的那一行,不要改动程序中的其他内容。#includeiostream#includecstdlibusing namespace std;class CDate//日期类{//ERROR******found******protected: CDate(){}; CDate(int d,int m,int y) {//ERROR******found****** SetDate(int day=d,int month=m,int year=y); }; void Display();//显示日期 void SetDate(int day,int month,int year)//设置日期 {m_nDay=day;m_nMonth=month;m_nYear=year;}private: int m_nDay;//日 int m_nNonth;//月 int m_nYear;//年};void CDate::Display()//显示日期{//ERROR******found****** coutm_nDay"-"m_nNonth"-"m_nYear; coutendl;}int main(){ CDate d(25,9,2005);//调用构造函数初始化日期 cout"原日期:"; d.Display(); d.SetDate(1,4,2006);//调用成员函数重新设置日期cout"更新后的日期:"; d.Display();return 0;}
C++中“<<”是一个( )符号
