问答题使用VC6打开考生文件夹下的源程序文件modi3.cpp。通过继承完成输入到屏幕指定的信息:
TestClassA
TestClassB
TestClassC
其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。
(1)完成类B虚继承于A,请在注释∥********1********后添加适当的语句。
(2)完成类C虚继承于A,请在注释∥********2********后添加适当的语句。
(3)完成类D继承于B,C,请在注释∥********3********后添加适当的语句。
(4)函数fun通过调用基类的fun,完成所输出的内容,请在注释∥********4********后添加适当的语句。
注意:增加代码,或者修改代码的位置已经用符号表示出来。请不要修改其他的程序代码。
#include
Class TeStClassA
{
public:
void fun(){
cout<<“TestClassA”<
问答题请使用VC6或使用[答题]菜单打开考生文件夹proj2下的工程proj2,此工程中包含一个源程序文件main.cpp,其中有坐标点类Point、线段类Line和矩形类Rectangle的定义,还有main函数的定义。程序中两点间的距离的计算是按公式实现的。请在横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的正确输出结果应为:Width:4Height:6Diagonal:7.2111area:24注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。#include<iostream>#include<cmath>usingnamespacestd;classPoint{//坐标点类public:constdoublex,y;Point(doublex=0.0,doubley=0.0):x(x),y(y){}//**********found**********doubledistanceTo(______)const{//到指定点的距离returnsqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y));}};classLine{//线段类public:constPointp1,p2;//线段的两个端点Line(Pointp1,Pointp2):p1(p1),p2(p2){}//**********found**********doublelength()const{returnp1.______;}//线段的长度};classRectangle{//矩形类public:constPointupper_left;//矩形的左上角坐标constPointdown_right;//矩形的右下角坐标Rectangle(Pointp1,Pointp2):up-perleft(p1),down_right(p2){}doublewidth()const{//矩形水平边长度//**********found**********returnLine(upperleft,______).length();}doubleheight()const{//矩形垂直边长度returnLine(upperleft,Point(upper_left,x,down_right,y)).length();}doublelengthOfDiagonal()const{//矩形对角线长度returnLine(upper_left,down_right).length();}doublearea()const{//矩形面积//**********found**********return______;}};intmain(){Rectangler(Point(1.0,8.0),Point(5.0,2.0));cout<<"Width:"<<r.width()<<endl;cout<<"Height:"<<r.height()<<endl;cout<<"Diagonal:"<<r.lengthOf-Diagonal()<<endl;cout<<"area:"<<r.area()<<endl;return0}
问答题使用VC6打开考生文件夹下的源程序文件modil.cpp,该程序运行时有错误,请改正错误,使得程序通过运行。
程序输出:
5
a
}
注意:不要改动main函数,不能增行或删行,也不能更改程序的结构,错误的语句在
∥********error********的下面。
#include
template
∥********error********
t min(t x,t y)
{
return(x>y)?y:x;
}
void main()
{
int n=5 ;
∥********error********
char c=“a”;
int d=1;
∥********eroor********
cout<
问答题请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中声明的CDeepCopy是一个用于表示矩阵的类。请编写这个类的赋值运算符成员函数operator=,以实现深层复制。要求:补充编制的内容写在“//**********333**********”与“//**********666**********”之间。不得修改程序的其他部分。注意:程序最后将结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件,并且在本程序中调用。//CDeepCopy.h#include<iostream>#include<string>usingnamespacestd;classCDeepCopy{public:intn;//动态数组的元素个数int*p;//动态数组首地址CDeepCopy(int);~CDeepCopy();CDeepCopy&operator=(constCDeepCopy&r);//赋值运算符函数};voidwriteToFile(char*);//main.cpp#include"CDeepCopy.h"CDeepCopy::~CDeepCopy(){delete[]p;}CDeepCopy::CDeepCopy(intk){n=k;P=newint[n];}//构造函数实现CDeepCopy&CDeepCopy::operator=(constCDeepCopy&r)//赋值运算符函数实现{//********333********//********666********}intmain(){CDeepCopya(2),d(3);a.P[0]=1;d.P[0]=666;//对象a,d数组元素的赋值{CDeepCopyb(3);a.P[0]=88;b=a;//调用赋值运算符函数cout<<b.P[0];//显示内层局部对象的数组元素}cout<<d.p[0];//显示d数组元素a.p[0]的值cout<<"dfadeaway;\n";cout<<a.P[0];//显示a数组元素a.P[0]的值writeToFile("");return0;}
问答题使用VC6打开考生文件夹下的工程test7_3,此工程包含一个源程序文件test7_3.cpp,其中含有一个类Circle的定义,但该类的定义并不完整。请按要求完成下列操作,将类Circle的定义补充完整。 (1)为类Circle增加一个构造函数,该函数有一个参数,并在构造时将该参数值赋给成员radius。将该函数实现为一个非内联函数,并且使用参数列表的方式将类成员赋值。请在注释“//**1**”之后添加适当的语句。 (2)为类Circle增加一个成员函数print(),使得可以输出有关圆的信息,比如下列程序 Circle c; c.SetRadius(5); c.Print(); 将输出:The circle has radius of 5! 请在注释“//**2**”之后添加适当的语句。 (3)完成友元函数void CompareR(Circle *cl,Circle*c2)的定义,在屏幕中输出c1与c2比较radius大小结果,要求使用 if-else结构完成。请在注释“//**3**”之后添加适当的语句。 输出结果如下; The circle has radus of 5! The circle has radius of 10! c1<c2 注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。 源程序文件test7_3.cpp清单如下: #include<iostream.h> class Circle public: Circle():radius(5) //**1** void SetRadius(int r) radius=r; int GetRadius() return radius; //**2** friend void CompareR(Circle *c1,Circle*C2); private: int radius; ; void CompareR(Circle *c1,Circle *C2) //**3** cout<<"c1>c2"<<endl; else if((c1->GetRadius())==(c2->GetRadius())) cout<<"c1=c2"<<endl; else if((c1->GetRadius())<(c2->GetRadius())) cout<<"c1<c2"<<endl; void main() Circle c1; c1.SetRadius(5); C1.Print(); Circle c2(10); c2.Print(); CompareR(
问答题请编写一个函数int compare(char *s,char *t)), 该函数的功能是对两个字符串进行比较。当s所指字符串和t所指字符串相等时,返回值为0;当s所指字符串大于是t指字符串时,返回值大于0;当s所指字符串小于t所指字符串时,返回值小于0。 注意:部分源程序已存在文件PROC8.cpp中。 文件PROC8.cpp的内容如下: //PROC8.cpp #include <iostream> #include <string> using namespace std; int compare(char *s,char *t) //* * * * * * * * * int main () char str1[100],str2[100]; int result; cout<<"Input the first string/n"; cin>>str1; cout<<"Input the second string/n"; cin>>str2; result=compare(str1,str2); if (result==0) cout<<"string1=string2 ! /n"; else if (result>0) cout<<"string1>string2 ! /n"; else cout<<"string1<string2 ! /n"; return 0;
问答题使用VC6打开考生文件夹下的源程序文件modi2.cpp。阅读下列函数说明和代码,完成空出部分的程序。实现函数sort(int A[],int n),用冒泡法将数组排序。 提示:所谓冒泡法,就是每次把相邻的两个数交换,较大的数交换到后面。这样下标从0到n-1的数与其后面相邻的数交换,可以把最大的数交换到数组的末端。进行n次下标从0到n-1的交换,则数组则会变成有序的,而且是由大到小的顺序。 注意:不能修改程序的其他部分,并且不能删除其他的部分,也不能修改程序的结构。#include<iostream.h>#define N 10void sort(int A[N],int n){}int main(){ int A[N]={5,7,4,6,10,13,78,-4,9,20}; sort(A,10); for(int i=0;i<sizeof(A)/sizeof(int);i++) { cout<<A[i]<<' '; } cout<<endl; return 0; }
问答题请使用VC6或使用【答题】菜单打开
proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有日期类Date、人员类Person及排序函数sortByName和主函数main的定义。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义和函数定义。此程序的正确输出结果应为:
按姓名排序
排序前
张三 男 出生日期:1978年4月20日
王五 女 出生日期:1965年8月3日
杨六 女 出生日期:1965年9月5日
李四 男 出生日期:1973年5月30日
排序后:
李四 男 出生日期:1973年5月30日
王五 女 出生日期:1965年8月3日
杨六 女 出生日期:1965年9月5日
张三 男 出生日期:1978年4月20日
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“// ****found****”。
#include <iostream>
using namespace std;
class Date{ //日期类
int year, month, day; //年、月、日
public:
Date(int year, int month, int day): year(year), month(month), day(day) {}
int getYear() const {return year;}
int getMonth() const {return month;}
int getDay() const {return day;}
};
class Person{ //人员
char name[14]; //姓名
bool is_male; //性别,true时表示男性
Date birth_date; //出生日期
public:
Person(char * name, bool is_male, Date birth_date)
// **********found**********
:______
{
strcpy(this -> name, name);
}
const char * getName() const {return name;}
bool isMale() const {return is_male;}
Date getBirthdate() const {return birth_date;}
//利用strcmp()函数比较姓名,返回一个正数、0或负数,分别表示大于、等于、小于
int compareName (const Person
cout << name <<" << (is_male? "男":"女") <<" << "出生日期:" << birth_date.getYear() << "年" //显示出生年
// **********found**********
______//显示出生月
<< birth_date.getDay() << "日"; //显示出生日
}
};
void sortByName (Person ps[], int size) {
//将人员数组按姓名排列为升序
for (int i = 0; i < size -1; i++) {
//采用选择排序算法
int m = i;
for (int j = i+1; j < size; j++)
if (ps[j].compareName (ps[m]) < 0)
m = j;
if(m > i) {
Person p = ps[m];
ps[m] = ps[i];
ps[i] = p;
}
}
}
int main() {
Person staff[] = {
Person("张三", true, Date (1978, 4, 20)),
Person("王五", false, Date (1965, 8, 3)),
Person("杨六", false, Date (1965, 9, 5)),
Person("李四", true, Date (1973, 5, 30))
};
const int size = sizeof(staff)/sizeof(staff[0]);
int i;
cout << endl << "按姓名排序";
cout << endl << "排序前:";
for (i = 0; i < size; i++) staff[i].show();
sortByName (staff, size);
cout << endl << endl << "排序后:";
for(i = 0; i < size; i++)
staff[i].show();
cout << endl;
return 0;
}
问答题使用VC6打开考生文件夹下的源程序文件modi1.cpp,该程序运行时有错,请改正其中的错误,使程序正常运行,并且使程序输出的结果为: a=7,b=0 a=8,b=10 注意:错误的语句在//********error********的下面,修改该语句即可。#include<iostream.h>Class CObj{public: //********error******** friend void func(CObj&,int,int); void display() { //********error******** cout<<"a="<<a<",b="<<<<b<<endl; }private: int a,b;};void func(CObj&obj,int t){ obj.a=t; obj.b=0;}void func(CObj&obj,int t,int j){ obj.a=t; obj.b=j;}Void main(){ //********error******** CObj obj1 func(obj1,7); obj1.display(); func(obj 1,8,10); obj1.display();}
问答题简单应用
请使用"答题"菜单或使用VC6打开考生文件夹proj2下的工程proj2。本程序中有两个类:一是时间类(Time),用于表示一天中的时间,采用24小时制;另一个是街灯类(StreetLight),用于表示街上的路灯。StreetLight类中有Time类的数据成员。这里对StreetLight类的数据成员和成员函数做一下说明:
int id; // 街灯的id
bool is_on; // 街灯的状态,true表示街灯已经开启,false表示街灯关闭
Time current_time; // 当前时间
void turn_on(); //打开街灯
void turn_off(); //关闭街灯
bool check(Time time_threshold); //判断是否过了可开灯的时间,并需要
//开灯
//(time_threshold)
请在程序中 //**********found********** 之下一行的横线处填写适当的代码,并删除横线,使程序完整、正确。
输出结果为:
Turn on Light2
问答题请使用VC6或使用[答题]菜单打开考生文件夹proj1下的工程proj1,该工程中包含程序文件main.cpp,其中有关TVset(“电视机”)和主函数main的定义。程序中位于每个“//ERROR********found********”之后的一行语句有错误,请加以改正。改正后程序的输出结果应该是:
规格:29英寸,电源:开,频道:5,音量:18
规格:29英寸,电源:关,频道:-1,音量:-1
注意:只修改每个“//ERROR****fund****”下的那一行,不要改动程序中的其他内容。
#include<iostream>
using namespace std;
class TVSet{ //"电视机"类
const int size;
int channel; //频道
int volume; //音量
bool on; //电源开关: true表示开,
false表示关
public:
//ERROR********found********
TVSet(int Size){
this->size(size);
channel=0;
volume=15;
on=false;
}
int getSize()const{return size;}
//返回电视机规格
bool isOn()const{return on;} //返回电源开关状态
//返回当前音量,关机情况下返回-1
int getVolume()const{return isOn
()?volume: -1; }
//返回当前频道,关机情况下返回-1
int getChannel()const{return isOn
()?channel: -1; }
//ERROR*********found*********
void turnOnOff()const//将电源在“开”和“关”之间转换
{on=! on; }
void setChannel To (int chan){ //设置频道(关机情况下无效)
if(isOn()
}
void setVolumeTo (int vol){ //设置音量(关机情况下无效)
if(isOn()
}
void show state(){
//ERROR********found********
cout<<"规格:"<<getSize()<<"英寸"
<<",电源:"<<(isOn()?"开": "关")
<<",频道:"<<getChannel()
<<",音量:"<<getVolume()<<endl;
}
};
int main(){
TVSet tv(29);
tv.turnOnOff();
tv.SetChannelTo(5);
tv.setVolumeTo(18);
tv.show State();
tv.turnOnOff();
tv.show state();
return 0;
}
问答题改错题
使用VC6打开考生文件夹下的工程kt12_1,此工程包含一个源程序文件kt12_1.cpp,但该程序运行有问题,请改正函数中的错误,使该程序的输出结果为:
100
源程序文件kt12_1.cpp清单如下:
#include
template
classpair
{ Tvalue1,value2;
public:
pair(Tfirst,Tsecond)
{value1=first;value2=second;}
/*****************found*****************/
chargetmax(); };
/*****************found*****************/
Tpair::getmax()
{ Tretval;
/*****************found*****************/
retval=value1>value2??value1:value2;
returnretval; }
voidmain()
{ pairmyobject(100,75);
cout<
问答题*
问答题请使用VC6或使用[答题] 菜单打开
proj1下的工程proj1,此工程中包含一个源程序文件main. cpp,其中有类Book(“书”)和主函数main的定义。程序中位于每个“//ERROR ****found****”下的语句行有错误,请加以改正。改正后程序的输出结果应该是:
书名:C++语句程序设计总页数:299
已把“C++语言程序设计”翻到第50页
已把“C++语言程序设计”翻到第51页
已把“C++语言程序设计”翻到第52页
已把“C++语言程序设计”翻到第51页
已把书合上。
当前页:0
注意:只修改每个“//ERROR ****found****”下的那一行,不要改动程序中的其他内容。
#include<iostream>
using namespace std;
class Book {
char*title;
int num_pages;//页数
int cur_page;//当前打开页面的页码,0表示书未打开
public:
//ERROR **********found**********
Book(const char*theTitle, int pages) num_pages(pages)
{
title=new char[strlen(theTitle)+1];
strcpy(title, theTitle);
cout<<endl<<"书名:"<<title
<<"总页数:"<<num_pages;
}
~Book() {delete[]title;}
bool isClosed()const {return cur_page==0;} //书合上时返回true,否则返回false
bool isOpen()const {return! isClosed();} //书打开时返回true,否则返回false
int numOfPages()const {return num_pages;} //返回书的页数
int currentPage()const {return cur_page;} //返回打开页面的页码
//ERROR **********found**********
void openAtPage(int page_no)const { //把书翻到指定页
cout<<endl;
if(page_no<1 | | page_no>num_pages) {
cout<<"无法翻到第"<<cur_page<<"页。";
close();
}
else{
cur_page=page_no;
cout<<"已把“"<<title<<"”翻到第"<<cur_page<<"页";
}
void openAtPrevPage() {openAtPage(cur_page-1);} //把书翻到上一页
void openAtNextPage() {openAtPage(cur_page+1);} //把书翻到下一页
void close() { //把书合上
cout<<endl;
if(isClosed())
cout<<"书是合上的。";
else{
//ERROR **********found**********
num_pages=0;
cout<<"已把书合上。";
cout<<endl;
{
};
int main() {
Book book("C++语言程序设计", 299);
book. openAtPage(50);
book. openAtNextPage();
book. openAtNextPage();
book. openAtPrevPage();
book. close();
cout<<"当前页:"<<book. currentPage()<<endl;
return 0;
}
问答题请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,此工程中声明的Array是一个表示数组的类。一个Array对象可以包含多个整型元素。Array的成员说明如下: 成员函数add用于向数组的末尾添加一个元素; 成员函数get用于获取数组中指定位置的元素; 数据成员a表示实际用于存储数据的整型数组; 数据成员size表示数组的容量,数组中的元素个数最多不能超过size; 数据成员num表示当前数组中的元素个数。 SortedArray是Array的派生类,表示有序数组。SortedAr-ray重新定义了Array中的add函数,以确保有序数组中的元。素始终按照升序排列。请在程序中的横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的正确输出结果应为: 10,9,8,7,6,5,4,3,2,1, 1,2,3,4,5,6,7,8,9,10, 注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。#include<iostream>using namespace std;class Array{public: Array(unsigned int s) { Size=s; num=0; a=new int[s]; } virtual—Array(){delete[]a; } virtual void add(int e) { if(num<size){//**********found************ num++; } } int get(unsigned int i)const { if(i<size) return a[i]; return 0 ; }protected: int*a; unsigned int size,num;};class SortedArray:public Array{public://**********found*********** SortedArray(unsigned int S) :________{} virtual void add(int e) { if(num>=Size) return; int i=0,j; while(i<num){ if(e<a[i]){ for(j=num;j>i;j—一){//**********found********** _________; }//**********found********** ______; break; } i++; } if(i==num) a[i]=e; num++; }};void fun(Array } for(i=0;i<10;i++){ cout<<a.get(i)<<”,”; } cout<<endl;}int main(){ Array a(10); fun(a); SortedArray sa(10); fun(sa); return 0;}
问答题使用VC6打开考生文件夹proj3下的工程proj3,其中声明了MyString类,它是一个用于表示字符串的类。成员函数reverse将字符串反转,例如“abcde”反转后就成了“edcba”。请补充完整函数reverse。在main函数中给出了一个测试数据,此情况下程序的输出应该是:This is a stringgnirts a si sihT注意:只需在函数reverse的//**********333**********和//**********666**********之间填入若干语句,不要改动程序中的其他内容。//MyString.h#include<iostream>using namespace std;char*dup(const char*);class MyString{char*str:public:MyString(const char*s=" "):str(dup(s)){}MyString(const MyString&m):str(dup(m.str)){}~MyString(){delete[]str;}void reverse();void show(ostream &os=cout)const{os<<str<<endl;}};inline ostream&operator<<(ostream&os,const MyString&m){m.show(os);return os;}void writeToFile(const char*path);//MyString.cpp#include"MyString.h"char*dup(constchar*s){char*p=new char[stden(s)+1];strcpy(p,s);return p;}void MyString::reverse(){//**********333**********//**********666**********}void writeToFile(const char*path);//writetoFile.cpp#include<fstream>#include"MyString.h"void writeToFile(const char*path){char full[50];strcpy(full,path);strcat(full,"out.dat");ofstream outfile(full);if(outfile.fail()){CelT<<"打开输出文件失败!";return;}MyString m1="This is another string":MyString m2("字符串反转演示");outfile<<m1<<m2;m1.reverse();m2.reverse();ouffile<<m1<<m2:outfile.close();}
问答题请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基类,避免二叉性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: 80 150 100 l 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****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(){return Weight;} }; //**********found********** class bicycle:_________public vehicle { private: int Height; public: bicycle(int maxspeed,int weight,int height):vehicle(maxspeed,weight),Height(height){} int getHeight(){return 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; }
问答题使用VC6打开考生文件夹下的源程序文件modi3.cpp,通过把类Distance定义为类Point的友元类,来实现计算两点之间距离的功能。其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。 (1)把类CDistance定义为类CPoint的友元类。请在注释//********1********之后添加适当的语句。 (2)定义类CPoint的构造函数,完成给私有数据成员x和y的赋值,并且两个参数的缺省值都为0。请在注释//********2********之后添加适当的语句。 (3)完成类CDistance的成员函数length(Point&pPoint,Point&qPoint)的定义,并在其中计算点p、q之间的距离,并且返回结果。假设两点之间的距离distance=sqrt((pPoint.x-qPoint.x)*(pPoint.x-qPoint.x)+(pPoint.y-qPoint.y)*(pPoint.y-qPoint.y))。请在注释//********3********之后添加适当的语句。 注意:增加代码,或者修改代码的位置已经用符号表示出来。请不要修改其他的程序代码。#include<iostream>#include<cmath>using namespace std;class CPoint{public: //********1******** //定义类Point的构造函数 //********2******** void display() { cout<<"x="<<x<<endl;cout<<"y="<<y<<endl;)private: float x,y;};Class CDistance{public: float length(CPoint&p,CPoint &q);};float CDistance::length(CPoint&pPoint,CPoint&qPoint){ //********3******** } int main() { CPoint mPoint(10,10),nPoint(40,50); mPoint.display(); nPoint.display(); CDistance len; cout<<len.length(mPoint,nPoint)<<endl; return 0; }
问答题使用VC6打开考生文件夹下的源程序文件modi3.cpp。其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。完成以下功能:
(1)完成构造函数的定义,使得数据成员变量filename和contex为空,内容长度FileLength为0。请在注释∥********1********后添加适当的语句。
(2)完成析构函数,对contex内存的释放。请在注释∥********2********后添加适当的语句。
(3)完成WriteFile()函数,用来对contex内容进行设置填充内容,如果以前有内容,则删除以前的内容,重新填写。请在注释∥********3********后添加适当的语句。
(4)完成CopyFile()函数,完成将参数对象的contex的内容拷贝到当前的文件内容中,请在注释∥********4********后添加适当的语句。
注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。
#include
class MyFileClasS
{
private:
char filename[64];
char*contex;
int FileLength;
public:
MyFileClass()
{
∥********1********
contex=NULL;
FileLength=0;
}
一MyFileClasS()
{
if(FileLength)
∥********2********
}
void OpenFile(char*str,int
len)
{
for(int i=0;i
问答题使用VC++6.0打开考生文件夹下的源程序文件1.cpp,该程序运行时有错,请改正其中的错误,使程序正常运行,并使程序输出的结果为:
sizeof(S1)=5
sizeof(s2)=10
sizeof(s3)=1
注意:不要改动main函数,不能增加或删除行,也不能更改程序的结构,错误的语句在//******error******的下面。
(1)不能删除assert()语句。
(2)只能修改后面的数字。
提示:assert函数如果为假,则会产生一个中断异常。
试题程序:
#include
#include
voidmain()
{
char*s1="abc":
//********error********
assert(sizeof(s1)==3):
cout<<"sizeof(s1)=5"< chars2[10]="ab":
//********error********
assert(sizeof(s2)==2);
cout<<"sizeof(s2)=10"< chars3=23:
//********error********
assert(sizeof(s3)==4);
cout<<"sizeof(s3)=1"< return;
}
