在下列的程序的横线处填上适当的语句,使该程序的输出为12。
include<iostream.h>
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()
{
第1题:
在下面的程序的横线处填上适当的语句,使该程序的输出为12。
include<iostream.h>
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()
{
______;//输出基类数据成员a的值
cout<<b<<endl;
}
};
int main()
{
Derived d(1);
d.show();
return 0;
第2题:
在下面程序的横线处填上适当的语句,使程序执行后的输出结果为ABCD。
include<iostream>
using namespace std;
classA
{
public:
A(){cout<<'A';}
};
class B:______
{
public:
B(){cout<<'B';}
};
class C:______
{
public:C(){cout<<'C';}
};
class D:public B,public C
{
public:D(){cout<<'D';}
};
void main(){D obj;)
第3题:
在下面程序横线处填上适当内容,使程序输出为:55599。
include <iostream>
using namespace std;
template <class TYPE>
class HisClass
{
TYPE data;
public:
HisClass(TYPE a, TYPE b, TYPE C) ;
TYPE getData(){ return data;)
};
template<class TYPE>
HisClass<TYPE>::HisClass(TYPE a,TYPE b,TYPE C)
{
【 】;
else主f(b>C)
data=b;
else
data=c;
}
int main()
{
HisClass<int> x1(3,4,5),x2(5,3,4),x3(4,5,3),x4(7,8,9),x5(8,7,9);
cout<<x1.getData()<<x2.getData()<<x3.getData()
<<x4.getData()<<X5.getData();
return 0;
}
第4题:
下面程序的执行结果是______。
include<iostream.h>
include<iomanip.h>
using namespace std;
void main()
{
cout<<setfill('x')<<setw(10);
cout<<"Hello"<<endl;
}
第5题:
在下面程序横线处填上适当内容,使得程序的输出为9876。
include <iostream>
using namespace std;
template<class T>
void f(【 】)
{
T t;
for (int i=0;i<n/2;i++)
{
t=a Ii];
a [i]=a[n-1-i];
a [n-1-i]=t;
}
}
int main ( )
{
int x[]={6,7,8,9};
f(x,4);
for (int i=0;i<4;i++)
cout<<x[i];
cout<<end1;
return 0;
}
第6题:
在下面程序的横线处填上______,使程序执行后的输出结果为1/2005。
include<iostream.h>
using namespace std;
class Date
{
Public:
Date(int m=1,int y=0): month(m),year(y){}
void Print(){cout<<month<<"/"<<year<<end1;}
______operator+(const Date&d1,const Date&d2);
private:
int month, year;
};
Date operator+(const Date&d1,const Date&d2)
{
int year,month;
year=d1.year+d2.year;
month=d1.month+d2.month;
year+=(month-1)/12;
month=(month-1)%12+1;
return Date(month,year);
}
void main()
{
Date d1(3,2004),d2,d3(10);
d2=d3+d1;
d2.Print();
}
第7题:
在下面程序的横线处填上适当的语句,使该程序的输出为12。
include <iostream>
using namespace std;
class Base
{
public:
int a;
Base(int i){a=i;}
};
class Derived: public Base
{
int a;
public:
Derived(int x): Base(x),b(x+l){}
void show()
{
【 】;∥输出基类数据成员a的值。
cout<<b<<end1;
}
};
int main()
{
Derived d(1);
d.show();
return 0;
}
第8题:
下列程序的输出结果是______。
include<iostream.h>
include<string.h>
using namespace std;
void fun(const char*s,char &C) {c=s[strlen(s)/2];}
int main()
{
char str[]="ABCDE";
char ch=str[1];
fun(str,ch);
cout<<ch;
return 0;
}
第9题:
已知下列程序的输出结果是23,请将横线处缺失的部分补充完整。
include<iostream>
using namespace std;
class MyClass{
public:
void Print()const{cout<<23;}
};
int main(){
MyClass*p=new MyClass();
______.Print();
return 0;
}
第10题:
在下面程序横线处填上适当内容,以使该程序执行结果为4.4。
include<iostream>
using namespace std;
template<typename T>
T average(T*datA)
{
T s=0;
int i:0;
while(data[i])
【 】;
return s/(i+1);
}
int main()
{
double x[]={2.5,4.5,6.5,5,0.0,5,3,18.5};
cout<<average(X);
return 0;
}