Exemplo n.º 1
0
 //  end of properties
 //  constructor
 public Siblings(Person person, Person[] personArray)
 {
     IdPerson = person.IdPerson;
     IdMother = person.IdMother;
     IdFather = person.IdFather;
     IdTest   = person.IdPerson;
     FindOutRealation(person, personArray);
 }
Exemplo n.º 2
0
 public static void CreateNewPerson(int idPerson, string name, string lastName, 
     bool gender, int age, bool married, string proffesion, 
     int idMother, string motherName, int idFather, string fatherName)
 {
     int i = PersonArray.Length ;
     Array.Resize<Person>(ref PersonArray, i + 1);
     PersonArray[i] = new Person(idPerson, name, lastName,
         gender, age, married, proffesion,
         idMother, motherName, idFather, fatherName);
     output(PersonArray[i].IdPerson + " " + PersonArray[i].Name + " " + PersonArray[i].LastName);
 }
Exemplo n.º 3
0
 public static void FindOutRelationWithSiblinds(Person person, Person[] personArray)
 {
     output("          " + person.Name + " " + person.LastName);
     Siblings siblings = new Siblings(person, personArray);
 }
Exemplo n.º 4
0
        public void FindParentsBasedOnPerson(Person person)
        {
            if (person.MotherName == null)
                Console.WriteLine("Can't find no mother based on person id!");
            else
                Console.WriteLine("Find mother based on person id! Mother name: " + person.MotherName);

            if (person.FatherName == null)
                Console.WriteLine("Can't find no father based on person id!");
            else
                Console.WriteLine("Find father based on person id! Father name: " + person.FatherName);
        }
Exemplo n.º 5
0
        public void OutputSiblings(HashtableEx siblings, string childRelation, Person[] array)
        {
            int h = siblings.values.Count;
            if (h > 0)
            {
                Console.Write("\n-----------------------------\n");

                Console.Write("\n" + childRelation + "\n");
                for (int i = 0; i < h; i++)
                {
                    int i = 0;
                    //object[] ar = new object[0];
                    //ar[i] = Convert.ToInt32(siblings.Get("barn"));
                    foreach (int item in ar)

                        //Console.WriteLine(siblings.Get("barn").ToString());
                        //Console.ReadLine();

                        foreach (Person per in array)
                        {
                            if (item == per.IdPerson)
                            {
                                string gender = per.Gender == true ? "woman" : "man";
                                Console.Write("\n         Id: " + per.IdPerson);
                                Console.Write("\n       Name: " + per.Name + " " + per.LastName);
                                Console.Write("\n     Gender: " + gender);
                                Console.Write("\n     Mother: " + FindName(per.IdMother, array));
                                Console.Write("\n     Father: " + FindName(per.IdFather, array) + "\n");

                            }   //  end of if
                        }   //  end of foreach
                }   //  end of foreach
            }   //  end of if
        }
Exemplo n.º 6
0
 public int[] FindParents(Person[] array)
 {
     int[] parentsId = new int[0];
     int i = 0;
     foreach (Person item in array)
     {
         if (item.IdPerson == IdPerson)
         {
             if (IdMother == item.IdMother)
             {
                 Array.Resize<int>(ref parentsId, i + 1);
                 parentsId[i] = item.IdMother;
                 i++;
             }   //  end of if
             if (IdFather == item.IdFather)
             {
                 Array.Resize<int>(ref parentsId, i + 1);
                 parentsId[i] = item.IdFather;
                 i++;
             }   //  end of if
         }   //  end of if
     }   //  end of foreach
     return parentsId;
 }
Exemplo n.º 7
0
        public void FindParentsBasedOnParent(Person parentPerson, Person[] everyPerson)
        {
            string parentGender = "";

            if (parentPerson.Gender)
                parentGender = "mother";
            else
                parentGender = "father";

            foreach (Person itemPerson in everyPerson)
            {
                if (parentPerson.IdPerson == itemPerson.IdMother && itemPerson.IdPerson != IdPerson)
                    Console.WriteLine("Find " + parentGender + " based on her id! The" + parentGender + " name is: " + parentPerson.Name);
            }
        }
