Ejemplo n.º 1
0
        private static void LoadArray(ref double[] array)
        {
            int?size = Reading.ReadInt("Vložte velikost pole");

            if (size != null)
            {
                if (size < 1)
                {
                    Console.WriteLine("Zadal jsi nekladne cislo pro velikost pole");
                    return;
                }
                array = new double[(int)size];
                for (int i = 0; i < size; i++)
                {
                    double?value = Reading.ReadDouble($"Array[{i}]");
                    if (value != null)
                    {
                        array[i] = (double)value;
                    }
                    else
                    {
                        Console.WriteLine("Nezadal jsi cislo");
                        break;
                    }
                }
            }
            else
            {
                Console.WriteLine("Nezadal jsi cislo");
                return;
            }
        }
Ejemplo n.º 2
0
        public void LoadStudents(int numberOfStudents)
        {
            students = new Student[numberOfStudents];
            for (int i = 0; i < numberOfStudents; i++)
            {
                string name   = Reading.ReadString("Zadej jmeno studenta");
                int?   number = Reading.ReadInt("Zadej cislo studenta");
                if (number != null)
                {
                    Console.WriteLine(faculties);
                    int?          typeOfFaculty = Reading.ReadInt("Zadej fakultu");
                    TypeOfFaculty faculty;
                    switch (typeOfFaculty)
                    {
                    case 1: faculty = TypeOfFaculty.FES; break;

                    case 2: faculty = TypeOfFaculty.FF; break;

                    case 3: faculty = TypeOfFaculty.FEI; break;

                    case 4: faculty = TypeOfFaculty.FCHT; break;

                    default: faculty = TypeOfFaculty.FEI; break;
                    }
                    students[i] = new Student(name, (int)number, faculty);
                    Console.WriteLine("--------------------------------");
                }
            }
            Console.WriteLine("Studenti byly nacteni");
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Finds the last occurance.
 /// </summary>
 public static void FindLastOccurance()
 {
     while (true)
     {
         try
         {
             int value = Reading.ReadInt(string.Format("Write the number you want to find"));
             if (FakeArray.ContainsValue(value))
             {
                 int index = 0; // Assigned, just so C# suts the hell up (since we already know, that there is index in the array)
                 foreach (var item in FakeArray)
                 {
                     if (item.Value == value)
                     {
                         index = item.Key;
                     }
                 }
                 Console.WriteLine("Index of value {0} is {1}", value, index);
             }
             else
             {
                 Console.WriteLine("There is no number like this in array");
             }
             break;
         }
         catch (Exception)
         {
             Console.WriteLine("Wrong input, try again...");
         }
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Finds the first occurance.
 /// </summary>
 public static void FindFirstOccurance()
 {
     while (true)
     {
         try
         {
             int value = Reading.ReadInt(string.Format("Write the number you want to find"));
             if (FakeArray.ContainsValue(value))
             {
                 foreach (var item in FakeArray)
                 {
                     if (item.Value == value)
                     {
                         Console.WriteLine("Index of value {0} is {1}", value, item.Key);
                         break;
                     }
                 }
             }
             else
             {
                 Console.WriteLine("There is no number like this in array");
             }
             break;
         }
         catch (Exception)
         {
             Console.WriteLine("Wrong input, try again...");
         }
     }
 }
Ejemplo n.º 5
0
        private static void nactiZKlavesnice()
        {
            Console.WriteLine();
            string  jmeno = Reading.ReadString("Zadej jméno");
            int     cislo = Reading.ReadInt("Zadej číslo");
            string  temp  = Reading.ReadString("Zadej fakultu (FEI, FES, FF, FCHT)");
            Fakulta fak   = 0;

            switch (temp)
            {
            case "FEI":
                fak = Fakulta.FEI;
                break;

            case "FES":
                fak = Fakulta.FES;
                break;

            case "FF":
                fak = Fakulta.FF;
                break;

            case "FCHT":
                fak = Fakulta.FCHT;
                break;

            default:
                //TODO
                break;
            }
            p.pole[p.pocetPrvku] = new Student(jmeno, cislo, fak);
            p.pocetPrvku++;
        }
Ejemplo n.º 6
0
        private static void PoleZKvesnice(int vel)
        {
            pole = new int[vel];

            for (int i = 0; i < vel; i++)
            {
                pole[i] = Reading.ReadInt($"Zadej {i+1} cislo: ");
            }
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            string name   = Reading.ReadString("Your name");
            int    age    = Reading.ReadInt("Your age");
            double points = Reading.ReadDouble("Points");
            char   grade  = Reading.ReadChar("Grade");

            Console.WriteLine('\n' + name + '\n' + age + '\n' + points + '\n' + grade);
        }
Ejemplo n.º 8
0
        private void ArrayReading(Studenti arrayOfStudents)
        {
            string  jmeno       = Reading.ReadString("Jméno");
            int     cislo       = Reading.ReadInt("Číslo");
            string  fakulta     = Reading.ReadString("Fakulta");
            Student tempStudent = new Student(jmeno, cislo, fakulta);

            arrayOfStudents.AddStudent(tempStudent);
        }
Ejemplo n.º 9
0
        public static Students CreateArrayOfStudents(Students students)
        {
            Student[] array = students.StudentsArray;
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = Reading.ReadInt();
            }

            return(array);
        }
Ejemplo n.º 10
0
        public static int[] CreateArray()
        {
            int[] array = new int[8];
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = Reading.ReadInt();
            }

            return(array);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Testuje funkčnost třídy
        /// </summary>
        public void DoIt()
        {
            int choice = 0;

            do
            {
                PrintMenu();
                choice = Reading.ReadInt("Zadej svoji volbu");
                ExecuteChoice(choice);
            } while (choice != 0);
        }
Ejemplo n.º 12
0
        private static int[] createArray()
        {
            int size = Reading.ReadInt(1, "Enter size of array: ");

            int[] arr = new int[size];
            for (int i = 0; i < size; i++)
            {
                arr[i] = Reading.ReadInt("Enter " + (i + 1) + ". element of array : ");
            }
            return(arr);
        }
Ejemplo n.º 13
0
 private int MenuDraw()
 {
     Console.WriteLine("Menu:");
     Console.WriteLine("1) Načtení studenta z klávesnice");
     Console.WriteLine("2) Výpis studentů na obrazovku");
     Console.WriteLine("3) Seřazení studentů podle čísla");
     Console.WriteLine("4) Seřazení studentů podle jména");
     Console.WriteLine("5) Seřazení studentů podle fakulty");
     Console.WriteLine("0) Konec programu");
     return(Reading.ReadInt("Zvolte číslo z nabídky"));
 }
Ejemplo n.º 14
0
        private static int[] NacteniPoleInt()
        {
            int pocetOpakovani = Reading.ReadInt("Pocet cteni");

            int[] pole = new int[pocetOpakovani];
            for (int i = 0; i < pocetOpakovani; i++)
            {
                Reading.ReadInt("Prvek číslo " + pocetOpakovani);
            }
            Console.WriteLine("");
            return(pole);
        }
Ejemplo n.º 15
0
        private static void NajitPosledniVyskyt(int[] pole)
        {
            int hledane = Reading.ReadInt("Hledane cislo");

            for (int i = pole.Length - 1; i >= 0; i--)
            {
                if (hledane == pole[i])
                {
                    Console.WriteLine("Hledane cislo je na indexu {0}", i);
                    return;
                }
            }
        }
Ejemplo n.º 16
0
 private static int PrintMenu()
 {
     Console.WriteLine("\nPress 1 for new array");
     Console.WriteLine("Press 2 for display array");
     Console.WriteLine("Press 3 for ascending sort of array");
     Console.WriteLine("Press 4 for descending sort of array");
     Console.WriteLine("Press 5 for find min in array");
     Console.WriteLine("Press 6 for find max in array");
     Console.WriteLine("Press 7 for find first occurence of entered value in array");
     Console.WriteLine("Press 8 for find last occurence of entered value in array");
     Console.WriteLine("Press 9 for exit\n");
     return(Reading.ReadInt("Enter your choice: "));
 }
Ejemplo n.º 17
0
        private static void findFirst(int[] array)
        {
            int searchedVal = Reading.ReadInt("Enter searched value: ");

            for (int i = 0; i < array.Length; i++)
            {
                if (array[i] == searchedVal)
                {
                    Console.WriteLine($"{searchedVal} found at {i + 1}. position");
                    return;
                }
            }
            Console.WriteLine($"{searchedVal} is not in array");
        }
Ejemplo n.º 18
0
        public static void FindNumberFirst(int[] array)
        {
            Console.Write("Najdi číslo");
            int numberToFind = Reading.ReadInt();

            for (int i = 0; i < array.Length; i++)
            {
                if (numberToFind == array[i])
                {
                    Console.WriteLine("První výskyt čísla " + numberToFind + " je na pozici " + i);
                    return;
                }
            }
            Console.WriteLine("Číslo " + numberToFind + " nenalezeno!");
        }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            while (true)
            {
                try {
                    Console.WriteLine("\n1. zadani pole \n2. vypis pole\n3. setrideni\n4. min hodnota\n5. prvni vyskyt\n6. posledni vyskyt\n7. konec\n");
                    int c = Reading.ReadInt($"Zadej moznost: ");
                    if (c == 1)
                    {
                        PoleZKvesnice(5);
                    }
                    else if (c == 2)
                    {
                        PoleVypis();
                    }
                    else if (c == 3)
                    {
                        PoleSetrid();
                    }
                    else if (c == 4)
                    {
                        PoleMin();
                    }
                    else if (c == 5)
                    {
                        PolePrvni();
                    }
                    else if (c == 6)
                    {
                        PolePosledni();
                    }
                    else
                    {
                        Console.WriteLine("Konec"); break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Vyvolana vyjimka. Konec.");
                    break;
                }
            }



            Console.ReadKey();
        }
Ejemplo n.º 20
0
        private static void PolePrvni()
        {
            if (pole != null)
            {
                int hledane = Reading.ReadInt($"Zadej hledane cislo: ");

                for (int i = 0; i < pole.Length; i++)
                {
                    if (hledane == pole[i])
                    {
                        Console.WriteLine($"Cislo {hledane} nalezeno na indexu {i}");
                        return;
                    }
                }
                Console.WriteLine($"Cislo {hledane} nenalezeno");
            }
        }
Ejemplo n.º 21
0
        private static int inputValues(string message)
        {
            int?number = null;

            do
            {
                try
                {
                    number = Reading.ReadInt(message);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            } while (number == null);

            return(number.Value);
        }
Ejemplo n.º 22
0
        static void Main(string[] args)
        {
            p = new Studenti();
            int c;

            do
            {
                Console.WriteLine("1) Načtení studentů z klávesnice");
                Console.WriteLine("2) Výpis studentů na obrazovku");
                Console.WriteLine("3) Seřazení studentů podle čísla");
                Console.WriteLine("4) Seřazení studentů podle jména");
                Console.WriteLine("5) Seřazení studentů podle fakulty");
                Console.WriteLine("0) Konec programu");

                c = Reading.ReadInt($"Zadej číslo");
                switch (c)
                {
                case 1:
                    nactiZKlavesnice();
                    break;

                case 2:
                    vypisStudenty();
                    break;

                case 3:
                    seradit(c);
                    break;

                case 4:
                    seradit(c);
                    break;

                case 5:
                    seradit(c);
                    break;

                default:
                    break;
                }
            } while (c != 0);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Vytvoří nového studenta
        /// </summary>
        /// <returns>Vrátí nového studenta</returns>
        private Student createStudent()
        {
            string  name;
            int     number;
            Faculty faculty;

            name   = Reading.ReadString("Zadej jméno");
            number = Reading.ReadInt("Zadej číslo");

            int numberFaculty;

            do
            {
                printFaculty();
                numberFaculty = Reading.ReadInt("Číslo fakulty");
            } while (numberFaculty < 0 || numberFaculty > countFaculty());

            faculty = getFacultyByPosition(numberFaculty);
            return(new Student(name, number, faculty));
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Adds the element.
        /// </summary>
        public static void AddElement()
        {
            int key;

            while (true)
            {
                try
                {
                    key = Reading.ReadInt(string.Format("Write an index to add/modify"));
                    if (key >= 0)
                    {
                        break;
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Wrong input, try again...");
                }
            }

            while (true)
            {
                try
                {
                    int value = Reading.ReadInt(string.Format("Write the value"));
                    if (FakeArray.ContainsKey(key))
                    {
                        FakeArray[key] = value;
                    }
                    else
                    {
                        FakeArray.Add(key, value);
                    }
                    break;
                }
                catch (Exception)
                {
                    Console.WriteLine("Wrong input, try again...");
                }
            }
        }
Ejemplo n.º 25
0
        static void Main(string[] args)
        {
            double[] array = new double[0];
            do
            {
                PrintMenu();
                switch (Reading.ReadInt("Vyberte možnost"))
                {
                case 1:
                    LoadArray(ref array);
                    break;

                case 2:
                    PrintArray(array);
                    break;

                case 3:
                    SortArray(array);
                    break;

                case 4:
                    FindMinValue(array);
                    break;

                case 5:
                    FindFirstValue(array);
                    break;

                case 6:
                    FindLastValue(array);
                    break;

                case 7:
                    Environment.Exit(0);
                    break;
                }
                Console.WriteLine("Pokračuj kliknutím");
                Console.ReadKey();
            } while (true);
        }
Ejemplo n.º 26
0
        public static void FindNumberLast(int[] array)
        {
            Console.Write("Najdi číslo");
            int numberToFind = Reading.ReadInt();
            int position     = -1;

            for (int i = 0; i < array.Length; i++)
            {
                if (numberToFind == array[i])
                {
                    position = i;
                }
            }
            if (position == -1)
            {
                Console.WriteLine("Číslo " + numberToFind + " nenalezeno!");
            }
            else
            {
                Console.WriteLine("Poslední výskyt čísla " + numberToFind + " je na pozici " + position);
            }
        }
Ejemplo n.º 27
0
        static void Main(string[] args)
        {
            int d = MathConventor.BinToDec(01011);
            //string q = MathConventor.DecToBin(20);
            //double? x1, x2;
            //bool b = ExtraMath.QuadraticEquation(1, 1, 1, out x1, out x2);
            Students     studenti = new Students(0);
            sortStudents sortStudents;

            do
            {
                studenti.PrintMenu();
                switch (Reading.ReadInt("Vyberte možnost"))
                {
                case 1:
                    int?numberOfStudents = Reading.ReadInt("Zadej pocet studentu");
                    if (numberOfStudents != null)
                    {
                        studenti.LoadStudents((int)numberOfStudents);
                    }
                    else
                    {
                        Console.WriteLine("Nezadal jste platne cislo");
                    }
                    break;

                case 2: studenti.PrintStudents(); break;

                case 3: sortStudents = studenti.CompareByNumber; studenti.BubbleSortStudents(sortStudents); break;

                case 4: sortStudents = studenti.CompareByName; studenti.BubbleSortStudents(sortStudents); break;

                case 5: sortStudents = studenti.CompareByFaculty; studenti.BubbleSortStudents(sortStudents); break;

                case 6: Environment.Exit(0); break;
                }
            } while (true);
        }
Ejemplo n.º 28
0
        static void Main(string[] args)
        {
            while (run)
            {
                Console.Clear();

                Console.WriteLine("Menu");
                Console.WriteLine("1. Zadání prvku z klávesnice");
                Console.WriteLine("2. Vložení náhodných hodnot");
                Console.WriteLine("3. Výpis pole na obrazovku");
                Console.WriteLine("4. Utřídění pole vzestupně");
                Console.WriteLine("5. Utřídění pole sestupně");
                Console.WriteLine("6. Hledání minimálního prvku");
                Console.WriteLine("7. Hledání prvního výskytu zadaného čísla");
                Console.WriteLine("8. Hledání posledního výskytu zadaného čísla");
                Console.WriteLine("9. Konec programu");
                int option = Reading.ReadInt("\nZadejte možnost");

                switch (option)
                {
                case 1:
                    Console.Clear();
                    list.Add(Reading.ReadInt("Hodnota"));
                    if (list.Count - 1 < 10)
                    {
                        Console.WriteLine($"Prvek {list[list.Count - 1]} vložen na index 0{list.Count - 1}");
                    }
                    else
                    {
                        Console.WriteLine($"Prvek {list[list.Count - 1]} vložen na index {list.Count - 1}");
                    }
                    Console.ReadKey();
                    break;

                case 2:
                    for (int i = 0; i < 1000; i++)
                    {
                        list.Add(rand.Next(0, 9999));
                    }
                    break;

                case 3:
                    Console.Clear();
                    PrintField();
                    Console.ReadKey();
                    break;

                case 4:
                    Console.Clear();
                    Descending();
                    Console.ReadKey();
                    break;

                case 5:
                    Console.Clear();
                    Ascending();
                    Console.ReadKey();
                    break;

                case 6:
                    Console.Clear();
                    FindMinimum();
                    Console.ReadKey();
                    break;

                case 7:
                    Console.Clear();
                    FirstOccurrence(Reading.ReadInt("hodnota"));
                    Console.ReadKey();
                    break;

                case 8:
                    Console.Clear();
                    LastOccurrence(Reading.ReadInt("hodnota"));
                    Console.ReadKey();
                    break;

                case 9:
                    run = false;
                    break;

                default:
                    Console.Clear();
                    Console.WriteLine("Špatná hodnota vstupu.");
                    Console.ReadKey();
                    break;
                }
            }
        }
Ejemplo n.º 29
0
        public void Run()
        {
            PrintMenu();
            while (true)
            {
                try {
                    var selectedMenu = Reading.ReadInt("Please enter number from menu");
                    switch (selectedMenu)
                    {
                    case 1:
                        EnterNewDoubleToConsole(ref _fieldOfDoubles, ref _position);
                        break;

                    case 2:
                        PrintNumbersFromField(_fieldOfDoubles);
                        break;

                    case 3:
                        try {
                            SortUtils.CocktailSortAscending(_fieldOfDoubles);
                        }
                        catch (Exception e) {
                            WriteLineColorRed(e.Message);
                        }

                        break;

                    case 4:
                        try {
                            SortUtils.CocktailSortDescending(_fieldOfDoubles);
                        }
                        catch (Exception e) {
                            WriteLineColorRed(e.Message);
                        }
                        break;

                    case 5:
                        FindMinInArrayAndPrintToConsole(_fieldOfDoubles);
                        break;

                    case 6:
                        FindFirstOccurenceOfNumberAndPrintToConsole(_fieldOfDoubles);
                        break;

                    case 7:
                        FindLastOccurenceOfNumberAndPrintToConsole(_fieldOfDoubles);
                        break;

                    case 8:
                        PrintMenu();
                        break;

                    case 9:
                        Console.WriteLine("Exiting!");
                        return;

                    default:
                        WriteLineColorRed("Unknown command!");
                        break;
                    }
                }
                catch (Exception e) {
                    WriteLineColorRed(e.Message);
                }
            }
        }