C++程序设计2009年1月真题试题(04737)

自考 责任编辑:彭雅倩 2020-03-30

摘要:C++程序设计2009年1月真题试题及答案解析(04737),本试卷总共100分。

C++程序设计2009年1月真题试题及答案解析(04737)

C++程序设计2009年1月真题试题及答案解析(04737),本试卷总共100分。

一、单项选择题

(本大题共20小题,每小题1分,共20分)在每小题列出的四个备选项中只有一个是符合题目要求的,请将其代码填写在题后的括号内。错选、多选或未选均无分。

1.C++源程序文件扩展名为(  )

A..cpp
B..h
C..lib
D..obj

2.在C++中使用流进行输入输出,其中专用于从键盘进行输入的流是(  )

A.cerr
B.cin
C.cout
D.cfile

3.包含自定义头文件file.h的预处理指令是(  )

A.#define
B.#include file.h
C.#define file.h
D.#include "file.h"

4.用于标识十六进制前缀或后缀是(  )

A.无
B.后缀L或l
C.前缀零
D.前缀0x

5.设存在整型变量int x,则下列句与其它三项含义不同的是(  )

A.int* p=&x;
B.int& p=x;
C.int & p=x;
D.int &p=x;

6.在定义类成员时,为产生封装性,则需使用哪个关键字(  )

A.public
B.publish
C.protected
D.private

7.设函数void swap(int&, int&)将交换两形参的值,如两整型变量int a=10; int b=15;则执行swap(a, b)后,a、b值分别为(  )

A.10,10
B.10,15
C.15,10
D.15,15

8.函数默认参数在函数原型中说明,默认参数必须放在参数序列的(  )

A.前部
B.中部
C.后部
D.两端

9.设存在函数int min(int, int)返回两参数中较小值,若求15,26,47三者中最小值,下列表达式中错误的是(  )

A.int m=min(min(15, 26), min(15, 47));
B.int m=min(15, 26, 47);
C.int m=min(15, min(47, 26));
D.int m =min(min(47, 26), 16);

10.下列函数不能和函数void print(char)构成重载的是(  )

A.int print(int);
B.void print(char, char);
C.int print(char);
D.void print(int, int);

11.在下列成对的表达式中,运算结果类型相同的一对是(  )

A.7/2和7.0/2.0
B.7/2.0和7/2
C.7.0/2和7/2
D.7.0/2.0和7.0/2

12.内联函数的特点是(  )

A.减少代码量,加快访问速度
B.减少代码量,减缓访问速度
C.增加代码量,减缓访问速度
D.增加代码量,加快访问速度

13.类的私有成员可在何处被访问(  )

A.本类的成员函数中
B.本类及子类的成员函数中
C.通过对象名在任何位置
D.不可访问

14.类的构造函数在以下什么情况下会被自动调用(  )

A.定义成员函数时
B.定义对象时
C.定义数据成员时
D.定义友元函数时

15.下列关于析构函数描述正确的是(  )

A.可以重载
B.函数体中必须有delete语句
C.返回类型必须是void类型
D.不能指定返回类型

16.设有函数T Sum(T x, T y){return x+y;},其中T为模板类型,则下列语句中对该函数错误的使用是(  )

A.Sum(1, 2);
B.Sum(3.0, 2.2);
C.Sum("A", "C");
D.Sum("A", "C");

17.下列哪个编译指令属于条件编译指令(  )

A.#include
B.#define
C.#else
D.#pragma

18.关于类的静态成员函数描述错误的是(  )

A.在创建对象前不存在
B.不能说明为虚函数
C.不能直接访问非静态函数
D.不是对象的成员

19.如果类A被声明成类B的友元,则(  )

A.类A的成员即类B的成员
B.类B的成员即类A的成员
C.类A的成员函数不得访问类B的成员
D.类B不一定是类A的友元

20.派生类的对象可以访问以下那种情况继承的基类成员(  )

