16,472
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <ctime>
using namespace std;
class CPlayBall
{
public:
void redf();
void bluef();
CPlayBall();
private:
bool red ;
bool blue;
};
int main()
{
CPlayBall pb;
int a = (unsigned)time(NULL)%2;
if (a == 0)
{
pb.redf();
}
else
{
pb.bluef();
}
return 0;
}
void CPlayBall::redf()
{
cout<<"小红拍皮球!"<<endl;
red = true;
if (blue == false)
{
bluef();
}
}
void CPlayBall::bluef()
{
cout<<"小蓝拍皮球!"<<endl;
blue = true;
if (red == false)
{
redf();
}
}
CPlayBall::CPlayBall()
:red(false)
,blue(false)
{
}