Example #1
0
        static void Main(string[] args)
        {
            List <Teacher> teachers = new List <Teacher> {
                new Teacher("Anne", "Marie", 30, 83262, 5, "Biology"),
                new Teacher("Kate", "Winslet", 25, 938274, 8, "Mathematics"),
                new Teacher("Barbara", "Plavin", 26, 83737832, 10, "Gymnastics"),
                new Teacher("Obama", "Barack", 55, 983262, 2, "Politics")
            };

            List <Student> students = new List <Student> {
                new Student("Romee", "Strjid", 21, 98362, 2, "Informatics"),
                new Student("Viktor", "Orban", 25, 938274, 3, "Politics"),
                new Student("Ion", "Cruza", 26, 83737832, 4, "Architecture"),
                new Student("Jennifer", "Aniston", 40, 1983262, 6, "Drama"),
                new Student("Mariah", "Carry", 50, 1283262, 3, "Drama"),
                new Student("Tomas", "Kent", 18, 247262, 4, "Geography")
            };

            int option = 0;

            do
            {
                UserOptionSelection.ChooseOption(ref option);
                switch (option)
                {
                case 1:
                    foreach (Teacher teacher in teachers)
                    {
                        teacher.GetDetail();
                        ((Person)teacher).CareerPath();
                    }
                    break;

                case 2:
                    foreach (Student student in students)
                    {
                        student.GetDetail();
                        student.CareerPath();
                    }
                    break;
                }
                Console.WriteLine();
            } while (option != 3);
        }
        static void Main(string[] args)
        {
            //1.Problem
            List <string> teachers = new List <string> {
                "Mr.Poppins", "Ms.Jackson", "Mss. Blueberry", "Mr.Alabama"
            };
            List <string> students = new List <string> {
                "Alan", "Karen", "Bobby", "Vanessa", "Kate", "Lindsay"
            };

            int option = 0;

            do
            {
                UserOptionSelection.ChooseOption(ref option);
                switch (option)
                {
                case 1:
                    foreach (string teacher in teachers)
                    {
                        Console.WriteLine(teacher);
                    }
                    break;

                case 2:
                    foreach (string student in students)
                    {
                        Console.WriteLine(student);
                    }
                    break;
                }
                Console.WriteLine();
            } while (option != 3);

            //2.Problem
            List <int> listNumbers = new List <int> {
                1, 2, 4, 5, 2, 1, 50, 32
            };

            int[] arrayNumbers = { 72, 482, 462, 46, 29, 26, 35, 3 };
            Dictionary <string, int> dictionaryNumbers = new Dictionary <string, int> {
                { "cabbage", 1 }, { "corn", 472 }, { "apple", 5 }, { "beans", 94 }, { "pineapple", 88 }
            };

            Console.WriteLine($"Maximum of list: {listNumbers.Max()} and minimum: {listNumbers.Min()}");
            Console.WriteLine($"Maximum of array: {arrayNumbers.Max()} and minimum: {arrayNumbers.Min()}");
            Console.WriteLine($"Maximum of dictionary: {dictionaryNumbers.Values.Max()} and minimum: {dictionaryNumbers.Values.Min()}");

            Console.WriteLine();
            Console.WriteLine($"Sum of list: {listNumbers.Sum()}");
            Console.WriteLine($"Sum of array: {arrayNumbers.Sum()}");
            Console.WriteLine($"Sum of dictionary: {dictionaryNumbers.Values.Sum()}");

            Console.WriteLine();
            Console.WriteLine($"Count of prime numbers in list: {CountPrimeNumbers(listNumbers)}");
            int listPrimesCount = listNumbers.Where(num => IsPrime(num)).Count();

            Console.WriteLine($"Count of prime numbers in array: {CountPrimeNumbers(arrayNumbers)}");
            Console.WriteLine($"Count of prime numbers in dictionary: {CountPrimeNumbers(dictionaryNumbers)}");

            Console.WriteLine();
            Console.WriteLine($"Average of prime numbers in list: {AverageOfPrimes(listNumbers)}");
            double listPrimesAverage = listNumbers.Where(num => IsPrime(num)).Average();

            Console.WriteLine($"Average of prime numbers in array: {AverageOfPrimes(arrayNumbers)}");
            Console.WriteLine($"Average of prime numbers in dictionary: {AverageOfPrimes(dictionaryNumbers)}");

            //3.Problem
            int[,] identityMatrix = new int[15, 15];

            for (int i = 0; i < 15; i++)
            {
                for (int j = 0; j < 15; j++)
                {
                    identityMatrix[i, j] = (i == j) ? 1 : 0;
                }
            }
            Console.WriteLine();
            Console.WriteLine("Identity Matrix: ");
            Console.WriteLine(Matrix4x4.Identity);

            DisplayMatrix(identityMatrix, 15);

            //4.Problem
            int[,] a      = { { 1, 4, 2, 6 }, { 2, 5, 1, 6 }, { 1, 2, 3, 4 }, { 3, 5, 2, 6 } };
            int[,] b      = { { 3, 4, 2, 7 }, { 3, 5, 7, 8 }, { 1, 2, 1, 9 }, { 4, 6, 3, 7 } };
            int[,] result = MultiplyTwoMatrices(a, b, 4);

            Console.WriteLine();
            DisplayMatrix(a, 4);
            Console.WriteLine("\n   X   ");
            DisplayMatrix(b, 4);
            Console.WriteLine(" = ", Environment.NewLine);
            DisplayMatrix(result, 4);
            Console.WriteLine();

            //5.Problem
            List <string> players = new List <string> {
                "Szilvia", "Barbara", "Jennifer", "Romee", "Kate", "Cher", "Mr.Bean", "The Rock", "Snoop Dog", "Bilie Eilish"
            };
            Random random = new Random();
            int    num    = random.Next(0, 9);

            Console.WriteLine("The players are: ");
            foreach (string player in players)
            {
                Console.WriteLine($"{player}");
            }

            Console.WriteLine($"The winner is:{players[num]} ");
        }