Exemplo n.º 8
0
 //public void OutputSiblings(int[] siblings, string childRelation, Person[] array)
 //{
 //    if (siblings.Length > 0)
 //    {
 //        Console.Write("\n-----------------------------\n");
 //        Console.Write("\n" + childRelation + "\n");
 //        foreach (int item in siblings)
 //        {
 //            foreach (Person per in array)
 //            {
 //                if (item == per.IdPerson)
 //                {
 //                    string gender = per.Gender == true ? "woman" : "man";
 //                    Console.Write("\n         Id: " + per.IdPerson);
 //                    Console.Write("\n       Name: " + per.Name + " " + per.LastName);
 //                    Console.Write("\n     Gender: " + gender);
 //                    Console.Write("\n     Mother: " + FindName(per.IdMother, array));
 //                    Console.Write("\n     Father: " + FindName(per.IdFather, array) + "\n");
 //                }   //  end of if
 //            }   //  end of foreach
 //        }   //  end of foreach
 //    }   //  end of if
 //}   //  end of OutputSiblings()
 public string FindName(int id, Person[] array)
 {
     string result = "";
     foreach (Person per in array)
     {
         if (id == per.IdPerson)
             result = per.Name + " " + per.LastName;
     }   //  end of foreach
     return result;
 }
Exemplo n.º 9
0
        public void FindOutRealation(Person person, Person[] array)
        {
            /*
            HashtableEx ht = new HashtableEx();

            ht["hello"] = "world";

            Console.WriteLine("Value of \"hello\": {0}", ht["hello"]);
            Console.WriteLine("Type of \"hello\": {0}", ht["hello"].GetType());

            Console.ReadKey();
            */
            //HashtableEx ht = new HashtableEx();
            //------------- looking down -----------
            int[] barnId = new int[0];
            int[] barnbarnId = new int[0];
            int[] barnbarnsbarnId = new int[0];
            int[] barnbarnsbarnbarnId = new int[0];
            int[] barnbarnsbarnbarnsbarnId = new int[0];

            barnId = FindChildren(array);
            //myHT["barn"] = FindChildren(array);
            //OutputSiblings(myHT, "          barn: " + barnId.Length, array);

            //OutputSiblings(barnId, "          barn: " + barnId.Length, array);
            //barnbarnId = FindGrandChildren(barnId, array);
            myHT["barnbarn"] = FindGrandChildren(myHT, array);
            //OutputSiblings(barnbarnId, "        barnbarn: " + barnbarnId.Length, array);
            //barnbarnsbarnId = FindGrandChildren(barnbarnId, array);
            //OutputSiblings(barnbarnsbarnId, "     barnbarns barn: " + barnbarnsbarnId.Length, array);
            //barnbarnsbarnbarnId = FindGrandChildren(barnbarnsbarnId, array);
            //OutputSiblings(barnbarnsbarnbarnId, "   barnbarns barnbarn: " + barnbarnsbarnbarnId.Length, array);
            //barnbarnsbarnbarnsbarnId = FindGrandChildren(barnbarnsbarnbarnId, array);
            //OutputSiblings(barnbarnsbarnbarnsbarnId, "barnbarns barnbarns barn: " + barnbarnsbarnbarnsbarnId.Length, array);

            //------------- looking up -------------

            int[] parentsId = new int[0];
            int[] grandParentsId = new int[0];
            int[] grandGrandParentsId = new int[0];
            int[] grandGrandGrandParentsId = new int[0];

            parentsId = FindParents(array);
            OutputSiblings(parentsId, "         Parents:", array);
            grandParentsId = FindGrandParents(parentsId, array);
            OutputSiblings(grandParentsId, "      Grand Parents:", array);
            grandGrandParentsId = FindGrandParents(grandParentsId, array);
            OutputSiblings(grandGrandParentsId, "   Grandgrand Parents:", array);
            grandGrandGrandParentsId = FindGrandParents(grandGrandParentsId, array);
            OutputSiblings(grandGrandGrandParentsId, "Grandgrandgrand Parents:", array);
        }
Exemplo n.º 10
0
        public int[] FindGrandParents(int[] parents, Person[] array)
        {
            int i = 0;
            int[] grandParentsId = new int[0];

            foreach (int item in parents)
            {
                foreach (Person per in array)
                {
                    if (item == per.IdPerson)
                    {
                        //if (item == per.IdMother)
                        //{   //  IdPerson är pappa eller mamma till
                            Array.Resize<int>(ref grandParentsId, i + 1);
                            grandParentsId[i] = per.IdMother;
                            i++;
                        //}   //  end of if
                        //if (item == per.IdFather)
                        //{   //  IdPerson är pappa eller mamma till
                            Array.Resize<int>(ref grandParentsId, i + 1);
                            grandParentsId[i] = per.IdFather;
                            i++;
                        //}   //  end of if
                    }   //  end of if
                }   //  end of foreach
            }   //  end of foreach
            return grandParentsId;
        }
