예제 #1
0
        public static void Run_Fancy()
        {
            var scores = new List <double>();

            for (double s = ConsoleRead.ReadDouble(); s != -1; s = ConsoleRead.ReadDouble())
            {
                scores.Add(s);
            }
            double avg       = scores.Average();
            double threshold = 0.0001;

            for (int i = 0; i < scores.Count; i++)
            {
                string pos   = "";
                var    color = ConsoleColor.Yellow;

                if (scores[i] - threshold > avg)
                {
                    pos   = "ABOVE ";
                    color = ConsoleColor.Green;
                }
                else if (scores[i] + threshold < avg)
                {
                    pos   = "BELOW ";
                    color = ConsoleColor.Red;
                }

                ConsoleWrite.WriteLinesColored(color, $"{scores[i]:f2} {pos}AVERAGE");
            }
        }
예제 #2
0
        static void Fibonachy()
        {
            Console.WriteLine("\n\tFibonachy\n\n");
            int num = ConsoleRead.Int("Imput count elements: ");

            int[] fibonachi = new int[num];
            for (int i = 0; i < num; i++)
            {
                int k = i - 2;
                if (k < 0)
                {
                    fibonachi[i] = i;
                }
                else
                {
                    fibonachi[i] = fibonachi[i - 1] + fibonachi[k];
                }
            }
            Console.WriteLine($"\nFibonachi array:\n");
            for (int i = 0; i < num; i++)
            {
                Console.Write(fibonachi[i] + " ");
            }
            StartMenu.EnterClearConsole();
        }
예제 #3
0
        public static void Run()
        {
            var scores = new List <double>();

            for (double s = ConsoleRead.ReadDouble(); s != -1; s = ConsoleRead.ReadDouble())
            {
                scores.Add(s);
            }
            double avg       = scores.Average();
            double threshold = 0.0001;//This is to avoid floating point errors

            for (int i = 0; i < scores.Count; i++)
            {
                if (scores[i] - threshold > avg)
                {
                    Console.WriteLine($"{scores[i]:f2} ABOVE AVERAGE");
                }
                else if (scores[i] + threshold < avg)
                {
                    Console.WriteLine($"{scores[i]:f2} BELOW AVERAGE");
                }
                else
                {
                    Console.WriteLine($"{scores[i]:f2} AVERAGE");
                }
            }
        }
예제 #4
0
        static void Progressions()
        {
            Console.WriteLine("\n\tArithmetic and Geometric progression\n\n");

            int startNum  = ConsoleRead.Int("Input start num: ");
            int increment = ConsoleRead.Int("Input increment: ");
            int countNum  = ConsoleRead.Int("Input number of elements: ");

            int[] arrA = new int[countNum];
            int[] arrG = new int[countNum];

            arrA[0] = startNum;
            arrG[0] = startNum;

            for (int i = 1; i < countNum; i++)
            {
                arrA[i] = arrA[i - 1] + increment;
                arrG[i] = arrG[i - 1] * increment;
            }

            Kiselev_Andrey.Array.Print(arrA, "Arithmetic progression:");
            Kiselev_Andrey.Array.Print(arrG, "Geometric progression:");

            StartMenu.EnterClearConsole();
        }
예제 #5
0
        public static void Run()
        {
            int num = ConsoleRead.ReadInt32();

            for (int i = 1; i < 10; i++)
            {
                Console.WriteLine($"{i} times {num} is {i * num}");
            }
        }
예제 #6
0
파일: StartUp.cs 프로젝트: vesy53/SoftUni
        private static void Main()
        {
            IReader reader = new ConsoleRead();
            IWriter writer = new ConsoleWriter();

            Engine engine = new Engine(reader, writer);

            engine.Run();
        }
예제 #7
0
        public string ReadLine()
        {
            var consoleRead = new ConsoleRead();

            UserDataOutput = consoleRead;
            Status         = EnumProcessStatus.WaitingForUserData;
            Hibernate();

            return(UserDataInput?.ToString());
        }
예제 #8
0
        static void Main(string[] args)
        {
            var building = new Building();
            var input    = new ConsoleRead();
            var output   = new ConsoleWrite();

            Engine gameEngine = new Engine(building, input, output);

            gameEngine.Run();
        }
        public static void Run_LINQ()  //This one is not as good as the above running total, but it does show how cool LINQ can be
        {
            var nums = new List <int>();

            for (int i = ConsoleRead.ReadInt32(); i != -1; i = ConsoleRead.ReadInt32())
            {
                nums.Add(i);
            }
            Console.WriteLine($"Sum: {nums.Sum()}");
            Console.WriteLine($"Average: {nums.Average():f2}");
        }
        public static void Run()
        {
            Console.WriteLine("Enter an integer");
            int num1 = ConsoleRead.ReadInt32();

            Console.WriteLine("Enter another integer");
            int num2 = ConsoleRead.ReadInt32();

            Console.WriteLine($"{num1} + {num2} = {num1 + num2}");
            Console.WriteLine($"{num1} - {num2} = {num1 - num2}");
            Console.WriteLine($"{num1} x {num2} = {num1 * num2}");
        }
