Hyluss

Ksiazka Telefoniczna

Mar 4th, 2017
318
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace qwertyuiqew
  7. {
  8.     class TKontakty
  9.     {
  10.         String Imie;
  11.         String Nazwisko;
  12.         String Telefon;
  13.         String Adres;
  14.  
  15.         public TKontakty()
  16.         {
  17.         }
  18.  
  19.         public TKontakty(String Im, String Na, String Tel, String Ad)
  20.         {
  21.             Imie = Im;
  22.             Nazwisko = Na;
  23.             Telefon = Tel;
  24.             Adres = Ad;
  25.         }
  26.  
  27.         public static TKontakty Nowy()
  28.         {
  29.             bool xd = true;
  30.             int cos;
  31.             String im, na, tel, ad;
  32.             TKontakty Kontakt;
  33.             Console.WriteLine("Podaj imie, nazwisko, numer, adres\n");
  34.             im = Console.ReadLine();
  35.             im = im.Trim();
  36.             na = Console.ReadLine();
  37.             do
  38.             {
  39.                 tel = Console.ReadLine();
  40.                 if (xd == Int32.TryParse(tel,out cos) ) break;
  41.                 Console.WriteLine("Podaj numer!");
  42.             } while (true);
  43.             tel = tel.Trim();
  44.             ad = Console.ReadLine();            
  45.             Kontakt = new TKontakty(im, na, tel, ad);
  46.             return Kontakt;
  47.         }
  48.  
  49.         public String ZwrocImie { get { return Imie; }  }
  50.  
  51.         public String ZwrocNazwisko { get { return Nazwisko; }  }
  52.  
  53.         public String ZwrocTelefon { get { return Telefon; }  }
  54.  
  55.         public String ZwrocAdres { get { return Adres; } }
  56.  
  57.     };
  58.  
  59.  
  60.     class Program
  61.     {
  62.         static void Main(string[] args)
  63.         {        
  64.             String ktory;
  65.             bool pl=true;
  66.             int l;
  67.             bool wyjdz =false;
  68.  
  69.             TKontakty[] tab;
  70.             tab = new TKontakty[10];
  71.  
  72.             for (int i = 0; i < tab.Length; i++)
  73.             {
  74.                 tab[i] = new TKontakty();
  75.             }
  76.  
  77.             do
  78.             {
  79.                 Console.WriteLine("Co chcesz zrobic?\nf1- dodaj kontakt\nf2 - usun kontakt\nf3 - zobacz kontakty\nf4 - usun wszystkie kontakty\nf5 - wyjdz z programu\n");
  80.                 ConsoleKey k;
  81.                 k = Console.ReadKey().Key;
  82.                 switch (k)
  83.                 {
  84.                     case ConsoleKey.F1:
  85.                         {
  86.                             for (int i = 0; i < tab.Length; i++)
  87.                             {
  88.                                 if (tab[i].ZwrocTelefon == null)
  89.                                 {
  90.                                     tab[i] = TKontakty.Nowy();
  91.                                     break;
  92.                                 }
  93.                                 if (tab[i].ZwrocTelefon == null && i==9) Console.WriteLine("Brak miejsca\n");
  94.                             }                            
  95.                             break;
  96.                         }
  97.                     case ConsoleKey.F2:
  98.                         {
  99.                             Console.WriteLine("Ktory kontakt usunac?\n");
  100.                             do
  101.                             {
  102.                                 ktory = Console.ReadLine();
  103.                                 if (pl == int.TryParse(ktory, out l) ) break;
  104.                             } while (true);
  105.                             tab[l - 1] = new TKontakty();
  106.                             break;
  107.                         }
  108.                     case ConsoleKey.F3:
  109.                         {
  110.                             for (int i = 0; i < tab.Length; i++)
  111.                             {
  112.                                 if (tab[i].ZwrocTelefon == null) Console.WriteLine("[{0}] - puste", i + 1);
  113.                                 else
  114.                                 {
  115.                                     Console.Write("[{0}] -", i+1);
  116.                                     Console.WriteLine (tab[i].ZwrocImie + " " + tab[i].ZwrocNazwisko + " " + tab[i].ZwrocTelefon + " " + tab[i].ZwrocAdres);
  117.                                 }
  118.                             }
  119.                             break;
  120.                         }
  121.                     case ConsoleKey.F4:
  122.                         {
  123.                             for (int i = 0; i < tab.Length; i++) tab[i] = new TKontakty();
  124.                             break;
  125.                         }
  126.  
  127.                     case ConsoleKey.F5:
  128.                         {
  129.                             wyjdz = true;
  130.                             break;
  131.                         }
  132.                 }
  133.             } while (wyjdz == false);
  134.  
  135.         }
  136.  
  137.  
  138.  
  139.     }
  140. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment