填空题在C++中的实型数据分为三种类型,即单精度float、双精度double和 【8】 。
填空题下列程序的输出结果是{{U}} 【15】 {{/U}}。
#include <iostream>
using namespace std;
class base {
public:
int n;
base(iht x) {n=x;}
virtual void set(int m) {n=m;cout<<n<<'';}
};
class deriveA: public base {
public:
deriveA(int x):base(x) {}
void set(int m){n+=m;cout<<n<<'';}
}:
class deriveB:public base {
public:
deriveB(int x):base(x) { }
void set(int m) {n+=m;cout<<n<<'';}
};
int main()
deriveA d1(1);
deriveB d2(3);
base *pbase;
pbase=
pbase->set(1);
pbase=
pbase->set(2);
return 0;
填空题下面程序的运行结果为 【10】 。 class A public: int num; A(int i)num=i; A(A &a)num=++a.num; void print()cout<<num; ; void main() A a(1),b(a); a.print(); b.print();
填空题C++本身没有定义I/O操作,但I/0操作包含在C++实现中。C++标准库iostream提供了基本的I/O类。I/O操作分别由类istream和工 【11】 提供。
填空题根据变量定义“static int x[5],y[2][3]=9,6,3,1,4,7;”,x[4]= [10] ,y[1][2]= [11] 。
填空题若将一个二元运算符重载为类的成员函数,其形参个数应该是______个。
填空题在下面的程序的横线处填上适当的语句,使该程序的输出为12。
#include <iostream>
using namespace std;
class Base
{
public:
int a,b;
Base(int i){ a=i; }
};
class Derived: public Base
{
int a;
public:
Derived(int x): Base(x),b(x+1){}
void show()
{
{{U}} 【13】 {{/U}}; //输出基烃数据成员a的值。
cout<<b<<end1;
}
};
int main()
{
Derived d(1);
D. show();
return 0;
}
填空题下面程序的输出结果是{{U}} 【15】 {{/U}}。
#inclde<iostreamn>
#include<math>
using namespace std;
class point
{
private:
double x;
double y;
public:
point(double a,double b)
{
x=a;
y=b;
}
friend double distance(point a,point b);
};
double distance(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int main()
{
point p1(1,2);
point p2(5,2);
cout<<distalice(p1,p2)<<endl;
return 0;
}
填空题C++语言中,派生类继承了基类的全部数据成员和除{{U}} 【11】 {{/U}}之外的全部函数成员。
填空题下面程序的输出结果是{{U}}【9】{{/U}}。
#include<iostream.h>
void main( )
{
int a[6]={1,2,3,4,5,6};
for(int i=0;i<5;i++)
cout<<a[i]<<"";
cout<<endl;
}
填空题设在主函数中有以下定义和函数调用语句,且fun()函数为void类型,请写出fun()函数的首部______。
int main()
{
double s[10][22];
int n:
...
fun (s):
...
return 0;
}
填空题多数运算符既能作为类的成员函数重载,也能作为类的非成员函数重载,但[]运算符只能作为类的{{U}} 【14】 {{/U}}函数重载。
填空题在内存中,存储字符'X'要占用1个字节,存储字符串"X"要占用 【7】 个字节。
填空题对于派生类的构造函数,在定义对象时构造函数的执行顺序:先执行调用______的构造函数,再执行调用子对象类的构造函数,最后执行派生类的构造函数体中的内容。
填空题有以下程序:
#include <iostream>
using namespace std;
class MyClass
{
public:
MyClass();
~MyClass();
static int s;
void SetValue(int val);
};
int MyClass::s=0;
MyClass::MyClass()
{
s++;
}
void MyClass::SetValue(int val)
{
s=val;
}
int main()
{
MyClass my[3],*p;
p=my;
for(int k=0;k<3;k++)
{
p->SetValue(k+1);
p++;
}
cout<<MyClass::s<<end1;
return 0;
运行后的输出结果是
________
。
填空题以下程序运行后的输出结果是 【10】 #include <iostream> #include <string> using namespace std; class Y; class X int x; char *strx; public: x(int a,char *str) x=a; strx=new char[strlen(str)+1]; strcpy(strx,str); void show(Y ; class Y private: int y; char *stry; public: Y(int b,char *str) y=b; stry=new char[strlen(str)+1]; strcpy(stry, str); friend void X::show(Y ; void X::show(Y &oB) cout<<strx<<","; cout<<ob.stry<<end1; int main() X a(10,"stringX"); Y b(20,"stringY"); a.show(B) ; return 0;
填空题对虚函数的调用有两种方式:______和______。
填空题以下程序的执行结果是______。 #include<iostream.h> #include<fstream.h> #include<stdlib.h> void main() char ch; fstream file; file.open("abc. dar",ios::out|ios:: in|ios::binary): if(! file) cout<<"abc.dat文件不能打开"<<endl; abort() ; file<<"12 34 56"<<endl; file.seekg(o,ios::beg): while(!file.eof()) streampos here=file.tellg(); file.get(ch); if(ch==' ') cout<<here<<" "; cout<<endl:
填空题以下程序输出结果为______。 #include<iostream> using namespace std; class TestClass 1 public: TestClass1() TestClass1(int i) x1=i; void dispa() cout<<"x1="<<x1<<","; private: int x1; : class TestClass2:public TestClass1 public: TestClass2() TestClass2(int i):TestClass1(i+10) x2=i: void dispb() dispa(); cout<<"x2="<<x2<<end1; private: int x2: : int main() TestClass2 b(2): b.dispb(); return 0;
填空题重载的流运算符函数应该被定义为类的{{U}} 【7】 {{/U}}函数。