예제 #11
0
 static void Main()
 {
     while (true)
     {
         string[] command = ConsoleRead.CommandInput();
         object   value   = CommandReader.FunctionCall(command[0], command);
         if (value != null)
         {
             Console.WriteLine($"Got -> {value}");
         }
     }
 }
예제 #12
0
        public static void ProgramStart()
        {
            string ConsoleRead;

            Console.WriteLine("Please type month and day on the Input line.");
            Console.WriteLine("For example, if you want to see the solution for the 20th May, type 'May Day20'");
            Console.Write("Input: ");
            ConsoleRead = Console.ReadLine();
            string[] temp = ConsoleRead.Split(' ');

            InvokeStringMethod(temp[0], temp[1]);
        }
예제 #13
0
        public static void Run()
        {
            Console.WriteLine("Enter item name");
            string itemName = Console.ReadLine();

            Console.WriteLine("Enter item price");
            double itemPrice = ConsoleRead.ReadDouble();

            Console.WriteLine("Enter quantity");
            int quant = ConsoleRead.ReadInt32();

            Console.WriteLine($"{quant} x {itemName} @ {itemPrice:c2} Total: {itemPrice * quant:c2}");
        }
예제 #14
0
        //This exercise can be a really cool one to try without Linq or using any sorting libraries, and try to sort your own array.
        //It's a really deep rabbit hole! But a great learning opportunity. Sorting an array in a naive (slow) way is within your abilty by this point, and if you're interested, you can follow sorting algorithms a long way!
        public static void Run()
        {
            var nums = new List <int>();

            for (int n = ConsoleRead.ReadInt32(); n != -1; n = ConsoleRead.ReadInt32())
            {
                nums.Add(n);
            }
            foreach (int n in nums.OrderBy(x => x))
            {
                Console.WriteLine(n);
            }
        }
        public static void Run()
        {
            int count = 0;
            int sum   = 0;

            for (int i = ConsoleRead.ReadInt32(); i != -1; i = ConsoleRead.ReadInt32())
            {
                sum += i;
                count++;
            }
            Console.WriteLine($"Sum: {sum}");
            Console.WriteLine($"Average: {sum/(double)count:f2}");
        }
        public static void Run()
        {
            int numNames = ConsoleRead.ReadInt32();
            var names    = new List <string>(numNames);

            for (int i = 0; i < numNames; i++)
            {
                names.Add(Console.ReadLine());
            }
            foreach (string n in names.OrderBy(x => x))
            {
                Console.WriteLine(n);
            }
        }
 public static void Run()
 {
     for (int i = ConsoleRead.ReadInt32(); i != -1; i = ConsoleRead.ReadInt32())
     {
         if (i < 50)
         {
             Console.WriteLine("FAIL");
         }
         else
         {
             Console.WriteLine("PASS");
         }
     }
 }
예제 #18
0
        static void Obratny()
        {
            Console.WriteLine("\n\tInverted num\n\n");
            int num = ConsoleRead.Int("Imput number: ");
            int res = 0, temp = num;

            while (temp != 0)
            {
                res  *= 10;
                res  += temp % 10;
                temp /= 10;
            }
            Console.WriteLine($"Inverted number: {res}");
            StartMenu.EnterClearConsole();
        }
예제 #19
0
        public static void Run()
        {
            string itemName  = Console.ReadLine();
            double itemPrice = ConsoleRead.ReadDouble();
            int    quant     = ConsoleRead.ReadInt32();

            Console.WriteLine($"{quant} x {itemName} @ {itemPrice:c2}");
            if (quant < 10)
            {
                Console.WriteLine($"Total: { itemPrice* quant:c2}");
            }
            else
            {
                Console.WriteLine($"Subtotal: { itemPrice * quant:c2}");
                Console.WriteLine($"-10% Discount: {itemPrice * quant * 0.1:c2}");//Yes, you can store this in a variable and subtract it in the next step, but there's not really any need
                Console.WriteLine($"Total: { itemPrice * quant * 0.9:c2}");
            }
        }
예제 #20
0
        public void Run()
        {
            ConsoleRead  consoleRead  = new ConsoleRead();
            ConsoleWrite consoleWrite = new ConsoleWrite();
            CreateBlobs  createBlob   = new CreateBlobs();
            Attacking    attacking    = new Attacking();
            Data         data         = new Data();

            string input = "";

            while (input != "drop")
            {
                input = consoleRead.Read();

                string[] commant = input.Split();

                if (commant[0] == "create")
                {
                    string name     = commant[1];
                    int    health   = Int32.Parse(commant[2]);
                    int    damage   = Int32.Parse(commant[3]);
                    string behavior = commant[4];
                    string attack   = commant[5];

                    data.AddBlob(createBlob.Create(name, health, damage, behavior, attack));
                }
                else if (commant[0] == "attack")
                {
                    attacking.Attack(data.Blobs, commant[1], commant[2]);
                }
                else if (commant[0] == "status")
                {
                    consoleWrite.WriteList(data.Blobs);
                }
                else if (commant[0] == "pass")
                {
                }
                else if (commant[0] == "drop")
                {
                    Environment.Exit(0);
                }
            }
        }