程序阅读题1、#include<iostream.h>

程序阅读题

1、

#include<iostream.h>
class Test
{
private:
int num;
public:
Test(int n=0){num=n;num++}
~Test(){cout<<″Destructor is active,number=″<<num<<endl;}
};
void main()
{
Test x[2];
cout<<″Exiting main″<<endl;
}

2、

#include <iostream.h>
class A
{
public:
virtual void fun (int data){cout<<”class A:”<<data<<endl;}
void fun(char *str){ cout<<”class A:”<<str<<endl; }
};
class B: public A
{
public:
void fun() {cout<<”class B”<<endl;}
void fun(int data) { cout<<”class B:”<<data<<endl;}
void fun(char *str){ cout<<”class B:”<<str<<endl;}
};
void main()
{
A *pA;
B b;
pA=&b;
pA->fun(1);
pA->fun(“Hello”);
}

3、

#include <iostream.h>
void main()
{
cout.fill('*');
cout.width(10);
cout<<"123.45"<<endl;
cout.width(8);
cout<<"123.45"<<endl;
cout.width(4);
cout<<"123.45"<<endl;
}

4、从键盘输入10,给出程序的输出结果。

#include<iostream>
#include<vector>
#include<iterator>
using namespace std;
main()
{
vector<int> v;
int i,j,n;
cin>>n;
for(i=1;i<=n;i++)
{
if(i%2!=0)
v.push_back(x);
}
vector<int>::iterator p;
for(p=v.begin();p!=v.end();p++)
cout<<*p<<endl;
}

5、

#include<iostream>
using namespace std;
class Sample
{
private:
int i;
static int count;
public:
Sample();
void display();
};
Sample::Sample()
{
i=0;
count++;
}
void Sample::display()
{
cout<<"i="<<i++<<",count="<<count<<endl;
}
int Sample::count=0;
void main()
{
Sample a,b;
a.display();
b.display();
}
答案
第1空:Exit main Destructor is active,number=1 Destructor is active,number=1
第2空:class B:1 class A:Hello
第3空:****123.45 123.45 //说明:数字前有两个空格 123.45 //说明:数字前无空格
第4空:1 3 5 7 9
第5空:i=0,count=2 i=0,count=2

题目信息

题号:7605
题型:填空题
难度:普通