7_6.cpp

来自「c++书籍的源代码」· C++ 代码 · 共 71 行

CPP
71
字号
#include<iostream.h>
class child;
 class mother
{
 public:
   void singing();
   friend void fun2(mother &p);
 private:
   void teaching(int h);
};
 void mother::singing()
{
   cout<<"唱歌"<<endl;
}
 void mother::teaching(int h)
{
   cout<<"做"<<h<<"小时的家教"<<endl; 
}
 class father
{
 public:
   friend mother;
   friend void fun1(father &p1,child &p2);
   void driving();
 protected:
   void repairing();
};
 void father::driving()
{
  cout<<"开车"<<endl; 
}
 void father::repairing()
{
  cout<<"修电脑"<<endl; 
}
 class child:public father,public mother
{
 public:
  friend void fun1(father &p1,child &p2);
  void play_pp(char s[30]);
};
 void child::play_pp(char s[30])
{
  cout<<"在"<<s<<"俱乐部打乒乓球"<<endl; 
}
 int main()
{
  void fun1(father &p1,child &p2);
  void fun2(mother &p);
  father s1;
  mother s2;
  child s3;
  s1.driving();
  s2.singing();
  fun2(s2);
  s3.play_pp("飞鱼");
  s3.driving();
  s3.singing();
  fun1(s1,s3);
  return(0);
}
 void fun1(father &p1,child &p2)
{
   p1.repairing();
   p2.repairing(); 
}
 void fun2(mother &p)
{
   p.teaching(2);
}

⌨️ 快捷键说明

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