69.cpp

来自「c++课程习题集的源代码」· C++ 代码 · 共 71 行

CPP
71
字号
#include<iostream.h>
#include<string.h>
 class eng
{
 public:
  eng(int x,char *y);
  ~eng();
  void display(void) const;
 private:
  int w;
  char t[20];
};
 class plane
{
 public:
  plane(int a,int b,int c,char *y);
  ~plane();
  void set_a(int x);
  friend void show(plane &p);
 private:
  int d;
  int s;
  eng g;
  static int count;
};
 eng::eng(int x,char *y)
{
 w=x;
 strcpy(t,y);
 cout<<"发动机对象创建"<<endl;
}
 eng::~eng()
{
 cout<<"发动机对象消亡"<<endl;
}
 void eng::display(void) const
{
 cout<<"发动机重量:"<<w<<"公斤"<<endl;
 cout<<"发动机型号:"<<t<<endl;
}
 plane::plane(int a,int b,int c,char *y):g(c,y)
{
 d=a;
 s=b;
 count++;
 cout<<"客机对象创建"<<endl;
}
 plane::~plane()
{
 count--;
 cout<<"客机对象消亡"<<endl;
}
 void plane::set_a(int x)
{
 d=x;
}
 int plane::count=0; 
 void show(plane &p)
{
 cout<<"载客量:"<<p.d<<"人"<<endl;
 cout<<"航程:"<<p.s<<"公里"<<endl;
 p.g.display(); 
 cout<<"客机数量:"<<plane::count<<endl;
}
 int main()
{
 plane f(240,1500,400,"NB737");
 show(f);
 return(0);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?