填空题 【12】 是一系列相关函数的模型或样板,这些函数的 【13】 形式相同,只是所针对的 【14】 不同。
填空题C++语言的参数传递机制包括传值和传地址两种,如果调用函数时,需要改变实参或者返回多个值,应该采取{{U}} 【11】 {{/U}}方式。
填空题下面是“二维向量”vector2D的定义,其中作为成员函数重载的运算符“+”的功能是将两向量的分量x和y对应相加,然后返回作为相加结果的新对象;请填空补充完整。
class vector2D{
double x; //x分量
double y; //y 分量
public:
vector2D(double x0=0, double y0=0):x(x0),y(y0){}
void show(cout<<' ('<<','<<y<<') ';}
vector2D operator + (vector2D);
};
{{U}} 【11】 {{/U}} operator + (vector2D a)
{
return vector2D({{U}} 【12】 {{/U}});
}
填空题下列程序的输出结果为012,请根据注释将横线处的缺失部分补充完整。 #include<iostream> using namespace std; class Test public: Test(int A) data=a; ~Test() void print()cout<<data;) private: int data; ; int main() Test t[3]=______;//对有3个元素的Test类对象数组t初始化 for(int i=0; i<3; i++) t[i]. print(); return 0;
填空题下列程序的运行结果是______。 #include<iomanip.h> int Func(int*a,int n) int s=1: for(int i=0;i<n;i++) s*=*a++; return s; void main( ) int a[]=l,2,3,4,5,6,7,8; int b=Func(a,6)+Func( cout<<"b="<<b<<endl;
填空题下列程序将x、y和z按从小到大的顺序排列,请将下面的函数模板补充完整。
template <class T>
void order({{U}} 【13】 {{/U}})
{
T a;
if(x>y)
{
a=x;
x=y;
y=a;
}
if (y>z)
{
a=y;
y=z;
z=a;
}
if (x>y)
{
a=x;
x=y;
y=a;
}
}
填空题阅读下面程序:
#include <iostream.h>
int fun2(int m)
{
if(m%3==0)
return 1;
else
return 0;
}
void fun1(int m, int
for (i=1; i<m; i++)
if(fun2(i))
S=S*i;
}
void main()
{
int n=9, s=2;
fun1(n, s);
cout<<s<<end1;
}
该程序的运行结果是{{U}} {{U}} {{/U}} {{/U}}。
填空题有如下程序: #include <iostream> using namespace std; class ONE public: virtual void f() cout << "1"; ; class TWO: public ONE public: TWO() cout << "2"; ; class THREE: public TWO public: virtual void f() TWO::f(); cout << "3"; ; int main() ONE aa, *p; TWO bb; THREE cc; p= P->f(); return 0; 执行上面程序的输出是 【11】 。
填空题非成员函数应声明为类的______才能访问这个类的private成员。
填空题重载加法运算符“+”,其函数名是______。
填空题下列程序的输出结果是{{U}} 【10】 {{/U}}。
#include <iostream>
using namespace std;
int main()
{
int data=1;
int
data+=5;
r+=5;
cout<<data<<end 1;
return 0;
}
填空题汇编程序的功能是将汇编语言所编写的源程序翻译成由{{U}} 【1】 {{/U}}组成的目标程序。
填空题将一个函数声明为一个类的友元函数必须使用关键字{{U}} 【9】 {{/U}}。
填空题以下程序的执行结果是_______。
#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>
void main()
{
char ch:
fstream file:
file.open("abc.dat",ios::out1ios::inlios::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:
}
填空题数组元素a[i]是该数组的第 【6】 个元素。
填空题以下程序的执行结果是______。
#include<iostream.h>
class CSample
{
private:
int n;
static int k:
public:
CSample (int i) {n=i;k++;};
voiddisp();
} ;
void CSample::disp()
{
cout <<"n="<<n<<",k="<<k<<endl
}
int CSample::k=0
void main()
}
CSample a(10),b(20),c(30);
a.disp();
b.disp();
c.disp();
}
填空题以下程序输出的结果是{{U}} {{U}} {{/U}} {{/U}}。
#include<iostream.h>
void main( )
{
int a=5,b=4,c=3,d;
d=(a>b>C) ;
cout<<d;
}
填空题在下面程序的横线处填上适当的内容,使程序执行后的输出结果为ABCD。#include <iostream>using namespace std;class A public: A() cout<<'A'; ;class B: 【14】 public: B()cout<<'B';class C: virtual public A public: C()cout<<'C';class D:public B, public C public: D() cout ;void main() D obj;
填空题下面是用来计算n的阶乘的递归函数,请将该函数的定义补充完整。(注:阶乘的定义是n!=n*(n-1)*...*2*1)
unsigned fact (unsigned n)
{
if(n<=1)
retum 1;
return【 】;
}
填空题在MyClass类的定义中,对赋值运算符:进行重载。请将画线处缺失的部分补充完整。
{{U}} 【13】 {{/U}}MyClass::operator=(const MyClass
value = rhs.value;
return *this;
}