49.在下面程序的下劃線處填上正確的語句,使其得到下面的輸出結(jié)果。
20
21
22
a[0]=20
a[1]=21
a[2]=22
程序清單如下:
#include < iostream >
using namespace std;
class base
{
private:int x;
public:
void setx(int a){x=a;}
int getx(){return x;}
} ;
void main()
{
base a [3],*p;
a[0].setx(20);
a[1].setx(21);
a[2].setx(22);
for(p=a; p<a+3;p++)
____________
for(int i=0;i<=2;i++)
____________
}
50.在下面程序中的下劃線處填上適當?shù)某绦,使程序的輸出結(jié)果如下:
x=2,y=3
源程序如下:
#include<iostream.h>
class Sample
{
int x,y;
public:
Sample(){x=y=0;}
Sample(________){x=a;y=b;}
void disp()
{
cout<<"x="<<x<<",y="<<y<<endl;
}
} ;
void main()
{
Sample s(2,3),________
P - >disp();
}
五、程序分析題(本大題共2小題,每小題5分,共10分)
51.請給出下面程序的輸出結(jié)果
#include<iostream>
using namespace std;
void fun()
{
static int n=25;
n--;
cout<<"n="<<n<<endl;
}
void main()
{
for(int i=0;i<=2;i++)
fun();
}
52.請給出下面程序的輸出結(jié)果
#include<iostream>
using namespace std;
class point
{
int num;
public:
point(int n)
{cout<<"Initializing"<<n<<endl;num=n;}
} ;
void main()
{
point A(88);
cout<<"Entering main"<<endl;
}
六、程序設(shè)計題(本大題共l小題,共10分)
53.給定兩個字符串對象S,P(P的長度小于S),實現(xiàn)一判斷函數(shù)find,檢測S是否完全包含P(串P是S的子串),若
包含則返回P第一個字符在串S中的起始地址,否則返回-1。
#include<iostream. h>
#include<string>
class str{
string s,p;
public:str(string&a,string&b){s=a;p=b;}
...find(...);
};
請寫出函數(shù)的過程(如果需要形式參數(shù),請給出形參類型和數(shù)量,以及返回值類型)