Guest User

Untitled

a guest
May 21st, 2021
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.12 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 Lab4
  8. {
  9.     class Stack
  10.     {
  11.         public string name; // Прізвище працівника
  12.         public int salary; // Оклад
  13.         public Stack next;
  14.     }
  15.     class Program
  16.     {
  17.         static void Main()
  18.         {
  19.             Stack head = null;
  20.             Stack current = null;
  21.             Console.WriteLine("Ви бажаєте створити стек (y-так)");
  22.             string n = Console.ReadLine();
  23.             int count = 0;
  24.  
  25.             //Створення стеку
  26.             while (n == "y")
  27.             {
  28.                 current = new Stack();
  29.                 Console.WriteLine("ВВедiть значення:");
  30.                 Console.WriteLine("Прiзвище працiвника: ");
  31.                 current.name = Console.ReadLine();
  32.                 Console.WriteLine("Оклад: ");
  33.                 current.salary = Convert.ToInt32(Console.ReadLine());
  34.                 current.next = head;
  35.                 head = current;
  36.                 count++;
  37.                 Console.WriteLine("Ви бажаєте продовжити введення елементiв (y-так)");
  38.                 n = Console.ReadLine();
  39.             }
  40.             Console.WriteLine("Кiлькiсть елементiв в стеку: {0}", count);
  41.  
  42.             //Перегляд вмісту стеку
  43.             //Стек не знищується
  44.             current = head;
  45.             while (current != null)
  46.             {
  47.                 Console.WriteLine($"Прiзвище: {current.name}   Оклад: {current.salary}");
  48.                 current = current.next;
  49.             }
  50.  
  51.             //Додавання елемента в стек
  52.             current = new Stack();
  53.             Console.WriteLine("ВВедiть значення:");
  54.             Console.WriteLine("Прiзвище працiвника: ");
  55.             current.name = Console.ReadLine();
  56.             Console.WriteLine("Оклад: ");
  57.             current.salary = Convert.ToInt32(Console.ReadLine());
  58.             current.next = head;
  59.             head = current;
  60.             count++;
  61.             Console.WriteLine("Кiлькiсть елементiв в стеку: {0}", count);
  62.  
  63.             current = head;
  64.             while (current != null)
  65.             {
  66.                 Console.WriteLine($"Прiзвище: {current.name}   Оклад: {current.salary}");
  67.                 current = current.next;
  68.                 current = current.next;
  69.             }
  70.  
  71.             int sum = 0;
  72.             int N = 0;
  73.  
  74.             while (current != null)
  75.             {
  76.                 sum += current.salary;
  77.                 N++;
  78.  
  79.                 current = current.next;
  80.             }
  81.  
  82.             Console.WriteLine("The sum of all the elements in the stack : {0}", sum );
  83.             int average = sum / N;
  84.  
  85.             Console.WriteLine("Arithmetic mean : {0}", average);
  86.  
  87.             Console.WriteLine("\nСтек знищено");
  88.  
  89.             Console.ReadLine();
  90.         }
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment