Ejemplo n.º 1
0
        /// <summary>
        /// Main method
        /// </summary>
        /// <param name="args">The arguments.</param>
        public static void Main(string[] args)
        {
            try
            {
                string str = null;
                do
                {
                    Console.WriteLine("Enter 1 For Anagram Program");
                    Console.WriteLine("Enter 2 For Prime numbers");
                    Console.WriteLine("Enter 3 For Insertion Sort");
                    Console.WriteLine("Enter 4 For Bubble Sort");
                    Console.WriteLine("Enter 5 For Merge Sort");
                    Console.WriteLine("Enter 6 For Vending Machine");
                    Console.WriteLine("Enter 7 For Temperature");
                    Console.WriteLine("Enter 8 For Square Root");
                    Console.WriteLine("Enter 9 For Decimal to Binary");
                    Console.WriteLine("Enter 10 For Nibble");
                    Console.WriteLine("Enter 11 For Binary Search of integers");
                    Console.WriteLine("Enter 12 For Binary Search of strings");
                    Console.WriteLine("Enter 13 For Insertion Sort of integers");
                    Console.WriteLine("Enter 14 For Insertion sort of strings");
                    Console.WriteLine("Enter 15 For Bubble sort of integers");
                    Console.WriteLine("Enter 16 For Bubble sort of strings");
                    Console.WriteLine("Enter 17 For Anagram and palindrome of prime numbers");
                    Console.WriteLine("Enter 18 For Binary search");
                    int num = Convert.ToInt32(Console.ReadLine());

                    switch (num)
                    {
                    case 1:
                        Anagram a = new Anagram();
                        a.StringAnagram();
                        break;

                    case 2:
                        Primenumbers p = new Primenumbers();
                        p.Isprime();
                        break;

                    case 3:
                        InsertionSort ins = new InsertionSort();
                        ins.Sortingofstrings();
                        break;

                    case 4:
                        BubbleSort bs = new BubbleSort();
                        bs.Bubblesortofint();
                        break;

                    case 5:
                        MergeSort m = new MergeSort();
                        Console.WriteLine("enter size of array");
                        int      size  = Convert.ToInt32(Console.ReadLine());
                        string[] words = new string[size];
                        Console.WriteLine("enter strings in to array");
                        for (int k = 0; k < size; k++)
                        {
                            words[k] = Console.ReadLine();
                        }

                        m.Sort(words);
                        Console.WriteLine("sorted array");

                        foreach (string sortedArray in words)
                        {
                            Console.WriteLine(sortedArray);
                            Console.ReadLine();
                        }

                        break;

                    case 6:
                        VendingMachine v = new VendingMachine();
                        v.CountCurrency();
                        break;

                    case 7:
                        Temperature t = new Temperature();
                        t.TemperatureConversion();
                        break;

                    case 8:
                        SquareRoot sq = new SquareRoot();
                        sq.FindSquareRoot();
                        break;

                    case 9:
                        DecimaltoBinary db = new DecimaltoBinary();
                        db.ConversionofDecimal();
                        break;

                    case 10:
                        Nibble nb = new Nibble();
                        nb.ToBinary();
                        break;

                    case 11:
                        Console.WriteLine("Enter the size of Array:");
                        int   arraysize = Utility.Getinteger();
                        int[] arr       = new int[arraysize];
                        Console.WriteLine("Enter " + arraysize + " Elemenets");
                        for (int i = 0; i < arr.GetLength(0); i++)
                        {
                            arr[i] = Utility.Getinteger();
                        }

                        Console.WriteLine("Enter an item to search:");
                        int item = Utility.Getinteger();

                        Utility.BinarySearch(arr, item);
                        break;

                    case 12:
                        Console.WriteLine("Enter the size of Array:");
                        int      sizeStr = Utility.Getinteger();
                        string[] s       = new string[sizeStr];
                        Console.WriteLine("Enter " + sizeStr + " Elemenets");
                        for (int i = 0; i < s.GetLength(0); i++)
                        {
                            s[i] = Utility.GetString();
                        }

                        Console.WriteLine("Enter an item to search:");
                        string itemStr = Utility.GetString();
                        Utility.BinarySearch(s, itemStr);
                        break;

                    case 13:
                        Console.WriteLine("Enter the size of Array:");
                        int   sizeIns = Utility.Getinteger();
                        int[] arrIns  = new int[sizeIns];
                        Console.WriteLine("Enter " + sizeIns + " Elemenets");
                        for (int i = 0; i < arrIns.GetLength(0); i++)
                        {
                            arrIns[i] = Utility.Getinteger();
                        }

                        Utility.InsertionSort(arrIns);
                        break;

                    case 14:
                        Console.WriteLine("Enter the size of Array:");
                        int      strsize = Utility.Getinteger();
                        string[] strIns  = new string[strsize];
                        Console.WriteLine("Enter " + strsize + " Elemenets");
                        for (int i = 0; i < strIns.GetLength(0); i++)
                        {
                            strIns[i] = Utility.GetString();
                        }

                        Utility.InsertionSort(strIns);
                        break;

                    case 15:
                        Console.WriteLine("Enter the size of Array:");
                        int   sizeBubInt = Utility.Getinteger();
                        int[] arrBubInt  = new int[sizeBubInt];
                        Console.WriteLine("Enter " + sizeBubInt + " Elemenets");
                        for (int i = 0; i < arrBubInt.GetLength(0); i++)
                        {
                            arrBubInt[i] = Utility.Getinteger();
                        }

                        Utility.BubbleSort(arrBubInt);
                        break;

                    case 16:
                        Console.WriteLine("Enter the size of Array:");
                        int      strsizeBub = Utility.Getinteger();
                        string[] strBub     = new string[strsizeBub];
                        Console.WriteLine("Enter " + strsizeBub + " Elemenets");
                        for (int i = 0; i < strBub.GetLength(0); i++)
                        {
                            strBub[i] = Utility.GetString();
                        }

                        Utility.BubbleSort(strBub);
                        break;

                    case 17:
                        AnagramAndPalindrome Ap = new AnagramAndPalindrome();
                        Ap.PalindromeOfPrimeNumbers();
                        Ap.AnagramOfPrimeNumbers();
                        break;

                    case 18:
                        BinarySearch binarysearch = new BinarySearch();
                        binarysearch.ReadFile();
                        break;

                    default:
                        Console.WriteLine("Please enter the valid input");
                        Console.ReadLine();
                        break;
                    }
                }while(str != "n");
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Defines the entry point of the application.
        /// </summary>
        /// <param name="args">The arguments.</param>
        static void Main(string[] args)
        {
            Console.WriteLine("1: Anagram Detection");
            Console.WriteLine("2: Prime Numbers between 0-1000");
            Console.WriteLine("3: Prime Numbers that are Anagram or Palindrome (0-1000)");
            Console.WriteLine("4: Utility Class");
            Console.WriteLine("5: Find Number");
            Console.WriteLine("6: Binary Search");
            Console.WriteLine("7: Insertion Sort");
            Console.WriteLine("8: Bubble Sort");
            Console.WriteLine("9: Merge Sort");
            Console.WriteLine("10: Vending Machine");
            Console.WriteLine("11: Day of Week");
            Console.WriteLine("12: Temperature Conversion");
            Console.WriteLine("13: Monthly Payment");
            Console.WriteLine("14: Square Root");
            Console.WriteLine("15: To Binary");
            Console.WriteLine("16: Binary Swap Nibbles");
            int choice = 0;

            while (!(choice > 0 && choice < 17))
            {
                try
                {
                    Console.Write("Enter your choice: ");
                    choice = Convert.ToInt32(Console.ReadLine());
                }
                catch (FormatException)
                {
                    //Console.WriteLine(Ex);
                }
            }
            switch (choice)
            {
            case 1:
                AnagramDetection anagramDetection = new AnagramDetection();
                anagramDetection.anagram();
                break;

            case 2:
                PrimeNumbers primeNumbers = new PrimeNumbers();
                primeNumbers.prime();
                break;

            case 3:
                PrimeAnagramPalindrome primeAnagramPalindrome = new PrimeAnagramPalindrome();
                primeAnagramPalindrome.checkForPrimeAnagramPalindrome();
                break;

            case 4:
                int[] integerArray = { 10, 8, 7, 4, 3, 5, 0, 1, 2, 6, 9 };
                integerArray = Utility.BubbleSort(integerArray);
                Console.WriteLine("After Bubble Sort:");
                for (int i = 0; i < integerArray.Length; i++)
                {
                    Console.Write(integerArray[i] + " ");
                }
                Console.WriteLine();
                int pos1 = Utility.BinarySearch(6, 0, 11, integerArray);
                if (pos1 == -1)
                {
                    Console.WriteLine("Not Found!");
                }
                else
                {
                    Console.WriteLine("Found at location: " + pos1);
                }

                Console.WriteLine();

                string[] stringArray = { "saad", "fahad", "saba", "zeeshan", "ashhar", "owais" };
                stringArray = Utility.BubbleSort(stringArray);
                Console.WriteLine("After Bubble Sort:");
                for (int i = 0; i < stringArray.Length; i++)
                {
                    Console.Write(stringArray[i] + " ");
                }
                int pos2 = Utility.BinarySearch("saad", 0, 11, stringArray);
                Console.WriteLine();
                if (pos2 == -1)
                {
                    Console.Write("Not Found!");
                }
                else
                {
                    Console.Write("Found at location: " + pos2);
                }
                break;

            case 5:
                FindingNumber findingNumber = new FindingNumber();
                findingNumber.Find();
                break;

            case 6:
                BinarySearch search = new BinarySearch();
                search.binarySearch();
                break;

            case 7:
                InsertionSort insertionSort = new InsertionSort();
                insertionSort.Sort();
                break;

            case 8:
                BubbleSort bubbleSort = new BubbleSort();
                bubbleSort.Sort();
                break;

            case 9:
                MergeSort mergeSort = new MergeSort();
                mergeSort.Sort();
                break;

            case 10:
                VendingMachine vendingMachine = new VendingMachine();
                vendingMachine.machine();
                break;

            case 11:
                DayOfWeek dayOfWeek = new DayOfWeek();
                dayOfWeek.getDay();
                break;

            case 12:
                TemperatureConversion conversion = new TemperatureConversion();
                conversion.temperatureConversion();
                break;

            case 13:
                MonthlyPayment monthlyPayment = new MonthlyPayment();
                monthlyPayment.payment();
                break;

            case 14:
                SquareRoot root = new SquareRoot();
                root.calculateSquareRoot();
                break;

            case 15:
                ConvertToBinary convert = new ConvertToBinary();
                convert.conversion();
                break;

            case 16:
                BinarySwapNibbles binarySwapNibbles = new BinarySwapNibbles();
                binarySwapNibbles.swapNibbles();
                break;

            default:
                Console.WriteLine("Wrong Choice!");
                break;
            }
        }