设为首页    加入收藏

自学考试省级导航

全国 A安徽 B北京 C重庆 F福建 G广东 广西 甘肃 贵州 H河南 河北 湖南 湖北 黑龙江 海南 J江苏 江西 吉林 L辽宁 N内蒙古 宁夏 Q青海 S山东 山西 陕西 四川 上海 T天津
     X新疆 西藏 Y云南 Z浙江 历年真题分类检索

全国2006年1月自考面向对象程序设计试题 (精美word版)(二)
2013-04-10 19:51:48 来源:91考试网 作者:www.91exam.org 【
四、完成程序题(本大题共5小题,每小题4分,共20分)
根据题目要求,完成程序填空。
26.请在下面程序的横线处填上适当内容,以使程序完整,并使程序的输出为:
   2,1
   4,3
#include<iostream.h>
class A
{
  int a;
public:
  A(int i=0){a=i;}
  int Geta( ){return a;}
};
class B
{
  A a;
  int b;
public:
  B(int i=0,int j=0): ①        {}
  void display( ){cout<<a.Geta()<<′,′<<b<<endl;}
};
void main( )
{
  B b[2]={B(1,2),B(3,4)};
  for(int i=0;i<2;i++)
    ②        ;
}
27.下面程序中A是抽象类。请在下面程序的横线处填上适当内容,以使程序完整,并使程序的输出为:
   B1 called
   B2 called
#include<iostream.h>
class A
{
public:
  ①            ;
};
class B1:public A
{
public:
  void display( ){cout<<”B1 called”<<endl;}
};
class B2:public A
{
public:
  void display( ){cout<<”B2 called”<<endl;}
};
void show(②        )
{
  p->display( );
}
void main( )
{
  B1 b1;
  B2 b2;
  A* p[2]={&b1,&b2};
  for(int i=0;i<2;i++)
    show(p[i]);
}
28.请在下面程序的横线处填上适当内容,以使程序完整,并使程序的输出为:
   Name:王小明
   Grade:90
#include<iostream.h>
#include<string.h>
class Person
{
  char name[20];
public:
  Person(char* s){strcpy(name,s);}
  void display( ){cout<<”Name:”<<name<<endl;}
};
class Student:public Person
{
  int grade;
public:
  Student(char* s, int g): ①        {grade=g;}
void display( )
{
  ②        ;
  cout<<”Grade:”<<grade<<endl;
}
};
void main( )
{
  Student s(“王小明”,90);
  s.display( );
}
29.请在下面程序的横线处填上适当内容,以使程序完整,并使程序的输出为5。
#include<iostream.h>
class Integer
{
  int x;
public:
  Integer(int a=0){x=a;}
  void display( ){cout<<x<<endl;}
  ①             ;
};
Integer Max(Integer a,Integer b)
{
  if(②        )
    return a;
  return b;
}
void main( )
{
  Integer a(3),b(5),c;
  c=Max(a,b);
  c.display( );
}
30.请在下面的横线处填上适当内容,以使类的定义完整。
class Array
{
  int* ptr;
  int size;
public:
  Array( ){size=0; ptr=0;}
  Array(int n){size=n;ptr=new int[size];}
  Array(①       )    //复制初始化构造函数
  {
    size=a.size;
ptr=new int[size];
for(int i=0;i<size;i++)
  ②       ;    //将源对象的动态数组内容复制到目标对象
  }
};

五、程序分析题(本大题共6小题,每小题5分,共30分)
阅读下面的程序,写出程序运行的结果。
31.#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;
}
32.#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”);
}
33.#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;
}
34.#include<iostream.h>
class Num
{
  int X,Y;
public:
  Num(int x,int y=0){X=x;Y=y;}
void value(int x,int y=0){X=x;Y=y;}
void value( ){
  cout<<X;
if(Y!=0)
cout<<(Y>0?’+’:’-’)<<(Y>0?Y:-Y)<<’i’;
cout<<endl;
}
};
void main( )
{
  Num n(1);
n.value( );
n.value(2,3);
n.value( );
Num m(3,-4);
m.value( );
}
35.#include<iostream.h>
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( );
}
36.#include<iostream.h>
class A
{
  int a;
public:
  A(int aa=0){a=aa;cout<<"a="<<a<<endl;}
};
class B
{
  int b;
public:
  B(int bb=0){b=bb;cout<<"b="<<b<<endl;}
};
class C:public B
{
  A a;
public:
  C( ){cout<<”C default constructor”<<endl;}
  C(int i,int j):a(i),B(j){cout<<”C constructor”<<endl;}
};
void main( )
{
  C c来源:www.91exam.org1,c2(5,6);
}

 

Tags:自学考试 历年真题
】【打印繁体】 【关闭】 【返回顶部
上一篇全国2005年10月自考面向对象程序.. 下一篇全国2011年7月自考离散数学试题 ..

网站客服QQ: 960335752 - 14613519 - 48225117