- 首頁(yè)|
- 網(wǎng)校|
- 焚題庫(kù)|
- APP |
- 微信公眾號(hào)
四、完成程序題(本大題共5小題,每題4分,共20分)
46.將下劃線處缺少的部分寫(xiě)在“答題紙”上。源程序如下:
#include < iostream >
using namespace std ;
class base
{
int a,b;
public:
base(int x,int y){a=x;b=y;}
void show(________________)
{
cout<<p.a<<’’,’’<<p.b<<endl;
}
}________________
void main( )
{
base b(78,87);
b.show(b);
}
47.將下劃線處缺少的部分寫(xiě)在“答題紙’’上。源程序如下:
#include <iostream>
#include <fstream>
using namespace std ;
void main( )
{
________________myf(''ab. txt'');//定義輸出流文件,并初始化
________________<<''This ia a TXT file'';//向文件輸入字符串
myf. close( );
}
48.在下面程序中的下劃線處填上適當(dāng)?shù)某绦颍ù鸢笇?xiě)在“答題紙’’上),使程序的輸出
結(jié)果如下:
67,90
源程序如下:
#include <iostream>
using namespace std ;
class base
{
private:
int x,y;
public:
void initxy( int a,int b){x=a;y=b;}
void show( base*p);
} ;
inline void base::show(________________)
{
cout<<p- >x<<'',''<<p- >y<<endl;
}
void print( base *p)
{
p -> show(p);
}
void main( )
{
base a;
a.initxy( 67 ,90);
print(________________);
}
49.下面程序給出了一個(gè)從普通的基類(lèi)派生出一個(gè)模板類(lèi)的方法,在下劃線處填上正確的
部分(答案寫(xiě)在“答題紙’’上)。
#include <iostream>
using namespace std ;
class Base
{
public:
Base( int a){x=a;}
int Getx(){return;}
void showb(){cout<<x<<endl;}
private:
int x;
} ;
template <class T>
class derived: public Base
{
public:
derived(T a,int b): ________________
{y=a;}
T Gety(){return y;}
void showd(){cout<<y<<'' ''<<Getx()<<endl;}
private:
________________
} ;
void main( )
{Base A(458);
A.showb( );
derived<char *>B ''It is'',1 357);
B.showd( );
}
50.下面程序的運(yùn)行結(jié)果如下:
20,22
60,22
將下劃線處缺少的部分寫(xiě)在“答題紙’’上。源程序如下:
#include <iostream>
using namespace std;
class base
{
private:
const int a;
static const int b;
public:
base(int);
void Show( );
};
________________=22;
________________:a( i ){} //初始化
void base::Show( )
{cout<<a<<”,”<<b<<endl;}
void main( )
{
base al(20),a2(60);
a1.Show( );
a2.Show( );
}