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

📄 boxmain.cpp

📁 众所周知操作系统由很多的通信机制
💻 CPP
字号:
#include <iostream>
#include <Windows.h>
#include "sendreceivemechanism.h"



int main()
{
	box mybox;
	boxuser boxuser0;//信箱用户一
	boxuser boxuser1;//信箱用户二
	boxuser0.waitrecieve=true;
	boxuser1.waitrecieve=true;
	string str(" is receiving a message");
	boxuser0.send.cont=str;
	boxuser1.send.cont=str;
	cout<<"=======================公共信箱通信方式的验证性程序=============================="<<endl;
	cout<<"================请按如下格式输入,当提示错误是请在此输入"<<endl;
	cout<<"验证开始吗?如果想开始请输入y或Y,否则输入n或N"<<endl;
	cout<<"你是想对那个信箱用户进行操作?"<<endl;
	cout<<"    0:代表信箱用户0"<<endl;
	cout<<"    1: 代表信箱用户1"<<endl;
	cout<<"请输入你要进行操作的信箱用户0或1........"<<endl;
	cout<<"你要对这个用户进行什么操作?"<<endl;
	cout<<"    s:代表要从用户中发送一消息"<<endl;
	cout<<"    r:代表要从信箱中接收一消息"<<endl;
	cout<<"请输入进行的操作类型........."<<endl;
	label:while(char beg=getchar())
	{
		Beep(1000,100);
		if (beg=='n'||beg=='N')
		{
			return 0;
		}
		else if (beg=='y'||beg=='Y')
		{
			/*cout<<"你是想对那个信箱用户进行操作?"<<endl;
			cout<<"    0:代表信箱用户0"<<endl;
			cout<<"    1: 代表信箱用户1"<<endl;
			cout<<"请输入你要进行操作的信箱用户0或1......"<<endl;*/
			char boxnumber;
			while(cin>>boxnumber)///////////////////////////////////////////////////////
			{
				if(boxnumber=='0'||boxnumber=='1')
				{
					/*cout<<"你要对这个用户进行什么操作?"<<endl;
					cout<<"    s:代表要从用户中发送一消息"<<endl;
					cout<<"    r:代表要从信箱中接收一消息"<<endl;
					cout<<"请输入进行的操作类型"<<endl;*/
					char operation;
					//////////////////////////////
					while(cin>>operation)
					{
						if (boxnumber=='0'&&operation=='s')//信箱用户0发送消息
						{
							
							user0send(boxuser0,mybox);
							cout<<"the user is sending a message  succeed"<<endl;
							if (boxuser1.waitrecieve==true)
								user1recieve(boxuser1,mybox);
							
						}
						else if (boxnumber=='0'&&operation=='r')//0接收消息
							user0recieve(boxuser0,mybox);
						else if (boxnumber=='1'&&operation=='s')//1发送消息
						{
							
							user1send(boxuser1,mybox);
							cout<<"the user1 is sending a message  succeed"<<endl;
							if (boxuser0.waitrecieve==true)
								user0recieve(boxuser0,mybox);
						}
						else if (boxnumber=='1'&&operation=='r')//1接收消息
							user1recieve(boxuser1,mybox);
						
						else
							cout<<"你输入了错误的操作命令应为s或r"<<endl;
						goto label;/////////////////////////////////////////////////////
				}
				}
				else 
				{
					cout<<"你输入了错误的命令!请重新输入0或1"<<endl;
				}
			}
		}
		else
		{
			cout<<"验证开始吗?如果想开始请重新输入请输入n或N或y或Y"<<endl;
		}
	}
	return 0;
}

⌨️ 快捷键说明

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