银行排队系统源程序清单.doc_第1页
银行排队系统源程序清单.doc_第2页
银行排队系统源程序清单.doc_第3页
银行排队系统源程序清单.doc_第4页
银行排队系统源程序清单.doc_第5页
已阅读5页,还剩11页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

第 16 页 共 16 页3 源程序清单CSeqBankQueue.cs类代码using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;namespace 银行排队系统 class CSeqBankQueue : CSeqQueue, IBankQueue private int callnumber;/记录系统自动产生的新来顾客的服务号 /叫号属性 public int Callnumber get return callnumber; set callnumber = value; public CSeqBankQueue() public CSeqBankQueue(int size) : base(size) /获得服务号码 public int GetCallnumber() if (IsEmpty() & callnumber = 0) callnumber = 1; else callnumber+; return callnumber; /服务窗口类 class ServiceWindow IBankQueue bankQ; public IBankQueue BankQ get return bankQ; set bankQ = value; public void Service() while (true) Thread.Sleep(10000); if (!bankQ.IsEmpty() Console.WriteLine(); lock (bankQ) Console.WriteLine(请0号到1号窗口!, bankQ.DeQueue(), Thread.CurrentThread.Name); CSeqQueue.cs类代码using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace 银行排队系统 public class CSeqQueue : IQueue private int maxsize; /循环顺序队列的容量 private T data; /数组,用于存储循环顺序队列中的数据元素 private int front; /指示最近一个己经离开队列的元素所占的位置 private int rear; /指示最近一个进行入队列的元素的位置 /索引器 public T thisint index get return dataindex; set dataindex = value; /容量属性 public int Maxsize get return maxsize; set maxsize = value; /队头指示器属性 public int Front get return front; set front = value; /队尾指示器属性 public int Rear get return rear; set rear = value; /初始化队列 public CSeqQueue() public CSeqQueue(int size) data = new Tsize; maxsize = size; front = rear = -1; /入队操作 public void EnQueue(T elem) if (IsFull() Console.WriteLine(Queue is full); return; rear = (rear + 1) % maxsize; ; datarear = elem; /出队操作 public T DeQueue() if (IsEmpty() Console.WriteLine(Queue is empty); return default(T); front = (front + 1) % maxsize; return datafront; /获取队头数据元素 public T GetFront() if (IsEmpty() Console.WriteLine(Queue is empty!); return default(T); return data(front + 1) % maxsize; /求循环顺序队列的长度 public int GetLength() return (rear - front + maxsize) % maxsize; /判断循环顺序队列是否为满 public bool IsFull() if (front = -1 & rear = maxsize - 1) | (rear + 1) % maxsize = front) return true; else return false; /清空循环顺序队列 public void Clear() front = rear = -1; /判断循环顺序队列是否为空 public bool IsEmpty() if (front = rear) return true; else return false; IBankQueue.cs接口代码using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace 银行排队系统 interface IBankQueue : IQueue int GetCallnumber();/获得服务号码 IQueue.cs接口代码using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace 银行排队系统 interface IQueue void EnQueue(T elem); /入队列操作 T DeQueue(); /出队列操作 T GetFront(); /取对头元素 int GetLength(); /求队列的长度 bool IsEmpty(); /判断队列是否为空 void Clear(); /清空队列 bool IsFull();/判断是否为满,在顺序队列中实现该算法,在链式队列中代码实现为空 Form1代码using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace 银行排队系统 public partial class Form1 : Form static IBankQueue bankQueue = new CSeqBankQueue(100); CSeqQueue q1 = new CSeqQueue(100); int Callnumber; public Form1() InitializeComponent(); Form2 f1 = new Form2(this.q1); Form3 f2 = new Form3(this.q1); Form4 f3 = new Form4(this.q1); f3.Show(); f2.Show(); f1.Show(); private void button1_Click(object sender, EventArgs e) if (!bankQueue.IsFull() Callnumber = bankQueue.GetCallnumber(); textBox1.Text = 您的号码是 + Callnumber + 号; bankQueue.EnQueue(Callnumber); q1.EnQueue(Callnumber); else Console.WriteLine(现在业务繁忙,请稍后再来!); Console.WriteLine(); private void button2_Click(object sender, EventArgs e) Form5 f5 = new Form5(); f5.Show(); private void Form1_Load(object sender, EventArgs e) private void timer1_Tick(object sender, EventArgs e) this.label4.Text = 当前时间: + DateTime.Now.ToString(); private void button3_Click(object sender, EventArgs e) Form6 f6 = new Form6(); f6.Show(); Form2代码using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace 银行排队系统 public partial class Form2 : Form CSeqQueue _q1 = new CSeqQueue(100); public Form2(CSeqQueue q1) InitializeComponent(); this._q1 = q1; public static int i = 0; public static string ts; DateTime Time1 = DateTime.Now; private void Form2_Load(object sender, EventArgs e) private void button1_Click(object sender, EventArgs e) if (!_q1.IsEmpty() textBox1.Text = 请 + _q1.DeQueue() + 号到一号窗口; i+; else MessageBox.Show(现在没有客人!, , MessageBoxButtons.OK, MessageBoxIcon.Warning); private void button2_Click(object sender, EventArgs e) if (i != 0) DateTime Time2 = DateTime.Now; TimeSpan t = Time2 - Time1; ts = t.Seconds.ToString(); MessageBox.Show(服务完毕, OK, MessageBoxButtons.OK, MessageBoxIcon.Information); else MessageBox.Show(尚未服务, Error, MessageBoxButtons.OK, MessageBoxIcon.Error); Form3代码using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace 银行排队系统 public partial class Form3 : Form CSeqQueue _q1 = new CSeqQueue(100); public Form3(CSeqQueue q1) InitializeComponent(); this._q1 = q1; public static int i = 0; public static string ts; DateTime Time1 = DateTime.Now; private void Form3_Load(object sender, EventArgs e) private void button1_Click(object sender, EventArgs e) if (!_q1.IsEmpty() textBox1.Text = (请 + _q1.DeQueue() + 号到二号窗口!); i+; else MessageBox.Show(现在没有客人!, , MessageBoxButtons.OK, MessageBoxIcon.Warning); private void button2_Click(object sender, EventArgs e) if (i != 0) DateTime Time2 = DateTime.Now; TimeSpan t = Time2 - Time1; ts = t.Seconds.ToString(); MessageBox.Show(服务完毕, OK, MessageBoxButtons.OK, MessageBoxIcon.Information); else MessageBox.Show(尚未服务, Error, MessageBoxButtons.OK, MessageBoxIcon.Error); Form4代码using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace 银行排队系统 public partial class Form4 : Form CSeqQueue _q1 = new CSeqQueue(100); public Form4(CSeqQueue q1) InitializeComponent(); this._q1 = q1; public static int i = 0; public static string ts; DateTime Time1 = DateTime.Now; private void Form4_Load(object sender, EventArgs e) private void button1_Click(object sender, EventArgs e) if (!_q1.IsEmpty() textBox1.Text = (请 + _q1.DeQueue() + 号到三号窗口!); i+; else MessageBox.Show(现在没有客人!, , MessageBoxButtons.OK, MessageBoxIcon.Warning); private void button2_Click(object sender, EventArgs e) if (i != 0) DateTime Time2 = DateTime.Now; TimeSpan t = Time2 - Time1; ts = t.Seconds.ToString(); MessageBox.Show(服务完毕, OK, MessageBoxButtons.OK, MessageBoxIcon.Information); else MessageBox.Show(尚未服务, Error, MessageBoxButtons.OK, MessageBoxIcon.Error); Form5代码using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace 银行排队系统 public partial class Form5 : Form public Form5() InitializeComponent(); double sum, avg; int i1 = 1; private void button1_Click(object sender, EventArgs e) if (textBox1.Text != & System.Text.RegularExpressions.Regex.IsMatch(this.textBox1.Text.Trim(), 0-9*$) & double.Parse(textBox1.Text.ToString() 0 & double.Parse(textBox1.Text.ToString() 0 & double.Parse(textBox2.Text.ToString() 0 & double.Parse(textBox3.Text.ToString() = 5) sum += double.Parse(textBox3.Text.ToString(); avg = sum / i1; i1+; textBox3.Text = 三号服务窗口平均得分 + avg; else MessageBox.Show(错误,请重新输入!, 三号窗口, MessageBoxButtons.OK, MessageBoxIcon.Error); textBox3.Text = ; errorProvider1.SetError(textBox3, 不是15之间的整数); Form6代码using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace 银行排队系统 public partial class Form6 : Form public Form6() InitializeComponent(); private void button1_Click(object sender, EventArgs e) if (Form2.ts != null & Form2.i != 0) double avg1 = double.Parse(For

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论