计算机类
公务员类
工程类
语言类
金融会计类
计算机类
医学类
研究生类
专业技术资格
职业技能资格
学历类
党建思政类
计算机等级考试(NCRE)
全国计算机应用水平考试(NIT)
计算机软件水平考试
计算机等级考试(NCRE)
全国高校计算机等级考试CCT
行业认证
信息素养
计算机等级考试二级
计算机等级考试一级
网络工程师(计算机等级考试四级)
计算机等级考试二级
数据库工程师(计算机等级考试四级)
计算机等级考试三级
信息安全工程师(计算机等级考试四级)
嵌入式系统开发工程师(计算机等级考试四级)
软件测试工程师(计算机等级考试四级)
C++语言程序设计
Python语言程序设计
WPS Office高级应用与设计
C语言程序设计
C++语言程序设计
Java语言程序设计
Visual Basic语言程序设计
Web程序设计
Access数据库程序设计
MySQL数据库程序设计
Visual FoxPro数据库程序设计
办公软件高级应用
问答题请使用VC6或使用【答题】菜单打开 prog1下的工程prog1。此工程中包含程序文件main.cpp,其中有类Score(“成绩”)和主函数main的定义。程序中位于每个“// ERROR ****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: 学号:12345678 课程:英语 总评成绩:85 注意:只修改每个“// ERROR ****found****”下的一行,不要改动程序中的其他内容。 #include <iostream> using namespace std; class Score{ public: Score (const char * the_course, const char * the_id, int the_normal, int the_midterm, int the_end_of_term} : course(the_course), normal(the_normal), midterm(the_midterm), end_of_term(the_end_of_term) { // ERROR *******found******* strcpy (the_id, student_id); } const char * getCourse() const {return course;} //返回课程名称 // ERROR *******found******* const char * getID() const {return } //返回学号 int getNormal() const {return normal;} //返回平时成绩 int getMidterm() const {return midterm;} //返回期中考试成绩 int getEndOfTerm() const {return end_of_term;} //返回期考试成绩 int getFinal() const; //返回总评成绩 private: const char * course; //课程名称 char student_id[12]; //学号 int normal; //平时成绩 int midterm; //期中考试成绩 int end_of_term; //期考试成绩 }; //总评成绩中平时成绩占20%,期中考试占30%,期考试占50%,最后结果四舍五入为一个整数 // ERROR *******found******* int getFinal() const { return normal * 0.2 + midterm * 0.3 + end_of_terms 0.5 + 0.5; } int main() { char English[] = "英语"; Score score (English, "12345678",68,83,92); cout << "学号:" << score.getID() << " "; cout << "课程:" << score.getCourse() << " "; cout << "总评成绩:" << score.getFinal() << endl; return 0; }
进入题库练习
问答题改错题 使用VC6打开考生文件夹下的工程kt11_1,此工程包含一个源程序文件kt11_1.cpp,但该程序运行有问题,请改正函数中的错误,使该程序的输出结果为: Valuesare:1,2and3 Pressanykeytocontinue 源程序文件kt11_1.cpp清单如下: #include classCommonBase { public: intx; }; /*****************found*****************/ classDeriveCommonA::publicCommonBase { public: inty; }; classDeriveCommonB:publicCommonBase { public: intz; }; /*****************found*****************/ classOverlapping:publicDeriveCommonA;publicDeriveCommonB { public: voidDisplay() { cout<<"Valuesare:"<
进入题库练习
问答题使用VC6打开考生文件夹proj2下的工程Proj2,其中有元素类Element和队列类Queue的定义。请在程序中的横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的输出结果应为: 3 8 5 0 5 0 7 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容。#include<iOStream>#include<cmath>#include<cstdlib>using namespace std;#define MaxLength i 00 class Element { //“元素”类public: int n; Element(int i=0):n(i){) }; class Queue{ //“队列”类 Element * element; //指向存储元素的数组的指针 int tail;//队尾元素的下标public: Queue():element(new Element[100]),tail(一1){} 一Queue(){delete[]element;} void push(Element ele); //在队列尾端添加一个元素 Element pop();//在队列首端删除一个元素,返回被删元素 Element front()const{return element[0];//返回队首元素,但不从队列中删除该元素 //******found****** int size()const{ return(_______);}//返回元素个数 void show()const,//显示集合中所有元素};void Queue::push(Element ele){ if(tail==MaxLength一1) return;//空间满,不做任何处理 //******found****** ________;}Element Queue::pop(){ if(Size()==0)exit(1); //队列空,不做任何处理 Element tmp=element[0]; for(int i=0;i<tail;i++) element[i]=element[i+1]; //******found****** __________; return tmp;}VOid Queue::show ()const { //******found****** for(_________) cout<<element[i].n<<''; cout<<endl;}int main(){ Queue q; q.push(3); q.push(8); q.push(5); q.push(0); q.show(); q.pop(); q.pop(); q.push(7); q.show(); return 0;}
进入题库练习
问答题请使用VC6或使用[答题]菜单打开考生文件夹proj1下的工程proj1,该工程中包含程序文件main.cpp,其中有类Door(“门”)和主函数main的定义。程序中位于每个“//ERROR****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: 打开503号门…门是锁着的,打不开。 打开503号门的锁…锁开了。 打开503号门…门打开了。 打开503号门…门是开着的,无须再开门。 锁上503号门…先关门…门锁上了。 注意:只修改每个“//ERROR********found********”下的那一行,不要改动程序中的其他内容。 #include<iostream> using namespace std; class Door{ int num; //门号 bool closed; //true表示门关着 bool locked; //true表示门锁着 public: Door(int num){ //ERROR********found******* num=this->num; closed=locked=true; } bool isClosed () const { return closed; } //门关着时返回true,否则返回false bool isOpened () const { return ! closed; } //门开着时返回true,否则返回false bool isLocked () const { return locked; } //门锁着时返回true,否则返回false bool isUnlocked () const { return ! locked; ) //门未锁时返回true,否则返回false void open() { //开门 cout<<endl<<"打开"<<num<<"号门..."; //ERROR********found******** if(closed) cout<<"门是开着的,无须再开门。"; else if(locked) cout<<"门是锁着的,打不开。"; else{ closed=false; cout<<"门打开了。"; } } void close(){ //关门 cout<<endl<<"关上"<<num<<"号门..."; if(closed) cout<<"门是关着的,无须再关门。"; else{ closed=true; cout<<"门关上了。"; } } //ERROR********found******** void lock()const{ //锁门 cout<<endl<<"锁上"<<num<<"号门..."; if(locked) cout<<"门是锁着的,无须再锁门。"; else{ if(! closed){ cout<<"先关门..."; closed=true; } locked=true; cout<<"门锁上了。"; } } void unlock(){//开锁 cout<<
进入题库练习
问答题使用VC6打开考生文件夹下的源程序文件modi2.cpp。阅读下列函数说明和代码,补充空出的代码。函数IsPalindromes(cha*string)实现的功能是判定给定的字符串是否构成回文字符串,如果是则返回1,否则返回0。 如:1234554321或者1234321都认为是回文字符串。 如果串为空或一个字母时,均认为是回文字符串。 注意:不能修改程序的其他部分,只能补充 IsPalindromes ()函数。 #include #defime MAXLEN 1024 bool IsPalindromes(char*string) { } Void main() { char str[MAXLEN]; cout<<"请输入一行文字"<
进入题库练习
问答题请使用VC6或使用【答题】菜单打开考生文件夹pmj2下的工程proj2,其中定义了Employee类和Manager类。Employee用于表示某公司的雇员,其属性包括姓名(name)和工作部分(dept)。Manager是Employee的公有派生类,用于表示雇员中的经理。除了姓名和工作部分之外,Manager的属性还包括级别(level)。Employee类的成员函数print用于输出雇员的信息;Manager类的成员函数print负责输出经理的信息。请在横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的正确输出结果应为:Name:SallySmithDept:SMesLevel:2注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。#include<iosLream>#include<string>usingnamespacestcl;classEmployee{public:Employee(stringFlame,stringdept)://**********found**********{}virtualvoidprint()const;stringdept()const//返回部门名称{//**********found**********}virtual~Employee(){}private:stringname_;stringdept_;};classManager:publicEmployee{public:Nanager(stringname,stringdept,intlevel)://**********found********** {}virtualvoidprint()const;private:intlevel;};voidEmployee::print()const{cout<<"Name:"<<name_<<end1;cout<<"Dept:"<<dept_<<end1;}voidNanager::print()const{//**********found**********cout<<"Level:"<<level<<end1;}intmain(){Employee*erap=newNanacjer("SallySmith”,”Sales”,2);emp->print:();deleteemp;return0;}
进入题库练习
问答题使用VC++6.0打开 下的源程序文件1.cpp,该程序运行时有错误,请改正程序中的错误,使得程序输出为: 10 TC1 注意:不要改动main函数,不能增加或删除行,也不能更改程序的结构,错误的语句在//******error******的下面。试题程序: #include <iostream> class TC1 { public: TC1() { }; //********error******** private: virtual ~TC1() { using namespace std; cout<<"TC1"<<endl; }; }; class TC2: public TC1 { public: //********error******** explicit TC2(int i) { m_i = i; }; TC2 } void print() { //********error******** cout<<m_i<<endl; } private: int m_i; }; void fun(TC2 C1) { C1.print(); } int main() { fun(10); return 0;
进入题库练习
问答题请使用VC6或使用【答题】菜单打开 proj2下的工程proj2。该工程中包含一个程序文件main.cpp,其中有“书”类Book及其派生出的“教材”类TeachingMaterial的定义,还有主函数main的定义。请在程序中“// *******found*******”下的横线处填写适当的代码,然后删除横线,以实现上述类定义和函数定义。此程序的正确输出结果应为: 教材名:C++语言程序设计 页 数:299 作 者:张三 相关课程:面向对象的程序设计 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“// ****found****”。 #include <iostream> using namespace std; class Book{ //“书”类 char * title; //书名 int num_pages; //页数 char * writer; //作者姓名 public: Book(const char * the_title, int pages, const char * the _writer):num_pages(pages) { title = new char [strlen (the_title) +1]; strcpy(title,the_title); // *********found********* ______ strcpy (writer, the_writer); } // **********found********** ~Book() {______} int numOfPages() const{return num_pages;} //返回书的页数 const char * theTitle()const{return title;} //返回书名 const char * theWriter()const{return writer;} //返回作者名 }; class TeachingMaterial: public Book{ //“教材”类 char * course; public: TeachingMaterial (const char * the_title, int pages, const char * the_writer, const char * the_course) // **********found********** :______{ course = new char[strlen (the_course) +1]; strcpy (course, the_course); } ~TeachingMaterial() {delete []course;} const char * theCourse()const{return course;} //返回相关课程的名称 }; int main() { TeachingMaterial a_book ("C++语言程序设计",299,"张三","面对对象的程序设计"); cout << "教材名:" << a_book.theTitle() << endl << "页数:" << a book.numOfPages() << endl <<"作者:" << a_book.theWriter() << endl // **********found********** << "相关课程:" <<______; cout << endl; return 0; }
进入题库练习
问答题请使用VC6或使用【答题】菜单打开 proj2下的工程proj2,其中有整数栈类IntList、顺序栈类SeqList和链接栈类LinkList的定义。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: 4 6 3 1 8 4 6 3 1 8 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动//“****found****”。 #include <iostream> using namespace std; class IntStack { //整数栈类 public: virtual void push(int) = 0; //入栈 virtual int pop() = 0; //出栈并返回出栈元素 virtual int topElement() const = 0; //返回栈顶元素,但不出栈 virtual bool isEmpty() const=0; //判断是否栈空 }; class SeqStack: public IntStack{int data[100]; //存放栈元素的数组 int top; //栈顶元素的小标 public: // ********found******** SeqStack():______{} //把top初始化为-1表示栈空 void push (int n) {data[++top] = n;} // **********found********** int pop() {return______;} int topElement() const {return data[top];} bool isEmpty() const {return top == -1;} }; struct Node{ int data; Node * next; }; class LinkStack: public IntStack{ Node * top; public: // **********found********** LinkStack():______{} //把top初始化为NULL表示栈空 void push (int n) { Node * p = new Node; p -> data = n; // **********found********** ______ top = p; } int pop(){ int d=top->data;; top=top->next; return d; } int topElement() const {return top -> data;} bool isEmpty() const {return top == NULL;} }; void pushData(IntStack st.push(1); st.push(3); st.push(6); st.push(4); } void popData(IntStack } int main(){ SeqStack st1; pushData(st1); popData(st1); cout << endl; LinkStack st2; pushData(st2); popData(st2); cout << endl; return 0; }
进入题库练习
问答题使用VC++6.0打开考生文件夹下的源程序文件2.cpp。阅读下列函数说明和代码,补充空出的代码。函数IsPalindromes(char *string)实现的功能是判定给定的字符串是否构成回文字符串,如果是则返回1,否则返回0。 例如:abcdcba或者1234321都认为是回文字符串。 如果串为空或一个字母时,均认为是回文字符串。 注意:不能修改程序的其他部分,只能补充IsPalindromes函数。 试题程序: #include<iostream.h> #define MAXLEN 1024 bool IsPalindromes(char *string) { } void main() { char str[MAXLEN]; cout<<"请输入一行文字"<<end1; cin.getline(str,MAXLEN); cout<<IsPalindromes(str)<<end1; return; }
进入题库练习
问答题用VC6打开考生文件夹下的源程序文件modi.3.cpp。其中定义的类并不完整,按照要求完成下列操作,将类的定义补充完整。在屏幕和程序modi3.txt文件中输出以下结果: Hello Test 出现异常情况 其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整: (1)以追加的方式打开文件modi3.txt,请在注释∥********1********后添加适当的语句。 (2)定义一个类对象s,请在注释∥********2********后添加适当的语句。 注意:仅在函数指定位置添加语句,请勿改动主函数main与其他函数中的任何内容。 #include #include using namespace std; void WriteFile(char*x) { ofstream outl ; ∥********1******** outl.open(“modi3.txt”,); outl<
进入题库练习
问答题使用VC6打开下的源程序文件modi3.cpp。其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。(1)在类TestClass中定义name为字符串类型,age为整型,请在注释//********1********之后添加语句。(2)设置类TestClass0的基类为TestClass类的定义,请在注释//********2********后添加语句。(3)在类TestClass的派生类TestClass0的公有成员中定义析构函数TestClass0,请在//********3********后添加。(4)设置类TestClass1的基类为TestClass类的定义,请在//********4********后实现。本程序输出如下结果:TestClassclassconstructorTestClass0classconstructorTestClassonclassconstructorTestClass1classconstructorTestClass1classconstructorTestClassclassconstructorTestClass0classconstructorTestClassclassconstructor注意:增加代码,或者修改代码的位置已经用符号表示出来。请不要修改其他的程序代码。#include<iostream.h>classTestClass{//********1********public:TestClass(){cout"TestClassclassconstructor"endl;}~TestClass(){cout"TestClassclassconstructor"endl;}};//********2********{char*departmert;intlevel;public:TestClass0(){cout"TestClass0classconstructor"endl;}//*******"3"*******{cout"TestClass0classconstructor"endl;}};//********4********{char*major;floatsalary;public:TestClass1(){cout"TestClass1classconstructor"endl;}~TestClass1(){cout"TestClass1classconstructor"endl;}};voidmain(){TestClass0s1;TestClass1t1;}
进入题库练习
问答题使用“答题”菜单或从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.0 无实根 4.5X^2+6X+2=0.0 有两个相同的实根: -0.666667和-0.666667 1.5X^2+2X-3=0.0 有两个不同的实根: 0.896805和-2.23014 //源程序 #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():x1(0.0),x2(0.0),num_of_roots(0) //创建一个“无实根”的Root对象 Root(double root) //************found************ :______ //创建一个“有两个相同的实根”的Root对象 Root(double root1,double root2) :x1(root1),x2(root2),num_of_roots(2) //创建一个有两个不同的实根的Root对象 void show() const //显示根的信息 cout<<"/t/t": switch(num_of_roots) case 0: //************found************ case 1: cout<<"有两个相同的实根:"<<x1<<"和"<<x2;break; default: cout<<"有两个不同的实根:"<<x1<<"和"<<x2;break; ; class Quadratic //二次多项式 public: const double a,b,c; //分别表示二次项、一次项和常数项3个系数 Quadratic(double a,double b,double c) //构造函数 //************found************ :______ Quadratic(Quadratic&x) //复制构造函数 :a(x.a),b(x.b),c(x.c) Quadratic add(Quadratic x)const //求两个多项式的和 return Quadratic(a+x.a,b+x.b,c+x.c); Quadratic sub(Quadratic x)const //求两个多项式的差 //************found************ double value(double x)const //求二次多项式的值 return a *x*x+b*x+c: Root root() const //求一元二次方程的根 double delta=b*b-4*a*e; //计算判别式 if(delta<0.0)return Root(); if(delta==0.0)return Root(-b/(2 *a)); double sq=sqrt(delta); return Root((-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.O,2.O),q3(q2.sub(ql)); q1.showFunction(); q1.root().show(); q2.showFunction(); q2.root().show(); q3.showFunction(); q3.root().show(); cout<<endl; return 0:
进入题库练习
问答题使用VC6打开考生文件夹下的源程序文件modil.cpp,请修改程序中的错误,使程序能得出正确的结果: num:0 num:1 num:10 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构,错误的语句在//*******error*******的下面。#include<iostream.h>int i=10;C1ass TestClass{public: TestClass(int i) { cout<<"num:"<<i<<end1; //********error******** i=i+1; } void Print()const { cout<<"num:"<<i<<end1; )private: int i;};void main(){ //********error******** TestClass print; int i(0); print.Print(); //********error******** cout<<"num: "<<i<<end1; return;}
进入题库练习
问答题使用VC6打开考生文件夹下的源程序文件modi2.cpp。阅读下列函数说明和代码,补充空出的代码。函数convert(char*des,char*str,char c,char*str2)的功能是: 如果str中包含字符“!”,则替换成'a'; 如果str中包含字符“&”,则替换成'b'; 如果str中包含字符“*”,则替换成str2。 并用函数返回目标转换后的指针。 注意:只能补充函数convert(char*des,char*str,char*str2)。 #include #include #define MAXLEN 1024 void convert(char *des,char * str,char *str2) { } void main() { char dest[MAXLEN]; char*str=”!&cefghi*!&"; char*str2="jklm"; convert(dest,str,str2); cout<
进入题库练习
问答题使用VC6打开考生文件夹下的源程序文件modi3.cpp,其中定义了用于表示矩形的CRect类,但类CRect的定义并不完整。请按要求完成下列操作,将类CRect的定义补充完成。(1)定义私有数据成员lefiPoint、topPoint、rightPoint、bottomPoint,分别用于表示矩形左上角及右下角的点的坐标,它们都是double型的数据。请在注释//********1********之后添加适当的语句。(2)完成默认构造函数CRect的定义,指定缺省实参为0,都是double型的数据。请在注释//********2********之后添加适当的语句。(3)定义函数体为空的析构函数。请在注释//********3********之后添加适当的语句。(4)在main()函数中定义CRect类的实例rect2,并把rectl的值赋给rect2。请在注释//********4********之后添加适当的语句。注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。#include<iostream.h>class CRect{private://********1********public://********2********//********3********void SetPoints(double,double,double,double);void SetLeftPoint(double m){leftPoint=m;}void SetRightpoint(double m){rightPoint=m;}void SetToppoint(double m){topPoint=m;}void SetBottomPoint(doublem){bottomPoint=m;}void Display();};CRect::CRect(double1,double t,double r,double b){leftPoint=1;topPoint=t;rightPoint=r;bottomPoint=b;}void CRect::SetPoints(double1,double t,double r,double b){leftPoint=1;topPoint=t;rightPoint=r;bottomPoint=b;}void CRect::Display(){cout<<"left-top point is("<<leftPoint<<","<<topPoint<<")"<<'\n';cout<<"right-bottom point is("<<rightPoint<<","<<bottomPoint(<")"<<'\n';}void main(){CRect rect0;rect0.Display();rect0.SetPoints(20,20.6,30,40);rect0.Display();CRect rectl(0,0,150,150);rectl.SetTopPoint(10.5);rectl.SetLeftPoint(10.5);//********4********rect2.Display();}
进入题库练习
问答题请使用“答题”菜单或使用VC6打开考生文件夹proj3下的工程proj3,其中声明了MyString类。MyString是一个用于表示字符串的类。成员函数startsWith的功能是判断此字符串是否以指定的前缀开始,其参数s用于指定前缀字符串。如果参数s表示的字符串是MyString对象表示的字符串的前缀,则返回true;否则返回false。注意,如果参数s是空字符串或等于MyString对象表示的字符串,则结果为true。 例如:字符串"abc"是字符串"abcde"的前缀,而字符串"abd"不是字符串"abcde"的前缀。请编写成员函数startsWith。在main函数中给出了一组测试数据,此情况下程序的输出应该是: s1=abcde s2=abc s3=abd s4= s5=abcde s6=abcdef s1 startsWith s2:true s1 startsWith s3 false s1 startsWith s4 true s1 startsWith s5 f true s1 startsWith s6 false 要求:补充编制的内容写在//********333********//********666********两行之间,不得修改程序的其他部分。 注意:程序最后已经将结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件,并且在本程序中调用。 //源程序 #include"MyString.h" bool MyString::startsWith(const char*s)const //********333******** //********666******** int main() char s1[]="abcde"; char s2[]="abc"; char s3[]="abd"; char s4[]=" "; char s5[]="abcde"; char s6[]="abcdef"; MyString str(s1); cout<<"s1="<<s1<<endl<<"s2="<<s2<<endl<<"s3="<<s3<<endl <<"s4="<<s4<<endl<<"s5="<<s5<<endl<<"s6="<<s6<<endl: cout<<boolalpha<<"s1 startsWith s2:"<<str.startsWith(s2)<<endl <<"s1 startsWith s3:"<<str.startsWith(s3)<<endl <<"s1 startsWith s4:"<<str.startsWith(s4)<<endl <<"s1 startsWith s5:"<<str.startsWith(s5)<<endl <<"s1 startsWith s6:"<<str.startsWith(s6)<<endl; //writeToFile("K://b10//61000101//"); return 0:
进入题库练习
问答题使用VC++6.0打开 下的源程序文件1.cpp,该程序运行时有错误,请改正其中的错误,使程序正常运行,并且输出以下结果: (4,5) 7,8 (4,8) 注意:错误的语句在//******error******的下面,修改该语句即可。 试题程序: #include<iostream.h> class TC0 { public: TC0(int i,int j) { x=i; y=j; } //******error****** virtual void move(int a;int h) { x+=a; y+=b; } void print() { court<<"("<<x<<:,:<<y<<")"<<endl; } public: int X,Y; }; class TC1:public TC0 { public: //******error****** TC1(int i,int j,int k):(i,j) { m=k; n=l; } void print() { cout<<m<<","<<n<<endl; } void func() { move(3,5); } void display() { //******error****** print(); } private: int m,n; }; void main() { TC0 obj(4,5); obj.print(); TC1 obj1(1,3,7,8); obj1.func(); obj1.print(); obj1.display(); }
进入题库练习
问答题使用VC6打开源程序文件modi3.cpp。其中类TestClass用于把文件输出到屏幕,然后进行文件的分割。分割的方法如下:第一个文件的大小是文件的前一半,另外一个文件的大小是剩余部分。 此程序将int.txt文件中的内容输出到屏幕,并且将文件按照以上方式分割,存于文件out1.txt和out2.txt中。其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。 (1)从输入文件中获得一个字符,并判断是否到文件结尾,如果到文件结尾,则退出循环。请在注释//********1********后添加适当的语句。 (2)把获得的输入文件的内容存储到buf中,并且用len记录下文件的长度。请在注释//********2********后添加适当的语句。 (3)将输入文件的后一半内容存储在第二个文件中,请在注释//********3********后添加适当的语句。 (4)使用文件流对象打开输入文件in.txt,请在注释//********4********后添加适当的语句。 注意:仅在函数指定位置添加语句,请勿改动主函数main与其他函数中的任何内容。#include<iostream.h>#include<fstream.h>#include<Stdlib.h>Class TestClass{public: TestClass(char*fileName) {len=0; fstream infile; infile.open(fileName,ios::in); char ch; //********1******** while() { cout<<ch; //********2******** } infile.Close(); } void split() { fstream outfile1; fstream outfile2; outfilel.open("out1.txt",ios::out); outfile2.open("out2.txt",ios::out); int i=0; for(i=0;i<len/2;i++) { outfilel<<buf[i]; } do{ //********3******** }while(i!=len); outfile1.close(); outfile2.CioSe(); }private: int len; char buf[1024];);void main(){ //********4******** TestClass Fsp(); Fsp.split(); return;}
进入题库练习
问答题请使用VC6或使用【答题】菜单打开 proj1下的工程proj1,此工程中包含程序文件main.cpp,其中有ElectricFan(“电风扇”)类和主函数main的定义。程序中位于每个“// ERROR ****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: 品牌:清风牌,电源:关,风速:0 品牌:清风牌,电源:开,风速:3 品牌:清风牌,电源:关,风速:0 注意:只修改每个“// ERROR ****found****”下的那一行,不要改动程序中的其他内容。 #include <iostream> using namespace std; class ElectricFan { //“电扇”类 char * brand; int intensity; //风速:0-关机,1-弱,2-中,3-强 public: ElectricFan(const char * the_brand): intensity(0) { brand = new char[strlen (the_brand) +1]; strcpy(brand, the brand); } ~ElectricFan() {delete[] brand;} // ERROR *******found******* const char * theBrand() const {return * brand;} //返回电扇品牌 int theIntensity() const {return intensity;} //返回风速 bool isOn() const {return intensity>0;} //返回电源开关状态 // ERROR *******found******* void turnOff() {intensity=1;} //关电扇 void setIntensity (int inten) { //开电扇并设置风速 // ERROR *******found******* if (intensity >= 1 } void show() { cout << "品牌:" << theBrand() << "牌" << ",电源:" << (isOn())? "开":"关") << ",风速:" << theIntensity() << endl; } }; int main() { ElectricFan fan ("清风"); fan.show(); fan.setIntensity(3); fan.show(); fan.turnOff(); fan.show(); return 0; }
进入题库练习