19. C++的输入/输出流库中,ios类是一个虚基类,istream类、ostream类以及streambuf类都是ios类的派生类。
20. 设inf是一个ifstream类的流对象,则inf.seekg(10,ios::beg);表示将文件指针从文件当前位置向后移动10个字节。
得 分 三、读程序写结果(每空2分,共32分)
(注意将结果写在下面相应横线上!)
⑴ ⑵ ⑶ ⑷
⑸ ⑹ ⑺ ⑻ ⑼ ⑽ ⑾_ ⑿ ⒀ ⒁ ⒂ ⒃ 1. 写出下面程序的运行结果。 #include
{ cout<<\} virtual ~A( )
{ cout<<\} };
class B:public A { public: B(int i)
{ cout<<\ buffer=new char[i]; } virtual ~B( ) { delete []buffer;
cout<<\} private: char* buffer;
};
void fun(A* a) { delete a; } void main() { A *b=new B(10); fun(b); }
运行结果: ⑴ ⑵ ⑶ ⑷
2. 写出下面程序的运行结果。 #include
cout<<\ }
virtual void Print()=0; };
class Circle:public Shape { private:
double r; public: void Draw() {
cout<<\ }
void SetData(double radius) {
r=radius; }
void Print() {
cout<<\ } };
class Rectangle:public Shape { private: double a,b; public: void Draw() {
cout<<\ }
void SetData(double x,double y) {
a=x,b=y;
}
void Print() {
cout<<\ } };
void main() { Circle c; Rectangle r; Shape *sp1=&c; Shape &sp2=r; c.SetData(10); r.SetData(3,5); sp1->Draw(); c.Print(); sp2.Draw(); r.Print(); }
运行结果: ⑸ ⑹ ⑺ ⑻
3. 写出下面程序的运行结果(注:运行结果中首行的空白行不考虑)。 #include
{ public: CArray(int i) { Length=i;
Buffer=new char[Length+1]; } ~CArray()
{ delete []Buffer; } int GetLength() { return Length; } char& operator[](int i); private: int Length; char* Buffer; };
char& CArray::operator[](int i) { static char ch; if(i
{ cout<<\ return ch; } }
void main() { int cnt;
CArray string1(6); char *string2=\ for(cnt=0;cnt<8;cnt++) string1[cnt]=string2[cnt];