⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cirqueue.cpp

📁 本设计的目的是通过设计和调试一个基于消息的通讯系统
💻 CPP
字号:
//CirQueue.cpp
#include<iostream.h>
#include"CirQueue.h"
#include<string>
#include"stdio.h"
const int setup=100;
char  queue[setup];
void CirQueue::EnQueue( char x)
{
  if((rear+1)%11==front)          
     cout<<"对不起,信箱已满,进程一进入等待状态!"<<endl;
  else
  {
	 cout<< x <<"发送成功!"<<endl;
     if(rear>=11)
	    rear-=11;
     rear=(rear+1)%Queuesize;         //队尾指针在循环意义下加1
     data[rear]=x;
  }
}

CirQueue::DeQueue()
{
  if(rear==front)
     cout<<"对不起,信箱里没有消息,请等待"<<endl;
  else
  {
	 if(front>=11)
		 front-=11;
	 front=(front+1)%Queuesize;    //对头指针在循环意义下加1
	 return data[front];
  }
}
void CirQueue::Send()
{
 int i=0;
 char x;
 cout<<"请输入进程发送的消息(一个字符代表一条信息):"<<endl;
 gets(queue);
 while(queue[i]!='\0'&& i<=9)
 {
     if(i<=9)
	 {
		  x=queue[i];
		  EnQueue(x);
	 }
	 i++;
 }
 while(queue[i]!='\0' && i>9)
 {
	   cout<<queue[i]<<"阻塞"<<endl;
	   i++;
 }
}
void CirQueue::Sendwait()
{
  int j=10;
  char x;
  while(queue[j]!='\0')
  {
   x=queue[j++];
   EnQueue(x);
  }
  if(front==rear) 
    cout<<"信箱消息已经接收完毕,进程二等待!"<<endl;
}
void CirQueue::Recieve()
{
 while(front!=rear)
 {
  DeQueue();
  cout<<  data[front]  <<"    接收成功!"<<endl;
 }
 if(front==rear) 
   cout<<"信箱消息已经接收完毕,进程二等待!"<<endl;
}

⌨️ 快捷键说明

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