Advertisement
cuniszkiewicz

StrukturaStudent

May 24th, 2025
161
0
10 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.Permissions;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Struktury
  9. {
  10.     internal class Program
  11.     {
  12.         struct Student
  13.         {
  14.             public string imie;
  15.             public string nazwisko;
  16.             public int wiek;
  17.             public double sredniaOcen;
  18.         }
  19.         static void Main(string[] args)
  20.         {
  21.             Student[] student = new Student[3];
  22.             int wybor;
  23.  
  24.             do
  25.             {
  26.                 Console.Clear();
  27.                 Console.WriteLine("0 - Wyjście z programu");
  28.                 Console.WriteLine("1 - Dodawanie studentów");
  29.                 Console.WriteLine("2 - Wyświetlanie studentów");
  30.                 Console.Write("Twój wybor: ");
  31.                 wybor = int.Parse(Console.ReadLine());
  32.  
  33.                 switch (wybor)
  34.                 {
  35.                     case 0:
  36.                         Console.Clear();
  37.                         Console.WriteLine("\n\n\n\n\n\n\n\n\t\t\t\t\t\tKONIEC");
  38.                         System.Threading.Thread.Sleep(1000);
  39.                         break;
  40.                     case 1:
  41.                         Console.WriteLine("Podaj dane studentów: ");
  42.                         for (int i = 0; i < student.Length; i++)
  43.                         {
  44.                             Console.WriteLine($"Student {i+1}:");
  45.                             Console.Write($"imie: ");
  46.                             student[i].imie = Console.ReadLine();
  47.                             Console.Write($"nazwisko: ");
  48.                             student[i].nazwisko = Console.ReadLine();
  49.                             Console.Write($"wiek: ");
  50.                             student[i].wiek = int.Parse(Console.ReadLine());
  51.                             Console.Write($"średnia ocen: ");
  52.                             student[i].sredniaOcen = double.Parse(Console.ReadLine());
  53.                         }
  54.                         break;
  55.                     case 2:
  56.                         for (int i = 0;i < student.Length;i++)
  57.                             Console.WriteLine($"Student: {student[i].imie} {student[i].nazwisko}, " +
  58.                                 $"wiek {student[i].wiek}, średnia ocen: {student[i].sredniaOcen}");
  59.                         Console.ReadKey();
  60.                         break;
  61.  
  62.                     default:
  63.                         Console.WriteLine("Nieodpowiedni wybór z menu!");
  64.                         Console.ReadKey();
  65.  
  66.                         break;
  67.                 }
  68.  
  69.  
  70.  
  71.             } while (wybor != 0);
  72.  
  73.         }
  74.     }
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement