Advertisement
Guest User

Untitled

a guest
Dec 19th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 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 struktura
  8. {
  9. struct osoba
  10. {
  11. public string nazwisko;
  12. public string imie;
  13. public string wiek;
  14. }
  15. class Program
  16. {
  17. static int WybierzOpcje()//wybieranie opcji
  18. {
  19. int a = 0;
  20. string str;
  21. while (true)
  22. {
  23. Console.Write("Podaj Liczbę: ");
  24. str = Console.ReadLine();
  25. if (int.TryParse(str, out a))
  26. break;
  27. else
  28. Console.WriteLine("Wprowadź liczbę 1,2,0");
  29. }
  30.  
  31. return a;
  32. }
  33.  
  34. static void WyswietlMenu()//menu
  35. {
  36.  
  37. Console.WriteLine("1 = Tworzenie listy osób ");
  38.  
  39. Console.WriteLine("2 = ??????????? ");
  40.  
  41. Console.WriteLine("0 = Wyjście z programu");
  42.  
  43. }
  44. static osoba wczytajOsobe()//wczytywanie danych osób
  45. {
  46. osoba os1;
  47. Console.Write("Podaj nazwisko: ");
  48. os1.nazwisko = Console.ReadLine();
  49. Console.Write("Podaj imie: ");
  50. os1.imie = Console.ReadLine();
  51. Console.Write("Podaj wiek: ");
  52. os1.wiek = Console.ReadLine();
  53. return os1;
  54. }
  55. static void pokazOsobe(osoba osX)//pokazanie osoby
  56. {
  57. Console.WriteLine("Dane wprowadzonej osoby: \nNazwisko i imię: {0} {1} , Wiek: {2}", osX.nazwisko, osX.imie, osX.wiek);
  58.  
  59. }
  60. static void ProgramGotowy()// program do wczytywania osób
  61. {
  62. string aaa;
  63. int dlugosc;
  64. Console.Write("Podaj długość listy: ");
  65. while (true)
  66. {
  67. aaa = Console.ReadLine();
  68. if (int.TryParse(aaa, out dlugosc))
  69. {
  70. break;
  71. }
  72. else
  73. Console.WriteLine("Podaj cyfre");
  74. }
  75.  
  76. osoba[] listaOsob = new osoba[dlugosc];
  77. osoba osg;
  78. int a = 0;
  79. // wczytanie do listy osób danych z klawiatury w pętli for
  80. for (int i = 0; i < dlugosc; i++)
  81. {
  82. a = i + 1;
  83. Console.WriteLine("Osoba numer " + a);
  84. listaOsob[i] = wczytajOsobe();
  85.  
  86. }
  87. //Wyświetlenie listy osób
  88.  
  89. foreach (osoba ludzik in listaOsob)
  90. pokazOsobe(ludzik);
  91.  
  92. Console.ReadKey();
  93. }
  94. static void UruchomProgram()//uruchamianie programu
  95. {
  96. while (true)
  97. {
  98. WyswietlMenu();
  99. int opcja = WybierzOpcje();
  100. switch (opcja)
  101. {
  102. case 0:
  103. return;
  104.  
  105. case 1:
  106. ProgramGotowy();
  107. break;
  108. default:
  109. Console.WriteLine("Wprowadź co innego");
  110. Console.WriteLine(" ");
  111. break;
  112. }
  113. }
  114.  
  115. }
  116. static void Main(string[] args)
  117. {
  118. UruchomProgram();
  119. Console.ReadKey();
  120. }
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement