华南俳烁实业有限公司

自考

各地資訊
當前位置:考試網(wǎng) >> 自學考試 >> 自考真題 >> 工學類 >> C語言程序設計 >> 文章內容

排行熱點

全國2011年1月高等教育自學考試C++程序設計試題_第4頁

來源:考試網(wǎng) [ 2011年12月10日 ] 【大 中 小】
44.#include<iostream.h>
  class point{private:float x;
   public:void f(float a){x=a;}
       void f(){x=0;}
   friend float max(point& a,point& b);
    };
   float max(point& a,point& b)
   {return(a.x>b.x)?a.x:b.x;}
   main(){
   point a,b;
   a.f(2.2);b.f(3.3);
   cout<<a.max(a,b);
   }
45.#include<iostream.h>
   template<class T>
class f{
private:T x,y;
public:void fl(T a,T b){x=a;y=b;}
T max(){return(x>y)?x:y;}
};
main(){
f a;
a.fl(1.5,3.8);
cout<<a.x<<a.y<<a.max()<<endl;
}
四、完成程序題(本大題共5小題,每小題4分,共20分)
46.完成下面類中的成員函數(shù)的定義。
  class point
   {
   private:
  int m,n;
  public:
  point(int,int);
  point(point&);
  };
  point::point(int a,int b)
  {
  m=a:
  _________=b;
  }
  point::point(_________)
  {
  m=t.m;
  n=t.n;
  }
47.下面是一個輸入半徑,輸出其面積和周長的C++程序,在下劃線處填上正確的語句。
  #include<iostream>
   using namespace std;
   _________pi=3.14159;
   void main()
   {
  double r;
   cout<<"r=";
   _________;
  double l=2.0*pi*r;
   double s=pi*r*r;
   cout<<"\n The long is:"<<l<<endl;
   cout<<"The area is:"<<s<<endl;
  }
48.在下劃線處填上缺少的部分。
   #include<iostream>
   #include<fstream>
   using namespace std;
   class complex
   {
   public:
   int real;
   int imag;
   complex(int r=0,int i=O)
   {
      real=r;
   imag=i;
 }
   };
   complex operator+(_________,complex& b)
   {
   int r=a.real+b.real;
   int i=a.imag+b.imag;
   return_________;
   }
   void main()
   {
   complex x(1,2),y(3,4),z;
   z=x+y;
   cout<<z.real<<"+"<<z.imag<<"i"<<endl;
   }
49.程序的輸出結果如下:
  1,9
   50,30
   請根據(jù)輸出數(shù)據(jù)在下面程序中的下劃線處填寫正確的語句。
   源程序如下:
  #include<iostream>
  using namespace std;
  class base
  {
  private:   
  int m;
  public:
  base(){};
  base(int a):m(a){}
  int get(){return m;}
  void set(int a){m=a;}
  };
  void main()
  {
  base*ptr=new base[2];
  ptr->set(30);
  ptr= _________;
  ptr->set(50);
  base a[2]={1,9};
   cout<<a[0].get()<<","<<a[1].get()<<endl;
   cout<<ptr->get()<<",";
  ptr=ptr-1;
   cout<<_________<<endl;
   delete[]ptr;
   }
責編:snrvge
九台市| 天等县| 宜黄县| 龙陵县| 湟中县| 彭阳县| 阳东县| 确山县| 中山市| 石狮市| 唐海县| 福贡县| 扎赉特旗| 内丘县| 云安县| 孟连| 江源县| 子长县| 剑川县| 莎车县| 晋城| 河津市| 忻州市| 平遥县| 康平县| 长兴县| 清苑县| 赞皇县| 治多县| 德阳市| 浠水县| 安庆市| 北安市| 五寨县| 昌邑市| 五河县| 若尔盖县| 寿阳县| 本溪市| 海林市| 南靖县|