计算机类
公务员类
工程类
语言类
金融会计类
计算机类
医学类
研究生类
专业技术资格
职业技能资格
学历类
党建思政类
计算机等级考试(NCRE)
全国计算机应用水平考试(NIT)
计算机软件水平考试
计算机等级考试(NCRE)
全国高校计算机等级考试CCT
行业认证
信息素养
计算机等级考试二级
计算机等级考试一级
网络工程师(计算机等级考试四级)
计算机等级考试二级
数据库工程师(计算机等级考试四级)
计算机等级考试三级
信息安全工程师(计算机等级考试四级)
嵌入式系统开发工程师(计算机等级考试四级)
软件测试工程师(计算机等级考试四级)
C++语言程序设计
Python语言程序设计
WPS Office高级应用与设计
C语言程序设计
C++语言程序设计
Java语言程序设计
Visual Basic语言程序设计
Web程序设计
Access数据库程序设计
MySQL数据库程序设计
Visual FoxPro数据库程序设计
办公软件高级应用
问答题使用VC6打开下的源程序文件modi2.cpp。阅读下列函数说明和代码,完成空出部分程序。函数fun(int*arr,intn)的功能是将指定的有序数组压缩成各元素互不相同的有序数组,即相同数只保留一个,多余的被删除。并返回互不相同的元素的个数。注意:不能修改程序的其他部分,只能修改fun()函数。#include<iostream>intfun(int*a,intn){}voidmain(){intA[]={6,6,5,4,4,3,3,2,1};intj=fun(A,sizeof(A)/sizeof(int));for(inti=0;i<j;i++){std::coutA[i]"";}std::coutstd::endl;return;}
进入题库练习
问答题使用VC6打开考生文件夹下的源程序文件modi1.cpp,但该程序运行时有错,请改正程序中的错误,使程序输出的结果为: 10 6 30 2 2 注意:错误的语句在//********error********的下面,修改该语句即可。#include<iostream.h>class CMyClass {private: int number; int Add(int i) { return number+=i; } int Sub(int i) { return number-=i; } int Mul(int i) { return number*=i; } int Div(int i) { if(i!=0) { return number/=i; } else return number; } //********error******** typedef int(FUNC)(int); //********error******** FUNC func[];public: CMyClass() { func[0]=CMyClass::Add; func[1]=CMyClass::Sub; func[2]=CMyClass::Mul; func[3]=CMyClass::Div; number=0; } int CallFunction(int i,int j) { //********error******** return(func[i])(j); }};Void main(){ CMyClass myobj; cout<<myobj.CallFunction(0,10)<<endl; cout<<myobj.CallFunction(1,4)<<endl; cout<<myobj.CallFunction(2,5)<<endlj cout<<myobj.CallFunction(3,15)<<endl; cout<<myobj.CallFunction(3,0)<<endl;}
进入题库练习
问答题综合应用题 使用VC6打开考生文件夹下的工程kt15_3。此工程包含一个kt15_3.cpp,其中定义了 类A、A1和A2,其中A1类由A类公有派生,A2类由A1类公有派生。上述三个类的定义并不完整,请按要求完成下列操作,将程序补充完整。 (1)定义类A的构造函数,该构造函数有一个整型的参数x,在构造函数中请将x赋值给数据成员a。请在注释“//**1**”之后添加适当的语句。 (2)定义类A1的构造函数,该构造函数有两个整型参数x和y,在构造函数中请将x赋值给数据成员b,将y作为基类A构造函数的参数值传入。请在注释“//**2**”后添加适当的语句。 (3)定义类A2的构造函数,该构造函数有三个整型的参数x,y和z,在构造函数中请将x赋值给数据成员c,将y和z分别赋值给基类A1构造函数的参数x和y。请在注释“//**3**”之后添加适当的语句。 (4)完成类A2的成员函数show的定义,该函数调用基类成员函数,输出基类数据成员a和b及类A2自身的数据成员c的值,上述三个值在输出时以空格隔开。请在注释“//**4**”之后添加适当的语句。 注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。 程序输出结果如下: 9 6 962 源程序文件kt15_3.cpp清单如下: #include classA { inta; public: //**1** intgeta(){returna;} }; classA1:publicA { intb; public: //**2** intgetb(){returnb;} }; classA2:publicA1 { intc; public: //**3** voidshow() { //**4** } }; voidmain() { A2a(2,6,9); cout<
进入题库练习
问答题请编写一个函数display(),该函数要求用户先输入一字符串,然后在屏幕上再输出该字符串(假设该字符串长度小于 100)。注意:部分源程序已存在文件test35_2.cpp中, 请勿修改主函数main和其他函数中的任何内容,仅在函数display()的花括号中填写若干语句。 如输入abc,输出结果如下: please input string: abe abc Press any key to continue 文件 test35_2.cpp 的内容如下: #include <iostream.h> #include <conio.h> void display() void main( ) cout display ( );
进入题库练习
问答题使用VC6打开考生文件夹下的源程序文件modi3.cpp。请完成以下部分,实现在屏幕上输出为: TestClass3 TestClass2 这个程序需要修改的部分,请按照以下部分实现。 (1)类TestClass0不能被实例化,请定义一个纯虚函数print,在注释//********1********水后添加适当的语句。 (2)类TestClass1私有虚继承类TestClass0,请在注释//********2********后添加适当的语句。 (3)类TestClass2公有继承类TestClass0,请在注释//********3********后添加适当的语句。 (4)类TestClass3公有继承类TestClass2与TestClass1,请在注释//********4********后添加适当的语句。 注意:仅在函数指定位置添加语句,请勿改动主函数main与其他函数中的任何内容。#include<iostream.h>Class TestClass0{ //********1********};//********2********Class Testelass1:{public: void print() { cout<<"TestClass1"<<endl; }};//********3********Class TestClass2:{public: void print() { cout<<"TestClass2"<<endl; }};//********4********Class TestClass3:{public: void print() { cout<<"TestClass3"<<endl; } }; void main() { TestClass3 c3; TestClass2 c2; c3.print(); c2.print(); return;}
进入题库练习
问答题请使用VC6或使用[答题]菜单打开考生文件夹prog2下的工程prog2。此工程中包含一个程序文件main.cpp,其中有“部门”类Department和“职工”类Staff的定义,还有主函数main的定义。在主函数中定义了两个“职工”对象,他们属于同一部门。程序展示,当该部门改换办公室后,这两个人的办公室也同时得到改变。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: 改换办公室前: 职工号:0789 姓名:张三 部门:人事处 办公室:521 职工号:0513 姓名:李四 部门:人事处 办公室:521 改换办公室后: 职工号:0789 姓名:张三 部门:人事处 办公室:311 职工号:0513 姓名:李四 部门:人事处 办公室:311 注意:只在横线处填写适当的代码,不要改动程序中的其他内容。 #include <iostream> using namespace std; class Department{ //"部门"类 public: Department (const char * name,const char * office){ strcpy(this ->name, name); //********** found********** ______ } oonst char * getName () const{ return name; } //返回部门名称 //********** found********** const char * getOffice ()const{______} //返回办公室房号 void changeOfficeTo(const char * office) { //改换为指定房号的另一个办公室 strcpy(this ->office, office); } private: char name[20]; //部门名称 char office[20]; //部门所在办公室记号 }; class Staff{ //"职工"类 public: //**********found********** Staff (const char * my id, constchar * my_name, Department ______{ strcpy (this -> staff_id, my_id); strcpy (this -> name, my_name ); } const char * getID () const{ returnstaff_id; } const char * getName () const{ return name;} Department getDepartment () const{return dept;} private: char staff_id[10]; //职工号 char name[20]; //姓名 Department //所在部门 }; void showStaff(Staff cout << "姓名:" <<staff.getName () <<""; cout <<"部门:" <<staff.getDepartmerit ().getName () <<""; cout <<"办公室:" <<staff, getDepartment(). getOffice() <<endl; } int main(){ Department dept("人事处", "521"); Staff Zhang ("0789", "张三", dept), Li("0513", "李四", dept); cout <<"改换办公室前:" <<endl; showStaff(Zhang); showStaff(Li); //人事处办公室由521搬到311 //**********found********** ______ cout <<"改换办公室后:" <<endl; showStaff(Zhang); showStaff(Li); return 0; }
进入题库练习
问答题请使用菜单命令或直接使用VC6打开 下的工程proj1,其中有“MP3播放器”类MP3Player和主函数main的定义。程序中位于每个//ERROR **********found**********下的语句行有错误,请加以更正。更正后程序的输出应该是: 天籁-1 黑色 注意:只能修改每个//ERROR ***********found***********下的那一行,不要改动程序中的其他内容。 #include<iostream> #include<iostream> using namespace std; class MP3Player { //“MP3播放器”类 char*type;//型号 char*color;//颜色 public: //ERROR *********found********* MP3Player(const char*ty=NULL, const char*co) { //ERROR *********found********* if(ty=NULL) type=NULL; else{ type=new ehar[stden(ty)+1]; strcpy(type, ty); } if(co==NULL) color=NULL; else{ color=new char[strlen(co)+1]; strcpy(color, co); } } ~MP3Player(){ if(type) delete[]type; //ERROR *********found********* if(color) delete color; } const char *getType()const {return type;} const char *getColor()const {return color;} }; int main(){ MP3Piayer myplayer(“天籁-1”, “黑色”); cout<<myplayer.getType()<<endl; cout<<myplayer.getColor()<<endl; return 0; }
进入题库练习
问答题使用VC++6.0打开 下的源程序文件1.cpp,该程序运行时有错,请改正错误,使得程序正确执行,并且输出以下语句: TC1: 0 TC2 注意:不要改动main函数,不能增加或删除行,也不能更改程序的结构,错误的语句在//******error******的下面。 试题程序: #include<iostream.h> struct TC1 { TC1(int i=0) { m_i=i; } void print() { cout<<"TC1:"<<m_i<<endl; } int m_i; }; class TC2 { public: TC2() { } void print() { cout<<"TC2"<<endl; } //********error******** private: ~TC2() { } }; int main() { //********error******** TC1 obj1(); //********error******** TC2 obj2(); obj1.print(); obj2.print(); return 0; }
进入题库练习
问答题请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程pmj1,此工程包含一个源程序文件proj1.epp。文件中将表示数组元素个数的常量Size定义为4,并用int类型对类模板进行了实例化。文件中位于每个注释“//ERROR ****found*****”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: 1 2 3 4 注意:模板参数名用T。只修改注释“//ERROR*********found*********”的下一行语句,不要改动程序中的其他内容。//proj1.cpp#include<iostream>using namespace std;//将数组元素个数Size定义为4//ERROR********found********const int Size;template<typename T>class MyClass{public: MyClass(T*P) { for(int i=0;i<Size;i++) array[i]=p[i]; } void Print();private: T array[Size]; }; template<typename T> //ERROR********found******** void MyClass::Print() { for(int i=0;i<Size;i++) cout<<array[i]<<’\t’; } int main() { int intArray[Size]={1,2,3,4}; //ERROR********found******** MyClass<double>obj(intArray); obj.Print(); cout<<endl; return 0; }
进入题库练习
问答题写出下列程序的运行结果。 #include <iostream> using namespace std; class Person { public: Person() {cout<<"Constructor of Person"<<endl; } ~Person() {cout<<"Destructor of Person"<<endl; } }; class Student: public Person { public: Student() {cout<<"Constructor of Student" <<endl;} ~Student() {cout<<"Destructor of Student"<<endl; } }; class Teacher: public Person { public: Teacher() {cout<<"Constructor of Teacher"<<endl;} ~Teacher() {cout<<"Destructor of Teacher"<<endl; } }; int main() { Student s; Teacher t; return0; }
进入题库练习
问答题使用VC6打开考生文件夹下的源程序文件modi3.cpp,其中定义了用于表示日期的类Date,但类Date的定义并不完整,按要求完成下列操作,将类的定义补充完整。 (1)定义私有成员变量year、month、day,分别表示年、月、日,类型为int。请在注释//********1********后添加适当的语句。 (2)完成构造函数,分别给year、month、day赋值,请在注释//********2********后添加适当的语句。 (3)完成重载符号“+=”的定义,请在注释/********3********后添加适当的语句。 (4)完成print()打印函数,如2008年8月8日到屏幕和文件modi3.txt格式相同,请在注释//********4********后添加适当的语句。 注意:仅在函数指定位置添加语句,请勿改动主函数main与其他函数中的任何内容。#include<iostream.h>#include<fstream>#include<iomanip>#include<cmath>using namespace std;void WriteFile(int c){ ofstream out1; out1.open("modi3.txt",ios base::app); out1<<c<< ' '; out1.close(); } void WriteFile(char*str) { ofstream out1; out1.open("modi3.txt",ios base::app); out1<<str;out1.Close();}void ClearFile(){ ofstream out1; out1.open("modi3.txt");out1.Close();}class Date{public: Date(int y,int m,int d) { //********2******** } void print()const; //********3******** { month+=m; int i=month/12; int j=month%12; if(j==0) { year+=(i-1); month=12; } else { year+=i; month=j; } return *this; }private: //********1********};void Date::print()const{ //********4******** WriteFile(year); WriteFile("年"); WriteFile(month); WriteFile("月"); WriteFile(day); WriteFile("日");}int main(){ ClearFile(); Date oly day(2008,8,8); oly day+=3; oly day.print(); return 0;}
进入题库练习
问答题使用VC6打开考生文件夹下的源程序文件modi2.cpp。请完成以下两个函数: (1)fun1(int n1;求出n的阶乘,必须使用递归调用。 (2)fun2(int n);求出n的阶乘,不能使用递归调用。 如果n小于1则返回0。 注意:请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。#include<iostream.h>//必须使用递归int funl(int n){};//不能使用递归int fun2(int n){}void main(){ int i; cout<<"请输入一个整数:"<<endl; cin>>i; tout<<"输入数字的阶乘是:"<<fun1(i)<<endl; cout<<"输入数字的阶乘是:"<<fun2(i)<<endl, return; }
进入题库练习
问答题请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程proj1。程序中位于每个“//ERROR****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为:Name:Smith Age:21 ID:99999 CourseNum:12Record:970注意:只修改每个“//ERROR****found****”下的那一行,不要改动程序中的其他内容。#include<iostream>using namespace std;class Studentlnfo{protected://ERROR*********found*********char Name;int Age;int ID:int CourseNum;float Record;public:Studentlnfo(char*name,int Age,int ID,int courseNum,float record);//ERROR*********found*********void~Studentlnfo(){}float AverageRecord(){return Record/CourseNum;}void show()const{cout<<"Name:"<<Name<<"Age:"<<Age<<"ID:"<<ID<<"CoumeNum:"<<CourseNum<<"Record:"<<Record<<endl;}};//ERROR*********found*********Studentlnfo Studentlnfo(char*Name,int Age,int ID,int CourseNum.float Record){Name=name;Age=age;this->ID=ID;CourseNum=courseNum;Record=record;}int main(){Studentlnfo st("Smith",21,99999,12,970);st.show();return0;}
进入题库练习
问答题使用VC6打开考生文件夹下的源程序文件modi3.cpp,其中定义了用于表示雇员的Employee类,但类Employee的定义并不完整。请按要求完成下列操作,将类CEmployee的定义补充完成。 (1)定义私有数据成员name、street、city、zipcode和age分别用于表示姓名、街道、城市、邮编、年龄,除年龄是整型外其余都是char型的数据。请在注释∥********1********之后添加适当的语句。 (2)完成默认构造函数CEmployee的定义,使其把参数传递给私有数据成员name、street、city、zipcode和age。请在注释∥********2********之后添加适当的语句。 (3)完成成员函数alterName(char*newName)的定义。请在注释∥********3********之后添加适当的语句。 (4)完成成员函数IsEqual(char*ename)的定义,实现当name相等时返回真,否则为假的功能,请在注释∥********3********之后添加适当的语句。 注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。 #include #include #define MAXLEN 2 0 class CEmployee { private: ∥********1******** int age; public: CEmployee (char*newName, char *newStreet,char *newCt, char*newZp,int newAge); void alterName(char*newName); void display(); bool IsEqual(char*ename); }; CEmployee::CEmployee(char *newName,char *newStreet,char *newCt,char*newZp,int newAge) { ∥********2******** age=newAge; } void CEmployee::alterName(char *newName) { ∥********3******** } bool CEmployee::I sEqual (cha:*ename) { ∥********4******** } void CEmployee::display() { cout << name << “ ”
进入题库练习
问答题请使用VC6或使用[答题]菜单打开考生文件夹proj2下的工程proj2。此工程中包含一个源程序文件main.cpp,其中有类Quadritic、类Root及主函数main的定义。一个Quadritic对象表示一个形如ax2+bx+c的一元二次多项式。一个Root对象用于表示方程ax2+bx+c=0的一组根,它的数据成员num_of_roots有3种可能的值,即0、1和2,分别表示根的3种情况:无实根、有两个相同的实根和有两个不同的实根。请在横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为(注:输出中的X^2表示x2): 3X^2+4X+5=0.1 无实根 4.5X^2+6X+2=0.0 有两个相同的实根:-0.666667和-0.666667 0.5X^2+2X-3=0.0 有两个不同的实根:0.896805和-2.23014 注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。 #include <iostream> #include <iomanip> #include <cmath> using namespace std; class Root{ //一元二次方程的根 public: const double x1; //第一个根 const double x2; //第二个根 const int num of roots; //不同根的数量:0、1或2 //创建一个“无实根”的Root对象 Root(): x1 (0.0), x2 (0.0), num_of_roots (0) {} //创建一个“有两个相同的实根”的Root对象 Root (double root) : x1 (root), x2 (root), num_of_roots(1) {} //创建一个“有两个不同的实根”的Root对象 Root (double root1, double root2) //********** found********** :______{} void show () const { //显示根的信息 cout << "/t/t"; //********** found********** switch (______) { case 0: cout <<"无实根"; break; case 1: cout << "有两个相同的实根:" << x1<<" 和 " <<x2; break; default: cout << "有两个不同的实根:" << x1<<" 和 " <<x2; break; } } }; class Quadratic { //二次多项式 public: const double a, b, c; Quadratic (double aa, double bb, double cc) //构造函数 :a(aa), b(bb), c(cc) {} Quadratic (Quadratic } Quadratic sub (Quadratic x) const { //求两个多项式的差 return Quadratic(a-x.a, b-x.b, c-x.c); } double value (double x) const { //求二次多项式的值 return a* x* x+b* x+c; } Root root ()const{ //求一元二次方程的根 double delta=b* b-4* a* c; //计算判别式 //********** found********** if (delta<0.0)______; if (delta ==0.0) return Root ( -b/(2* a)); double sq = sqrt (delta); returnRoot((-b+sq)/(2* a), (-b-sq) / (2" a)); } void show() const{ //显示多项式 cout << endl << a << "X^2 " << showpos <<b << "X" << c << noshowpos; } void showFunction () { //显示一元二次方程 show (); cout <<" =0.0"; } }; int main () { Quadratic q1 (3.0, 4.0, 5.0), q2(4.5, 6.0, 2.0), q3 (q2. sub(q1)); q1.showFunction (); q1.root().show(); q2.showFunction (); q2.root ().show(); q3.showFunction (); q3.root ().show(); cout << endl; return 0; }
进入题库练习
问答题使用VC6打开考生文件夹下的源程序文件modil.cpp,该程序运行时有错误,请改正程序中的错误,使得程序运行后没有内存遗漏。可以在修改处增加或者删除一条语句。本程序完成输入两个字符串,分别存储到s1,s2中。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构,错误的语句在 ∥********error********的下面。 #include Void main() { char*s1; char s2[102 4]; cout<<“please input a string:”<
进入题库练习
问答题请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中声明的DataList类,是一个用于表示数据表的类。sort成员函数的功能是将当前数据表中的元素升序排列。请编写这个sort函数。程序的正确输出应为: 排序前: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 #include<iostream> using 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(1en){ d=new double[1en]; for(int i=0;i<len;i++) d[i]=(data==NULL?0.0:data[i]);}void DataList::sort(){//数据表排序//**********333**********//**********666**********}void DataList::show()const{//显示数据表 for(int i=0;i<len—1;i++)cout<<d[i]<<","; cout<<d[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(); cout<<endl<<"排序后:"; list.show(); writeToFile("",list); return 0;}
进入题库练习
问答题请使用“答题”菜单或使用VC6打开考生文件夹proj1下的工程proj1,此工程包含程序文件 main.cpp,其中有类Book(“书”)和主函数main的定义。程序中位于每个//ERROR************found************下的语句行有错,请加以改正。改正后程序的输出应该是: 书名:C++语言程序设计 总页数:299 已把"C++语言程序设计"翻页到第50页 已把“C++语言程序设计"翻页到第51页 已把书合上。 书是合上的。 已把"C++语言程序设计"翻页到第1页 注意:只能修改每个//ERROR************found************下的那一行,不要改动程序中的其他内容。 // 源程序 #include<iostream> using namespace std; class Book char*title; int num_pages; //页数 int cur_page; //当前打开页面的页码,0表示书未打开 public: Book(const char*theTitle,int pages):num_pages(pages) //ERROR************found************ title=new char[strlen(theTitle)]; strcpy(title,theTitle); cout<<endl<<"书名:"<<title<<"总页数:"<<num_pages; ~Book()delete[]title; //ERROR************found************ bool isOpen() const return num_pages!=0; //书打开时返回true,否则返回false int numOfPages() const return num_pages; //返回书的页数 int currentPage() const return cur_page; //返回打开页面的页码 void openAtPage(int page_no) //把书翻到指定页 cout<<endl; if(page_no<1 1|| page_no>num_pages) cout<<"无法翻到第"<<cur_page<<"页。"; close(); else cur_page=page_no; cout<<"已把" "<<ticle<<" "翻到第"<<cur_page<<"页"; void openAtPrevPage()openAtPage(cur_page-1);//把书翻到上一页 void openAtNextPage()openAtPage(cur_page+1);//把书翻到下一页 void close() //把书合上 cout<<endl; if(! isOpen())cout<<"书是合上的。"; else //ERROR************found************ num_pages=0; cout<<"已把书合上。"; couf<<endl; ; int main() Book book("C++语言程序设计",299); book.openAtPage(50); book.openAtNextPage(); book.close(); book.close(); book.openAtNextPage(); return 0:
进入题库练习
问答题请使用VC6或使用【答题】菜单打开 proj3下的工程文件proj3,其中该工程中包含定义了用于表示姓名的抽象类Name、表示“先名后姓”的姓名类Name1(名、姓之间用空格隔开)和表示“先姓后名”的姓名类Name2(姓、名之间用逗号隔开);程序应当显示: John Smith Smith,John 但程序中有缺失部分,请按照以下提示,把缺失部分补充完整: (1)在“// **1** ****found****”的下方是函数show中的一个语句,它按先名后姓的格式输出姓名。 (2)在“// **2** ****found****”的下方是函数getWord中的一个语句,它把一个字符序列复制到head所指向的字符空间中,复制从start所指向的字符开始,共复制end-start个字符。 (3)在“// **3** ****found****”的下方是函数createName中的语句,它根据指针p的值决定返回何种对象:如果p为空,直接返回一个Name1对象,否则直接返回一个Name2对象。注意:返回的Name1或Name2对象必须是动态对象,返回的实际是指向它的指针。 注意:只在指定位置编写适当代码,不要改动程序中的其他内容,也不要删除或移动“****found****”。填写的内容必须在一行中完成,否则评分将产生错误。 //proj3.cpp #include <iostream> using namespace std; class Name{ protected: char * surname; //姓 char * firstname; //名 public: ~Name() {delete[] surname; delete[] firstname;} virtual void show() = 0; }; class Name1:public Name{ public: Name1(const char * name); // **1** ******found****** void show() {______;} }; class Name2:public Name{ public: Name2(const char * name); void show() {cout << surname << "," << firstname;} }; char * getWord (const char * start,const char * end) { char * head = new char[end - start +1]; // **2** ******found****** for (int i = 0; i < end - start; i ++)______; head[end-start]="/0"; return head; } Name1::Name1(const char * name) { char * p = strchr(name,""); firstname = getWord(name,p); surname = new char [strlen (p)]; strcpy(surname,p+1); } Name2::Name2(const char * name) { char * p = strchr(name,","); surname = getWord(name,p); firstname = new char[strlen(p)]; strcpy(firstname,p+1); } Name * createName(const char * s) { char * p = strchr(s,","); // **3** ******found****** if(p)______; } int main() { Name * n; n = createName("John Smith"); n -> show(); cout << endl; delete n; n = createName("Smith,John"); n -> show(); cout << endl; delete n; return 0; }
进入题库练习
问答题使用VC6打开考生文件夹下的源程序文件modil.cpp。本程序要求输入一字符串,然后将其中的小写字母改变成大写字母,字符可能输入多行,当输入字符“?”时,默认字符输入结束,最后把结果输出到界面。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构,错误的语句在∥********error********的下面。 #include void main() { int i=0; char str[12 0] ; cout=‘a’) str[i] =str[i] ‘a’+‘A’; i++; } cout<
进入题库练习