kwest87

Untitled

Dec 8th, 2022
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.24 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. /* У вас есть множество целых чисел. Каждое целое число - это сумма покупки.
  8.  Вам нужно обслуживать клиентов до тех пор, пока очередь не станет пуста.
  9.  После каждого обслуженного клиента деньги нужно добавлять на наш счёт и выводить его в консоль.
  10.  После обслуживания каждого клиента программа ожидает нажатия любой клавиши, после чего затирает консоль и по новой выводит всю информацию, только уже со следующим клиентом
  11.  */
  12.  
  13. namespace ConsoleApp7
  14. {
  15.     internal class Program
  16.     {
  17.         static void Main(string[] args)
  18.         {
  19.             int cashbox = 0;
  20.             Queue<int> amounts = new Queue<int>();
  21.             AddInQueue(amounts);
  22.  
  23.             for (int i = amounts.Count; i > 0; i--)
  24.             {
  25.                 DisplayQueue(amounts);
  26.                 ServiseQueue(amounts, ref cashbox);
  27.                 Console.ReadKey();
  28.                 DisplayCashBox(cashbox);
  29.             }
  30.         }
  31.  
  32.         static Queue<int> AddInQueue(Queue<int> amounts)
  33.         {
  34.             amounts.Enqueue(6);
  35.             amounts.Enqueue(3);
  36.             amounts.Enqueue(3);
  37.             amounts.Enqueue(92);
  38.             amounts.Enqueue(30);
  39.             return amounts;
  40.         }
  41.  
  42.         static void DisplayCashBox(int cashbox)
  43.         {
  44.             Console.Clear();
  45.             Console.WriteLine("В кассе :" + cashbox + " рублей.");
  46.         }
  47.  
  48.         static void DisplayQueue(Queue<int> amounts)
  49.         {
  50.             Console.Write("Очередь покупок : ");
  51.  
  52.             foreach (int sum in amounts)
  53.             {
  54.                 Console.Write("  " + sum);
  55.             }
  56.         }
  57.  
  58.         static Queue<int> ServiseQueue(Queue<int> amounts, ref int cashbox)
  59.         {
  60.             cashbox += amounts.Dequeue();
  61.             return amounts;
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment