compclass.h

来自「适合初学者学习以及程序员回顾」· C头文件 代码 · 共 48 行

H
48
字号
// CompClass.h

#ifndef COMPCLASS_H
#define COMPCLASS_H
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
using std::cerr;

//---- 宣告类别 Component --------
class Component
{
  private:
    int I;
  public:
    // 类别 Component 的建构函数
    Component (): I(1)      {} // 预设建构函数
    Component (int N): I(N) {} // 建构函数
    // 类别 Component 的解构函数
    ~Component()            {}
    int Get() const   {return I;}
    void Double()     {I*=2;}
};

//---- 宣告类别 Host --------
class Host
{
  private:
    int k;
    Component C1, C2;
  public:
    Component C3;
    // 类别 Host 的建构函数
    Host() : k(1), C1(1), C2(1), C3(1)  {}
    Host(int L, int M, int N, int P)
           : k(L), C1(M), C2(N), C3(P)  {}
    // 类别 Host 的解构函数
    ~Host()           {}
    int  Get() const  {return k;}
    void Double()     {k*=2;}
    void DoubleComp()
      {C1.Double(); C2.Double(); C3.Double();}
    int  GetC1()      {return C1.Get();}
    int  GetC2()      {return C2.Get();}
};

#endif

⌨️ 快捷键说明

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