コード例 #1
0
        /// <summary>
        /// Defines the entry point of the application.
        /// </summary>
        /// <param name="args">The arguments.</param>
        static void Main(string[] args)
        {
            Console.WriteLine("1: Replace String");
            Console.WriteLine("2: FlipCoin");
            Console.WriteLine("3: Leap Year");
            Console.WriteLine("4: Power of 2");
            Console.WriteLine("5: Harmonic Number");
            Console.WriteLine("6: Prime Factors");
            Console.WriteLine("7: Gambler");
            Console.WriteLine("8: Coupon Numbers");
            Console.WriteLine("9: 2D Array");
            Console.WriteLine("10: Sum of Integer Zero");
            Console.WriteLine("11: Distance");
            Console.WriteLine("12: Permutations");
            Console.WriteLine("13: Stop Watch");
            Console.WriteLine("14: Tic-Tac-Toe");
            Console.WriteLine("15: Quadratic");
            Console.WriteLine("16: Wind Chill");
            int choice = 0;

            while (!(choice > 0 && choice < 17))
            {
                try
                {
                    Console.Write("Enter your choice: ");
                    choice = Convert.ToInt32(Console.ReadLine());
                }
                catch (FormatException)
                {
                    //Console.WriteLine(Ex);
                }
            }

            //Console.WriteLine(choice);
            switch (choice)
            {
            case 1:
                ReplaceString replaceString = new ReplaceString();
                replaceString.Print();
                break;

            case 2:
                FlipCoin flip = new FlipCoin();
                flip.flipCoin();
                break;

            case 3:
                LeapYear leap = new LeapYear();
                leap.leapYear();
                break;

            case 4:
                PowerOfTwo powerOfTwo = new PowerOfTwo();
                powerOfTwo.printPowerOfTwo();
                break;

            case 5:
                HarmonicNumber harmonic = new HarmonicNumber();
                harmonic.printHarmonicNumber();
                break;

            case 6:
                Factors factors = new Factors();
                factors.printFactors();
                break;

            case 7:
                Gambler gambler = new Gambler();
                gambler.gambling();
                break;

            case 8:
                CouponNumbers coupon = new CouponNumbers();
                coupon.CouponCode();
                break;

            case 9:
                TwoDArray array = new TwoDArray();
                array.input();
                break;

            case 10:
                SumZero sumZero = new SumZero();
                sumZero.checkSumForZero();
                break;

            case 11:
                Distance distance = new Distance();
                distance.calculateDistance();
                break;

            case 12:
                Permutations permutations = new Permutations();
                permutations.permutation();
                break;

            case 13:
                StopWatch watch = new StopWatch();
                watch.simulate();
                break;

            case 14:
                TicTacToe ticTacToe = new TicTacToe();
                ticTacToe.game();
                break;

            case 15:
                Quadratic quadratic = new Quadratic();
                quadratic.roots();
                break;

            case 16:
                WindChill windChill = new WindChill();
                int       t         = 100;
                int       v         = 0;
                while (!(Math.Abs(t) <= 50 && v <= 120 && v >= 3))
                {
                    Console.WriteLine("Enter Temperature and Wind Speed: ");
                    t = Convert.ToInt32(Console.ReadLine());
                    v = Convert.ToInt32(Console.ReadLine());
                }
                windChill.calculateEffectiveTemperature(t, v);
                break;

            default:
                Console.WriteLine("Wrong Choice!");
                break;
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the no of the program which you want to run from the given programs");
            Console.WriteLine("2d Array(1)");
            Console.WriteLine("Replace the string(2)");
            Console.WriteLine("Flip a Coin(3)");
            Console.WriteLine("Cheak wheather the year is leap year or not(4)");
            Console.WriteLine("Power of 2(5)");
            Console.WriteLine("Find nth Harmonic no(6)");
            Console.WriteLine("Find the Factor of a no(7)");
            Console.WriteLine("Generate Distinct Cupon no.(8)");
            Console.WriteLine("Gambler Game(9)");
            Console.WriteLine("Triple Sum(10)");
            Console.WriteLine("Find Distance(11)");
            Console.WriteLine("Stop Watch(12)");
            Console.WriteLine("Qudratic(13)");
            Console.WriteLine("Calculate WindChill(14)");


            int p = int.Parse(Console.ReadLine());

            switch (p)
            {
            case 1:
                Console.WriteLine("Enter the row");
                int r;
                r = int.Parse(Console.ReadLine());
                Console.WriteLine("Enter the coulumn");
                int c;
                c = int.Parse(Console.ReadLine());
                Array2D a = new Array2D();
                //Calling the methods to generate 2D array by taking user input
                a.ArrayInt(r, c);
                a.ArrayDouble(r, c);
                a.ArrayBoolean(r, c);
                break;

            case 2:
                ReplaceStr b = new ReplaceStr();
                //Calling method to replace the string by the user given string
                b.ReplaceS();
                break;

            case 3:
                FlipCoin d = new FlipCoin();
                //Calling method to flip the coin and calculate the percentage
                d.CoinFlip();
                break;

            case 4:
                LeapYear e = new LeapYear();
                //Calling method to cheak whether the year is a leap year or not
                e.ChkLeapYear();
                break;

            case 5:
                PowerOfTwo f = new PowerOfTwo();
                //Calling method to calculate the power of 2 from 0 to n
                f.Powerof2();
                break;

            case 6:
                Harmonic h = new Harmonic();
                //Calling method to calculate the nth harmonic no
                h.ChkHarmonic();
                break;

            case 7:
                Factors g = new Factors();
                //Calling method to find the factors of a no
                g.FindFactors();
                break;

            case 8:
                CuponNum k = new CuponNum();
                //Calling method to generate the cupon nos
                k.Couponno();
                break;

            case 9:
                Gambler l = new Gambler();
                //Calling method to play Gambling Game
                l.GamblerG();
                break;

            case 10:
                TripleSum m = new TripleSum();
                //Calling method to find the sequence of three nos which sum is equals to 0
                m.ThreeSum();
                break;

            case 11:
                Distance n = new Distance();
                //calling method to calculate the distance between two points
                n.FindDistance();
                break;

            case 12:
                StopWatch o = new StopWatch();
                //Start the watch
                Console.WriteLine("Enter 1 to start");
                int t = int.Parse(Console.ReadLine());
                if (t == 1)
                {
                    o.Start();
                }


                //Stop and Calculate the Elapsed time
                Console.WriteLine("Enter 0 to stop");
                int t1 = int.Parse(Console.ReadLine());
                if (t1 == 0)
                {
                    o.Stop();
                }

                Console.WriteLine();
                break;

            case 13:
                Quadratic q = new Quadratic();
                //Calling Find method to find  roots
                q.Find();
                break;

            case 14:
                int       x = int.Parse(args[0]);
                int       y = int.Parse(args[0]);
                WindChill s = new WindChill();
                //calling method to calculate windchill
                s.FindWindChill(x, y);
                break;
            }
        }