①当消费者获得的数据为大写字母时,则把大写字母转换成小写字母,并显示;

②当消费者获得的数据为小写字母时,则把小写字母转换成大写字母,并显示;

🌂当消费者获得的数据为字符0、1、2、……8、9时,把这些字符直接显示到屏幕;

④当消费者获得的数据为符号(+、-、*、\……)时,把这些符号打印成7行7列的菱形);

处理完数据后,结束临界区;接着唤醒生产者线程。

#include"stdafx.h"
#include"iostream.h"

#define MAX 10
char buff[MAX]={0};

int in = 0;
int out = 0;
int full = 0;
int empty = MAX;

char PRODECT[MAX]={‘A’,‘B’,‘C’,‘D’,‘E’,‘F’,‘G’,‘H’,‘I’};

void ShowBuff()
{
cout<<endl;
for(int i = 0 ; i<MAX;i++)
{
cout<<“buff[”<<i<<"]:"<<buff[i]<<endl;
}
}
int p1(int n)
{
if (empty > 0) //wait(empty)
{
cout<<“I am Producter “<<n<<”!..”;
empty–;
buff[in] =PRODECT[rand()%MAX];
cout<<“Producting…”<<buff[in]<<“at”<<in<<endl;
in=(in+1)%10;
full++;
return -1;
}
else
{
cout<<“Buff is full…”<<“Producter”<<n<<“return is block!” <<endl;
return n;
}
}
int C1(int n)
{
if(full>0)
{
cout<<“I am Consumer”<<n<<"!..";
full–;
cout<<“Consuming…”<<buff[out]<<“at”<<out<<endl;buff[out]=0;
out = (out + 1)%MAX;
empty++;
return -1;
}
else
{
cout<<“Buff is empty…”<<“Consumer”<<n<<endl;
return n;
}
}

10-06 19:32