A.私有继承的私有成员
B.公有继承的私有成员
C.私有继承的保护成员
D.公有继承的公有成员

二、填空题

(本大题共20小题,每小题1分,共20分)请在每小题的空格中填上正确答案。错填、不填均无分。

11.若使用标准输出流把整型变量a的值输出到屏幕上,实现此操作的C++语句是_________。

12.C++将数据从一个对象流向另一个对象的流动抽象为“流”,从流中获取数据的操作称为_________。

13.执行下列代码int b=100;cout<<"Hex:"<<hex<<b;程序的输出结果是_________。

14.静态联编所支持的多态性称为_________的多态性。

15.C++程序必须有且只有一个主函数,其函数名为_________。

16.写出声明一个复数对象的语句,并使该对象被初始化为2.2+1.3i,此声明语句是_________。

17.若有函数定义为:int add(int m1=0, int m2=2, int m3=4){ return m1+m2+m3; }在主函数中有int s=add(1)+add(0, 1)+add(0, 1, 2);则执行此语句后s的值为_________。

18.C++中使用_________关键字说明函数为内联函数。

19.在源程序中有宏定义:#define PI 3.14,则若不想使该宏定义影响到程序的其它地方,可以使用_________删除该宏定义。

110.类和其它数据类型不同的是,组成这种类型的不仅可以有数据,还可以有对数据进行操作的__________。

111.有下列代码int a=0; double b=0; cin>>a>>b;当用键盘输入1.25时,b=_________。

112.对于类Point而言,其析构函数的定义原型为_________。

113.对象成员构造函数的调用顺序取决于这些对象在类中说明的顺序,与它们在成员初始化列表中给出的顺序_________。

114.类的简单成员函数是指声明中不含_________、volatile、static关键字的函数。

115.与操作对象的数据类型相互独立的算法称为_________。

116.从一个或多个以前定义的类产生新类的过程称为_________。

117.在vector类中向向量尾部插入一个对象的方法是_________。

118.C++中用于动态创建对象,并返回该对象的指针的关键字是_________。

119.C++的流类库预定义的与标准输出设备相联接的流是_________。

120.执行下列代码cout<<noshowpoint<<123.0;程序输出结果是_________。

三、改错题

(本大题共5小题,每小题2分,共10分)下面的类定义中有一处错误,请用下横线标出错误所在行并给出修改意见。

21.#include<iostream.h>class f{private: float x, y;public:f(float a, float b){x=a; y=b;}float max( ){return(x<y)?x:y;};main( ){f a(1.5, 3.8);cout<<a.max()<<endl;}

22.#include<iostream.h>class test{private: int x;public: test(int a){x=a;}void set(int a){x=a;}void get( ){cout<<x<<endl;}}main( ){const test a(3);a.set(5);a.get( );}

23.#include<iostream.h>class point{private: float x, y;public: f1(float a, float b){x=a; y=b;}point( ){x=0; y=0;}void getx( ){cout<<x<<endl;void gety( ){cout<<y<<endl;};void print(point a){cout<<a.x<<endl;}main( ){point a;a.f1(3.0, 5.0);print(a);}

24.#include<iostream.h>class f{private: int x, y;public: fl(int a, int b){x=a;y=b;}void print( ){cout<<x<<y<<endl;};main( ){f a;a.f1(1.5,1.8);a.print( );}

25.#include<iostream.h>main( ){int x=6;const int*p=x;cout<<*p<<endl;}

四、完成程序题

(本大题共5小题,每小题4分,共20分)

31.完成下面程序,使其输出10,并在退出运行时正确释放分配给指针的存储空间。#include <iostream>using namespace std;void main( ){int  *a, *p;a=new int(10);p=_________;cout<<*p<<endl;_________}

