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 HomeWork
- {
- class Program
- {
- static void write(List<string> brothers)
- {
- int db = 1;
- foreach (string x in brothers)
- {
- if (db == brothers.Count) Console.Write("{0} ", x);
- else
- {
- Console.Write("{0}, ", x);
- db++;
- }
- }
- }
- //
- static void write2(List<string> child)
- {
- int db = 1;
- foreach (string x in child)
- {
- if (db == child.Count) Console.Write("{0} ", x);
- else
- {
- Console.Write("{0}, ", x);
- db++;
- }
- }
- }
- static void Main(string[] args)
- {
- Console.Write("Főbb adatok: ");
- People p = new People { Name = "Lajos", Age = 1950, Sex = "female" };
- Console.WriteLine("{0}, {1}", p.Name, p.Age);
- Console.WriteLine("Apja neve: István");
- Console.Write("Anyja neve: Anna");
- Console.WriteLine();
- Console.Write("Testvére(k): ");
- p.setbrothers("Ibolya");
- p.setbrothers("Géza");
- write(p.getbrothers());
- Console.WriteLine();
- Console.Write("Gyereke(k): ");
- p.setchild("Zalán");
- p.setchild("Tamara");
- p.setchild("Richárd");
- write2(p.getchild());
- Console.ReadLine();
- }
- }
- class People
- {
- public string Name;
- private int _age;
- public int Age
- {
- get { return _age; }
- set
- {
- if (value < 1900 || value > 2000)
- {
- throw new Exception("Hiba: rossz évszám!");
- }
- _age = value;
- }
- }
- private string _sex;
- public string Sex
- {
- get { return _sex; }
- set
- {
- if (value != "male" && value != "female")
- {
- throw new Exception("Hiba: rossz nem");
- }
- _sex = value;
- }
- }
- // testvérek
- private List <string> brothers = new List <string> ();
- public void setbrothers(string a)
- {
- int x = 0;
- for (int i = 0; i < brothers.Count; i++)
- {
- if (a == brothers[i]) x = 1;
- }
- if (a == "") x = 1;
- else if (a == null) x = 1;
- if (x == 0) brothers.Add(a);
- else throw new Exception("Nem lehet egyforma nevű testvér, se üres érték!");
- }
- public List <string> getbrothers()
- {
- return brothers;
- }
- // gyerekek
- private List<string> child = new List<string>();
- public void setchild(string a)
- {
- int x = 0;
- for (int i = 0; i < child.Count; i++)
- {
- if (a == child[i]) x = 1;
- }
- if (a == "") x = 1;
- else if (a == null) x = 1;
- if (x == 0) child.Add(a);
- else throw new Exception("Nem lehet egyforma nevű gyerek, se üres érték!");
- }
- public List<string> getchild()
- {
- return child;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment