kwest87

Untitled

Dec 10th, 2022
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.20 KB | None | 0 0
  1. [StartCode]
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. /* У вас есть множество целых чисел. Каждое целое число - это сумма покупки.
  9.  Вам нужно обслуживать клиентов до тех пор, пока очередь не станет пуста.
  10.  После каждого обслуженного клиента деньги нужно добавлять на наш счёт и выводить его в консоль.
  11.  После обслуживания каждого клиента программа ожидает нажатия любой клавиши, после чего затирает консоль и по новой выводит всю информацию, только уже со следующим клиентом
  12.  */
  13.  
  14. namespace ConsoleApp7
  15. {
  16.     internal class Program
  17.     {
  18.         static void Main(string[] args)
  19.         {
  20.             int cashbox = 0;
  21.             Queue<int> amounts = new Queue<int>();
  22.             AddInQueue(amounts);
  23.  
  24.             for (int i = amounts.Count; i > 0; i--)
  25.             {
  26.                 DisplayQueue(amounts);
  27.                 ServTheQueue(amounts, ref cashbox);
  28.                 Console.ReadKey();
  29.                 DisplayCashBox(cashbox);
  30.             }
  31.         }
  32.  
  33.         static void AddInQueue(Queue<int> amounts)
  34.         {
  35.             amounts.Enqueue(6);
  36.             amounts.Enqueue(3);
  37.             amounts.Enqueue(3);
  38.             amounts.Enqueue(92);
  39.             amounts.Enqueue(30);
  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 void ServTheQueue(Queue<int> amounts, ref int cashbox)
  59.         {
  60.             cashbox += amounts.Dequeue();
  61.         }
  62.     }
  63. }
  64. [EndCode]
Advertisement
Add Comment
Please, Sign In to add comment