RedFlys

Home work - queue

Nov 11th, 2021
1,018
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.62 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Home_Work
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Queue<int> clients = new Queue<int>();          
  14.             FillQueue(clients);
  15.  
  16.             Work(clients);
  17.         }
  18.  
  19.         static void Work(Queue<int> clients)
  20.         {
  21.             int cash = 0;
  22.  
  23.             while (clients.Count > 0)
  24.             {
  25.                 ServeClient(clients, ref cash);
  26.  
  27.                 Console.WriteLine("Нажмите любую клавишу, что бы обслужить следующого клиента.");
  28.                 Console.ReadKey();
  29.                 Console.Clear();
  30.             }
  31.  
  32.             Console.WriteLine("Клиенты закончились.\n" +
  33.                  $"Вы заработали {cash}.\n");
  34.             Console.ReadKey();
  35.         }
  36.  
  37.         static void ServeClient(Queue<int> clients, ref int cash)
  38.         {
  39.             cash += clients.Peek();
  40.  
  41.             Console.WriteLine($"В очереди {clients.Count} человек.\n" +
  42.                 $"Клиент заплатил за покупки {clients.Dequeue()}.\n" +
  43.                 $"Всего в кассе {cash}.\n");
  44.         }
  45.  
  46.         static void FillQueue(Queue<int> clients)
  47.         {
  48.             Random random = new Random();
  49.             int numberOfClients = 10;
  50.  
  51.             for (int i = 0; i < numberOfClients; i++)
  52.             {
  53.                 clients.Enqueue(random.Next(100, 1000));
  54.             }            
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment