{
base b(3);
Derived d(6,7); b.showbase(); d.showderived(); b=d; b.showbase(); Derived b1(d);(或Derived b1(6,7); 或base b1(6);或 base b1(d);) b1.showbase(); base* pb=&b1; pb->showbase(); d.showderived(); b.showbase(); }
输出结果如下: x=3
x=6,y=7 x=6 x=6 x=6
x=6,y=7 x=6
48.下面程序的运行结果如下: B::display() C::display()
在下划线处填上缺少的部分。源程序如下: #include
public:
virtual void display( ) {cout << \::display( ) \};
class C:public B {
public: virtual void (或void)display(){cout<<\::display()\};
void fun(B*p) {
p->display(); }
void main() {
B b,*pb; C c; pb=&b; fun(pb); pb=&c; fun(pb); }
49.下面程序的运行结果如下: This is line1 This is line2 This is line3
在下划线处填上缺少的部分。源程序如下: #include
16
{
fstream fin, fout;
fout.open(\ if(!fout.is_open()) return;
for(int i=0;i<3;i=i+1) fout<<\ fout.close();
fin.open(\ if(! fin.is_open()) return; char str[100];
while(!fin.eof()(或等价答案)) { fin.getline(str,100); cout< fin.close(); } 50.在下划线处填上缺少的部分。源程序如下: #include template __T___y; y=x*x-T(5); return y; } void main() { float a=2; cout< 五、程序分析题(本大题共4小题,每小题5分,共20分) 51.请写出myTextl.txt文本文件中的内容 #include ofstream myFile1; myFile1.open(\ cout<<\ ,2008,May 25):\string Date(\string Year=Date.substr(0,4); int k=Date.find(\int i=Date.find(\ string Month=Date.substr(k+1,i-k-1); string Day=Date.substr(i+1,2); string NewDate=Day+\myFile1<<\:\ myFile1<<\:\myFile1.close(); } original date:2008,January 1 Converted date:1 January 2008 52.给出下面程序的输出结果 #include 17 using namespace std; class Simple { int x,y; public: Simple(){x=y=0;} Simple(int i,int j){x=i;y=j;} void copy(Simple&s); void setxy(int i,int j){x=i;y=j;} void print(){cout<<\}; void Simple::copy(Simple&s) { x=s.x;y=s.y; } void func(Simple s1,Simple&s2) { s1.setxy(30,40); s2.setxy(70,80); } void main() { Simple obj1(1,2),obj2; obj2.copy(obj1); func(obj1,obj2); obj1.print(); obj2.print(); } x=1,y=2 x=70,y=80 53.给出下面程序的输出结果 #include\ int main() { int i=17; while(i>=10) if(--i%4==3)continue; else cout<<\ } i=16 i=14 i=12 i=10 54.给出下面程序的输出结果 #include