Exemplo n.º 11
0
 public HashtableEx FindGrandChildren(HashtableEx barnId, Person[] array)
 {
     //int i = 0;
     HashtableEx grandbarnId = new HashtableEx();
     int x = barnId.values.Count;
     //foreach (int item in barnId)
     for (int i = 0; i < x; i++)
     {
         int item = Convert.ToInt16(barnId.Get("barn"));
         foreach (Person per in array)
         {
             if (item != per.IdPerson)
                 if ((item == per.IdMother) || (item == per.IdFather))
                 {   //  IdPerson är pappa eller mamma till
                     //Array.Resize<int>(ref grandbarnId, i + 1);
                     grandbarnId[(int)per.IdPerson] = per.Name;
                     i++;
                 }   //  end of if
         }   //  end of foreach
     }   //  end of foreach
     return grandbarnId;
 }
Exemplo n.º 12
0
 public void FindChildrenBasedOnPerson(Person person, Person[] everyPerson)
 {
     string childGender = "";
     foreach (Person itemPerson in everyPerson)
     {
         if ((itemPerson.IdFather == person.IdPerson) || (itemPerson.IdMother == person.IdPerson))
         {
             childGender = ReturnChildrenGender(itemPerson.Gender);
             Console.WriteLine("Found " + childGender + " based on person id");
         }
     }
 }
Exemplo n.º 13
0
        public void FindChildrenBasedOnChild(Person childPerson, Person[] everyPerson)
        {
            int antalBoys  = 0;
            int antalGirls = 0;
            string childGender = "";

            foreach (Person itemPerson in everyPerson)
            {
                if ((childPerson.IdMother == itemPerson.IdMother && itemPerson.IdMother != IdPerson) ||
                     (childPerson.IdPerson == itemPerson.IdFather && itemPerson.IdFather != IdPerson))
                {
                    if (childPerson.Gender)
                        antalGirls++;
                    else
                        antalBoys++;
                    childGender = ReturnChildrenGender(childPerson.Gender);
                }
                int antalChildren       = antalGirls + antalBoys;
                string totalChildren    = "";
                string totalGirls       = "";
                string totalBoys        = "";

                if (antalChildren == 1)
                    totalChildren = "child";
                if (antalChildren > 1)
                    totalChildren = "children";
                if (antalGirls == 1)
                    totalGirls = "girl";
                if (antalGirls > 1)
                    totalGirls = "girls";
                if (antalBoys == 1)
                    totalBoys = "boy";
                if (antalBoys > 1)
                    totalBoys = "boys";

                if (antalGirls > 0)
                    totalGirls = "Found a " + antalGirls + " " + totalGirls;
                else
                    totalGirls = "";
                if (antalBoys > 0)
                    totalBoys = "Found a " + antalBoys + " " + totalBoys;
                else
                    totalBoys = "";

                if (antalChildren > 0)
                {
                    Console.WriteLine("Found a " + (antalChildren) + " " + totalChildren + " based on child! /n" +
                        totalGirls + "/n" + totalBoys);
                }
            }
        }
Exemplo n.º 14
0
 //public int[] FindGrandChildren(int[] barnId, Person[] array)
 //{
 //    int i = 0;
 //    int[] grandbarnId = new int[0];
 //    foreach (int item in barnId)
 //    {
 //        foreach (Person per in array)
 //        {
 //            if (item != per.IdPerson)
 //                if ((item == per.IdMother) || (item == per.IdFather))
 //                {   //  IdPerson är pappa eller mamma till
 //                    Array.Resize<int>(ref grandbarnId, i + 1);
 //                    grandbarnId[i] = per.IdPerson;
 //                    i++;
 //                }   //  end of if
 //        }   //  end of foreach
 //    }   //  end of foreach
 //    return grandbarnId;
 //}   //  end of FindGrandChildren()
 public int[] FindChildren(Person[] array)
 {
     int[] barnId = new int[0];
     int i = 0;
     foreach (Person item in array)
     {
         if (item.IdPerson != IdPerson)
         {
             if ((IdPerson == item.IdMother) || (IdPerson == item.IdFather))
             {   //  IdPerson är pappa eller mamma till
                 Array.Resize<int>(ref barnId, i + 1);
                 barnId[i] = item.IdPerson;
                 i++;
             }   //  end of if
         }   //  end of if
     }   //  end of foreach
     return barnId;
 }