Guest User

Untitled

a guest
Feb 19th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.60 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 HomeWork
  8. {
  9.     class Program
  10.     {
  11.         static void write(List<string> brothers)
  12.         {
  13.             int db = 1;
  14.             foreach (string x in brothers)
  15.             {
  16.                 if (db == brothers.Count) Console.Write("{0} ", x);
  17.                 else
  18.                 {
  19.                     Console.Write("{0}, ", x);
  20.                     db++;
  21.                 }
  22.             }
  23.         }
  24.          //
  25.         static void write2(List<string> child)
  26.         {
  27.             int db = 1;
  28.             foreach (string x in child)
  29.             {
  30.                 if (db == child.Count) Console.Write("{0} ", x);
  31.                 else
  32.                 {
  33.                     Console.Write("{0}, ", x);
  34.                     db++;
  35.                 }
  36.             }
  37.         }
  38.         static void Main(string[] args)
  39.         {
  40.             Console.Write("Főbb adatok: ");
  41.             People p = new People { Name = "Lajos", Age = 1950, Sex = "female" };
  42.             Console.WriteLine("{0}, {1}", p.Name, p.Age);
  43.             Console.WriteLine("Apja neve: István");
  44.             Console.Write("Anyja neve: Anna");
  45.             Console.WriteLine();
  46.             Console.Write("Testvére(k): ");
  47.             p.setbrothers("Ibolya");
  48.             p.setbrothers("Géza");
  49.             write(p.getbrothers());
  50.             Console.WriteLine();
  51.             Console.Write("Gyereke(k): ");
  52.             p.setchild("Zalán");
  53.             p.setchild("Tamara");
  54.             p.setchild("Richárd");
  55.             write2(p.getchild());
  56.             Console.ReadLine();
  57.         }
  58.     }
  59.  
  60.     class People
  61.     {
  62.         public string Name;
  63.         private int _age;
  64.         public int Age
  65.         {
  66.             get { return _age; }
  67.             set
  68.             {
  69.                 if (value < 1900 || value > 2000)
  70.                 {
  71.                     throw new Exception("Hiba: rossz évszám!");
  72.                 }
  73.                 _age = value;
  74.             }
  75.         }
  76.         private string _sex;
  77.         public string Sex
  78.         {
  79.             get { return _sex; }
  80.             set
  81.             {
  82.                 if (value != "male" && value != "female")
  83.                 {
  84.                     throw new Exception("Hiba: rossz nem");
  85.                 }
  86.                 _sex = value;
  87.             }
  88.         }
  89.  
  90.         // testvérek
  91.  
  92.         private List <string> brothers = new List <string> ();
  93.         public void setbrothers(string a)
  94.         {
  95.             int x = 0;
  96.             for (int i = 0; i < brothers.Count; i++)
  97.             {
  98.                 if (a == brothers[i]) x = 1;
  99.             }
  100.             if (a == "") x = 1;
  101.             else if (a == null) x = 1;
  102.             if (x == 0) brothers.Add(a);
  103.             else throw new Exception("Nem lehet egyforma nevű testvér, se üres érték!");
  104.         }
  105.         public List <string> getbrothers()
  106.         {
  107.             return brothers;
  108.         }
  109.  
  110.         // gyerekek
  111.         private List<string> child = new List<string>();
  112.         public void setchild(string a)
  113.         {
  114.             int x = 0;
  115.             for (int i = 0; i < child.Count; i++)
  116.             {
  117.                 if (a == child[i]) x = 1;
  118.             }
  119.             if (a == "") x = 1;
  120.             else if (a == null) x = 1;
  121.             if (x == 0) child.Add(a);
  122.             else throw new Exception("Nem lehet egyforma nevű gyerek, se üres érték!");
  123.         }
  124.         public List<string> getchild()
  125.         {
  126.             return child;
  127.         }
  128.     }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment