Está en la página 1de 4

ISFT 38

PROGRAMACIN II EJERCICIOS

TS Anlisis de Sistemas

Fenmenos de espera En una ventanilla se atiende una sola cola. La disciplina es la siguiente: En tiempos fijos (perodos iguales) se atiende o ingresa un elemento (no las dos cosas a la vez). Puede no haber nadie en la cola. No puede haber ms de 6 elementos en la cola (si un cliente llega y ve esa situacin no se pone en la cola). Se comienza con 5 elementos.

Se lleva un registro de: Cantidad de elementos que desistieron de ingresar. Tiempo inactivo.

Ejemplo:

EJERCICIOS FENMENOS DE ESPERA

1 / 4

ISFT 38

PROGRAMACIN II EJERCICIOS

TS Anlisis de Sistemas

Codificacin sugerida:
using using using using using using using using using System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.Forms; System.Collections;

namespace WindowsFormsApplication1 { public partial class Form1 : Form { bool primeraVez = false; static Random azar = new Random(); Queue cola = new Queue(); int ltimo; int perdidos = 0; int inactivos=0; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { if (primeraVez == false) { PrimerClick(); } else { AtencinClientes(); } } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { } private void PrimerClick() { primeraVez = true; for (int i = 1; i < 6; i++) {
EJERCICIOS FENMENOS DE ESPERA 2 / 4

ISFT 38

PROGRAMACIN II EJERCICIOS listBox1.Items.Add(i); cola.Enqueue(i); } ltimo = 5;

TS Anlisis de Sistemas

} private void AtencinClientes() { int n = azar.Next(2); if (n == 0) { //Cliente atendido if (cola.Count != 0) //Si hay elementos en la cola { cola.Dequeue(); listBox1.Items.Clear(); foreach (int k in cola) listBox1.Items.Add(k); } else { inactivos++; textBox2.Text = Convert.ToString(inactivos); } } else { //Cliente ingresado if (listBox1.Items.Count > 6) //Si hay ms de 6 el cliente no entra { perdidos++; textBox1.Text=Convert.ToString(perdidos); } else { ltimo++; cola.Enqueue(ltimo); listBox1.Items.Add(ltimo); } } } private void label1_Click(object sender, EventArgs e) { } private void textBox1_TextChanged(object sender, EventArgs e) { } private void textBox2_TextChanged(object sender, EventArgs e)
EJERCICIOS FENMENOS DE ESPERA 3 / 4

ISFT 38

PROGRAMACIN II EJERCICIOS

TS Anlisis de Sistemas

{ } } }

EJERCICIOS FENMENOS DE ESPERA

4 / 4

También podría gustarte