2009年9月全国计算机等级考试二级笔试试卷(二)

时间:2012-06-05 20:50:01

微信搜索关注"91考试网"公众号,领30元,获取事业编教师公务员等考试资料40G
te:
Int data;
};
Sample::Sample(int data){
 【10】 
}

(11)有如下类定义:
class Sample{
public:
Sample();
~Sample();
Private:
Static int date;
};

将静态数据成员data初始化为0的语句是 【11】 。

(12)“图形”类Shape中定义了纯虚函数CalArea(),“三角形”类Triangle继承了类Shape,请将Triangle类中的CalArea函数补充完整。
class Shape{
public:
virtual int CalArea()=0;
}
class Triangle: public Shape{
public:
Triangle{int s, int h}: side(s),height(h) {}
 【12】 { return side*height/2 ; }
private:
int side;
int height;
};

(13)有如下程序:
#include 
using namespace std;
class GrandChild{
public:
GrandChild(){ strcpy (name,”Unknown”); }
const char * getName()const { return name; }
virtual char * getAddress()const=0;
private:
char name[20];
};
class GrandSon : public GrandChild{
public:
GrandSon{char *name} {}
Char * getAddress() const { return “Shanghai”; }
};
int main(){
GrandChild *gs=new GrandSon(“Feifei”);
cout<getName()<<”住在”<getAddress()<<endl;
delete gs;
return 0;
}
运行时的输出结果是 【13】 。</endl;

 (14)如下程序定义了“单词”类word,类中重载了<运算符,用于比较“单词”的大小,返回相应的逻辑值。程序的输出结果为:After Sorting: Happy Welcome,请将程序补充完整。
#include 
#include 
using namespace std;
class Word{
public:
Word(string s) : str(s) { }
string getStr(){ return str; }
 【14】 const { return (str
friend ostream& operator << (ostream& output, const Word &w)
{ output<
private:
string str;
};
Int main(){
Word w1(“Happy”),w2(“Welcome”);
Cout<<”After sorting: “;
if(w1<<w2;
else cout<<w2<<<w1;
return 0;
}</w2<

(15)请将下列模板类Data补充完整。
template 
class Data{
public:
void put (T v) { val=v; }
 【15】 get()   //返回数据成员val的值,返回类型不加转换
{ return val; }
private:
T val;
};

20099月全国计算机等级考试二级C++笔试参考答案

一、选择题

(1)

 

(2)

 

(3)

 

(4)

 

(5)

 

(6)

 

(7)

 

(8)

 

(9)

 

(10)

 

(11)

D

(12)

C

(13)

B

(14)

C

(15)

B

(16)

A

(17)

D

(18)

A

(19)

C

(20)

D

(21)

B

(22)

D

(23)

C

(24)

B

(25)

D

(26)

A

(27)

C

(28)

B

(29)

D

(30)

A

(31)

B

(32)

D

(33)

C

(34)

B

(35)

A

* 本答案仅供参考


首页 上页 1 2 3 下页 尾页 2/3/3
微信搜索关注"91考试网"公众号,领30元,获取公务员事业编教师考试资料40G
【省市县地区导航】【考试题库导航】

电脑版  |  手机版  |  返回顶部