内容发布更新时间 : 2025/10/31 9:26:02星期一 下面是文章的全部内容请认真阅读。
Point ( ){ X=a; Y=b; }
void Print(){
cout<<\ cout<<\ } private: float X,Y; };
class Distance{ public:
float Dis(Point &p,Point &q);}; f1oat Distance::Dis(Point &p,Point &q){ float result;
                          ; cout< void main(){      Point p(10,10),q(20,20);     Distance d;     d.Dis(p,q); }   34.friend class Distance                  float a, float b                        result=sqrt((p.X-q.X)*( p.X-q.X)+(p.Y-q.Y)*(p.Y-q.Y))  32.在下面程序的横线处填上适当的语句,使运行该程序执行结果为20。                       class MyClass{ pub1ic:                          //为x置值                          //取x值 private:     int x;   };  void main(){      Myclass my(20);      cout< 33.#include  MyClass(int n){ x=n;}                   33. 下列程序的运行结果如下:  Base's cons. Derived's cons. Derived's des. Base's des.  根据结果将程序补充完整。 #incude      Base(){cout<<              < class Derived:public Base{ public:      Derived(){cout<<\    ~Derived(){cout<<\};  void main(){      Base *Ptr=                            delete ptr;  }  34.  “Base's cons.”                       ~Base()                             new Derived                         34.分析下列程序,写出其运行结果。  #include  int GetNum(){return x;}                 { public:      MyClass(int a){x=a;}     void Fun1(){x++;}     void Fun2(){x+=2;}     void Fun3(){x+=3;}      void Print(){cout<<\private:     int x; };  void main() {  MyClass my(8); void (MyClass::*pf)(); my.Print();      pf=MyClass::Fun1;  (my.*pf)();  my.Print();  pf=MyClass::Fun2;  (my.*pf)();  my.Print(); pf=MyClass::Fun3;  (my.*pf)();  my.Print(); } 运行结果:  37.    x=8           (2分)  x=9           (1分) x=11          (1分) x=14          (1分)    35.仔细阅读程序,在题后写出其运行结果。  #include     Box(int h=10,int w=12,int len=15):height(h),width(w),length(len){ }    int volume();   private:    int height;    int width;     int length;  };  int Box::volume()   {return(height*width*length);  } int main()  {int i;   Box a[3]={    Box(10,12,15),    Box(15,18,20),    Box(16,20,26)    };    for (i=0;i<=2;i++)      cout<<\  return 0;  }  运行结果:  38.  volume of a[0] is 1000          (2分)  volume of a[1] is 5400          (2分) volume of a[0] is 8320          (1分)    36.计算两个长方柱的体积,请编一个基于对象的程序,数据成员包括length (长)、width(宽)、height(高)。要求用成员函数实现以下功能。 (1)由键盘分别输入两个长方柱的长、宽、高。 (2)计算长方柱的体积。 (3)输出2个长方柱的体积。   #include    void get_value();       (1分)   float volume();       (1分)   void display();       (1分)  public:    float lengh;   float width;    float height;       (1分)   };   void Box::get_value()       (1分)  { cout<<\  cin>>lengh;   cin>>width;   cin>>height; }   float Box::volume()       (1分) { return(lengh*width*height);}   void Box::display()       (1分) { cout< int main()  { Box box1,box2; box1.get_value();  box1.display();       (1分) box2.get_value();  box2.display();       (1分) return 0; }   37. 根据输出结果,在程序中填入正确的语句。                        class Instrument{ public:      virtual void Print() const{cout<<\};  class Piano:public Instument{ public:      void Print() const{                      } };  class Guitar :public InstruIment{ pub1ic:      void Print() const{cout<<\};  void Tone(                      )