吃水果问题,c++版

来源:互联网 发布:2016淘宝类目排行榜 编辑:程序博客网 时间:2024/04/19 23:52

#include <iostream>

#include <signal.h>

#include <ctime>

#include <cstdlib>

#include <windows.h>

using namespacestd;

 

 

int apple=0;

int orange=0;

bool father_lag;

bool mother_lag;

bool son_lag;

bool daugther_lag;

 

void father()

{

                   apple++;

                   cout<<"father放了一个苹果,";

}

 

void mother()

{

                   orange++;

                   cout<<"mother放了一个橘子,";

}

 

void son()

{

                   orange--;

                   cout<<"son 吃了一个橘子,";

}

 

void daugther()

{

                   apple--;

                   cout<<"daugther吃了一个苹果,";

}

void print()

{

        

 

         if(father_lag==true)

                   cout<<"father进程处于等待状态;"<<endl;

         if(mother_lag==true)

                   cout<<"mother进程处于等待状态;"<<endl;

         if(son_lag==true)

                   cout<<"son进程处于等待状态;"<<endl;

         if(daugther_lag==true)

                   cout<<"daugther进程处于等待状态;"<<endl;

 

         if((father_lag==false)&&(mother_lag==false)&&(son_lag==false)&&(daugther_lag==false)!=true)

                   cout<<endl;

}

 

 

 

int main()

{

         intk;

         for(k=0;k<10;k++)

         {

                   cout<<""<<k+1<<"次操作"<<endl;

                   srand((unsigned)time(NULL));

                   inti=rand()%2;

                   if(i==0)

                   {

                            cout<<"father进程被调用"<<endl;

                            Sleep(1000);

                            father();

                            father_lag=false;

                            mother_lag=true;

                            print();

                   }

                   else

                   {

                            cout<<"mother进程被调用"<<endl;

                            Sleep(1000);

                            mother();

                            mother_lag=false;

                            father_lag=true;

                            print();

                   }

 

                   father_lag=false;

                   mother_lag=false;

 

                   if(orange)

                   {

                            cout<<"son进程被调用"<<endl;

                            Sleep(1000);

                            son();

                            son_lag=false;

                            daugther_lag=true;

                            print();

                   }

                   else

                   {

                            cout<<"daugther进程被调用"<<endl;

                            Sleep(1000);

                            daugther();

                            daugther_lag=false;

                            son_lag=true;

                            print();

                   }

 

                   daugther_lag=false;

                   son_lag=false;

         }

 

         return0;

阅读全文
'); })();
0 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 丛菌多少钱一斤 丛文俊 肉丛蓉功效与作用 肉丛蓉功效 丛林深处 丛林拼音 丛林总动员 丛林之狐 丛林的拼音 丛林奇航 丛林狼作品 丛林女超人 激情丛林 丛林地狱 丛林奇兵 丛林噩梦 丛林之王 丛林欢乐世界 丛林之王号大虫是什么生肖 丛林有情狼 丛林王 丛林野食王 丛林野食王第二季 丛林之王是什么动物 泰山归来之丛林之王 丛林虎啸 丛林豹美发剪刀 丛林豹 苍竹 丛明晨 丛组词 丛的组词 丛字组词 丛怎么组词 丛的组词有那些 丛字组词有哪些 丛连彪 东侨开发区 东石笋风景区 东海岛旅游度假区 准东经济技术开发区