Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace struktura
- {
- struct osoba
- {
- public string nazwisko;
- public string imie;
- public string wiek;
- }
- class Program
- {
- static int WybierzOpcje()//wybieranie opcji
- {
- int a = 0;
- string str;
- while (true)
- {
- Console.Write("Podaj Liczbę: ");
- str = Console.ReadLine();
- if (int.TryParse(str, out a))
- break;
- else
- Console.WriteLine("Wprowadź liczbę 1,2,0");
- }
- return a;
- }
- static void WyswietlMenu()//menu
- {
- Console.WriteLine("1 = Tworzenie listy osób ");
- Console.WriteLine("2 = ??????????? ");
- Console.WriteLine("0 = Wyjście z programu");
- }
- static osoba wczytajOsobe()//wczytywanie danych osób
- {
- osoba os1;
- Console.Write("Podaj nazwisko: ");
- os1.nazwisko = Console.ReadLine();
- Console.Write("Podaj imie: ");
- os1.imie = Console.ReadLine();
- Console.Write("Podaj wiek: ");
- os1.wiek = Console.ReadLine();
- return os1;
- }
- static void pokazOsobe(osoba osX)//pokazanie osoby
- {
- Console.WriteLine("Dane wprowadzonej osoby: \nNazwisko i imię: {0} {1} , Wiek: {2}", osX.nazwisko, osX.imie, osX.wiek);
- }
- static void ProgramGotowy()// program do wczytywania osób
- {
- string aaa;
- int dlugosc;
- Console.Write("Podaj długość listy: ");
- while (true)
- {
- aaa = Console.ReadLine();
- if (int.TryParse(aaa, out dlugosc))
- {
- break;
- }
- else
- Console.WriteLine("Podaj cyfre");
- }
- osoba[] listaOsob = new osoba[dlugosc];
- osoba osg;
- int a = 0;
- // wczytanie do listy osób danych z klawiatury w pętli for
- for (int i = 0; i < dlugosc; i++)
- {
- a = i + 1;
- Console.WriteLine("Osoba numer " + a);
- listaOsob[i] = wczytajOsobe();
- }
- //Wyświetlenie listy osób
- foreach (osoba ludzik in listaOsob)
- pokazOsobe(ludzik);
- Console.ReadKey();
- }
- static void UruchomProgram()//uruchamianie programu
- {
- while (true)
- {
- WyswietlMenu();
- int opcja = WybierzOpcje();
- switch (opcja)
- {
- case 0:
- return;
- case 1:
- ProgramGotowy();
- break;
- default:
- Console.WriteLine("Wprowadź co innego");
- Console.WriteLine(" ");
- break;
- }
- }
- }
- static void Main(string[] args)
- {
- UruchomProgram();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement