Пример #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("====================TASK 1====================");
            StudentClass studentClassA = new StudentClass {
                ExcellentPupils = 10, GoodPupils = 14, MediocrePupils = 4
            };
            StudentClass studentClassB = new StudentClass {
                ExcellentPupils = 8, GoodPupils = 12, MediocrePupils = 5
            };
            StudentClass studentClassC = new StudentClass {
                ExcellentPupils = 12, GoodPupils = 7, MediocrePupils = 8
            };

            int excellectQty = studentClassB.ExcellentPupils + studentClassB.ExcellentPupils + studentClassC.ExcellentPupils;
            int goodQty      = studentClassB.GoodPupils + studentClassB.GoodPupils + studentClassC.GoodPupils;
            int mediocreQty  = studentClassB.MediocrePupils + studentClassB.MediocrePupils + studentClassC.MediocrePupils;

            Console.WriteLine("==Pupils sorted by grades");
            Console.WriteLine($"Excellent pupils: {excellectQty}");
            Console.WriteLine($"Good pupils: {goodQty}");
            Console.WriteLine($"Mediocre pupils: {mediocreQty}\n");

            Program program = new Program();

            Console.WriteLine("==Class A:");
            program.PrintStudentClassSummary(studentClassA);
            Console.WriteLine("==Class B:");
            program.PrintStudentClassSummary(studentClassB);
            Console.WriteLine("==Class C:");
            program.PrintStudentClassSummary(studentClassC);

            Console.WriteLine("\n==All Classes:");
            program.PrintAllClassesSummary(excellectQty, goodQty, mediocreQty);
            Console.WriteLine();

            Console.WriteLine("====================TASK 2====================");
            while (true)
            {
                Console.Write("Enter your number: ");
                string numberStr = Console.ReadLine();
                if (int.TryParse(numberStr, out int number))
                {
                    Console.WriteLine($"Is number even: {program.IsNumberEven(number)}");
                    break;
                }
            }
            Console.WriteLine();

            Console.WriteLine("====================TASK 3====================");
            bool flag;
            int  numA, numB, numC;

            Console.WriteLine("Enter three numbers:");
            Console.Write("1st(A): ");
            do
            {
                flag = program.GetIntNumberFromInput(out numA);
            } while(!flag);
            Console.Write("2nd(B): ");
            do
            {
                flag = program.GetIntNumberFromInput(out numB);
            } while(!flag);
            Console.Write("3rd(C): ");
            do
            {
                flag = program.GetIntNumberFromInput(out numC);
            } while(!flag);
            int[] nums = new[] { numA, numB, numC };
            Array.Sort(nums);
            Console.WriteLine($"{nums[0]} <= {nums[1]} <= {nums[2]}");
            Console.WriteLine();

            Console.WriteLine("====================TASK 4====================");
            int[] arr = { 1, 2, 3, 4, 1, 1, 4, 1, 5, 6, 6, 7, 4, 1, 2, 3, 5, 7, -12, 132, 415, 1 - 5, 1 - 5, 5, 15, 1, 5 - 1, 51, -16, 6 - 7, 415, 7, 415 };
            arr = program.GetDistinctValues(arr);
            foreach (var num in arr)
            {
                Console.WriteLine(num);
            }
            Console.WriteLine();

            Console.WriteLine("====================TASK 5====================");
            int[,] initialMatrix =
            {
                { 1, 2, 3, 4, 5 },
                { 1, 2, 3, 4, 5 },
                { 1, 2, 3, 4, 5 },
                { 1, 2, 3, 4, 5 }
            };

            int[,] transposedMatrix = program.GetTransposedMatrix(initialMatrix);
            for (int i = 0; i < transposedMatrix.GetLength(0); i++)
            {
                for (int j = 0; j < transposedMatrix.GetLength(1); j++)
                {
                    Console.Write($"{transposedMatrix[i, j]} ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();

            Console.WriteLine("====================TASK 6====================");
            double numDbl = -13214.5423643;

            numDbl = program.RoundNumberToNDigits(numDbl, 4);
            Console.WriteLine(numDbl);
            Console.WriteLine();

            Console.WriteLine("====================TASK 7====================");
            try
            {
                Console.WriteLine($"Y1 = {program.EvaluateFormulaOne(-4.54)}");
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.WriteLine($"Y2 = {program.EvaluateFormulaTwo(41.51)}");
            Console.WriteLine();

            Console.WriteLine("====================TASK 8====================");
            Console.WriteLine(program.GetFirstTokenFromString("я-нехочу-делать-дз", '-'));
            Console.WriteLine();

            Console.WriteLine("====================TASK 9====================");
            int[] indices = program.GetPositionRangeOfStringInString("Lorem ipsum dolor sit amet", "amet");
            Console.WriteLine($"{indices[0]}-{indices[1]}");
            Console.WriteLine();

            Console.WriteLine("====================EXTRA TASK====================");
            Dictionary <int, int> valuesWithTwoOrMoreMatches = program.GetValuesWithMoreThanTwoMatchesWithLINQ(new [] { 1, 2, 3, 4, 1, 1, 4, 1, 5, 6, 6, 7, 4, 1, 2, 3, 5, 7, -12, 132, 415, 1 - 5, 1 - 5, 5, 15, 1, 5 - 1, 51, -16, 6 - 7, 415, 7, 415 });

            foreach (var key in valuesWithTwoOrMoreMatches.Keys)
            {
                Console.WriteLine($"{key}: {valuesWithTwoOrMoreMatches[key]}");
            }
        }
Пример #2
0
 // Task 1
 void PrintStudentClassSummary(StudentClass studentClass)
 {
     Console.WriteLine($"Excellent pupils: {studentClass.GetPupilsPercentageByMarks(studentClass.ExcellentPupils)}%");
     Console.WriteLine($"Good pupils: {studentClass.GetPupilsPercentageByMarks(studentClass.GoodPupils)}%");
     Console.WriteLine($"Mediocre pupils: {studentClass.GetPupilsPercentageByMarks(studentClass.MediocrePupils)}%");
 }