32.#include <iostream>using namespace std;class base{private: int x;public: base(int a){x=a;}int get( ){return x;}void showbase( ) {cout<<"x="<<x<<endl;}};class Derived: public base{private: int y;public: Derived(int a,int b): base(a){y=b;}void showderived( ){cout<<"x="<<get( )<<",y="<<y<<endl;}};   void main( ){base b(3);Derived d(6,7);b.showbase( );d.showderived( );___________; b.showbase( );___________;b1.showbase( );base* pb=&b1;pb->showbase( );d.showderived( );b.showbase( );}输出结果如下:x=3x=6,y=7x=6x=6x=6x=6,y=7x=6

33.下面程序的运行结果如下:B::display( )C::display( )在下划线处填上缺少的部分。源程序如下:  #include<iostream>  using namespace std;  class B  {  public:    _________display( )  {cout << "B::display( ) "<<endl;}    };    class C: public B    {    public:         __________display( ){cout<<"C::display( )"<<endl;}    };    void fun(B*p)    {    p->display( );    }    void main( )    {    B b, *pb;    C c;    pb=&b;    fun(pb);    pb=&c;    fun(pb);    }

34.下面程序的运行结果如下:    This is line1    This is line2    This is line3在下划线处填上缺少的部分。源程序如下:    #include <iostream>    #include_________    using namespace std;    void main( )    {    fstream fin, fout;    fout.open("my. txt", ios:: out);    if(!fout.is_open( ))       return;    for(int i=0;i<3;i=i+1)       fout<<"This is line"<<i+1<<endl;    fout.close( );    fin.open("my.txt",ios:: in);    if(! fin.is_open( ))       return;    char str[100];    while(_________)    {      fin.getline(str,100);      cout<<str<<endl;    }    fin.close( );    }

35.在下划线处填上缺少的部分。源程序如下:#include <iostream>using namespace std;___________    T fun(T x)    {    _________y;    y=x*x-T(5);    return y;    }    void main( )    {    float a=2;    cout<<fun(a);    }

五、程序分析题

(本大题共4小题,每小题5分,共20分)

41.请写出myTextl.txt文本文件中的内容#include <iostream>#include <string>using namespace std;#include<fstream>void main( ){ofstream myFile1;myFile1.open("myText1.txt");cout<<"Enter the data in Chinese format(e.g.,2008,May 25):"<<endl;string Date("2008,January 1");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+" "+Month+" "+Year;myFile1<<"original date:"<<Date<<endl;myFile1<<"Converted date:"<<NewDate<<endl;myFile1.close( );}

42.给出下面程序的输出结果#include <iostream>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<<"x="<<x<<",y="<<y<<endl;}};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( );}

43.给出下面程序的输出结果  #include"iostream.h"  int main( )  {  int i=17;  while(i>=10)  if(--i%4==3)continue;  else  cout<<"i="<<i--<<endl;  }

44.给出下面程序的输出结果  #include<iostream>  using namespace std;  void main( )  {  int num=300;  int &ref=num;  cout<<ref;  ref=ref-100;  cout<<" "<<num;  num=num-50;  cout<<" "<<ref<<endl;  }

六、程序设计题

(本大题共1小题,共10分)

51.定义堆栈类模板Stack(先进后出),栈的大小由使用者确定。要求该类模板对外提供如下二种基本操作:(1)push入栈(2)pop出栈,用数组来实现#include<iostream>using namespace std;template<class T,int size>class Stack{  T x[size];  int current;  public:  Stack( ){current=0;}  ....push(....);  ....pop(....);};请写出两个函数的过程(如果需要形式参数,请给出形参类型和数量,以及返回值类型)

更多资料
更多课程
更多真题
温馨提示:因考试政策、内容不断变化与调整,本网站提供的以上信息仅供参考,如有异议,请考生以权威部门公布的内容为准!

自考备考资料免费领取

去领取

距离2024 自考考试

还有
  • 1
  • 7
  • 5
自考报名

每年3月、8月

领准考证

考前7天

考试信息

每年4月、10月

成绩查询

考后45天

专注在线职业教育23年

项目管理

信息系统项目管理师

厂商认证

信息系统项目管理师

信息系统项目管理师