コード例 #1
0
        static void Main(string[] args)
        {
            try
            {
                Racionalni rac = new Racionalni(25);
                //Debug.Assert(rac.ToString() == "25 / 1");
                Console.WriteLine(rac);

                // Naredba koja poziva konstruktor pretvorbe iz double
                //rac = new Racionalni(0.25);
                //Debug.Assert(rac.ToString() == "1 / 4");
                Console.WriteLine(rac);

                // Naredba koja poziva konstruktor pretvorbe iz double
                //rac = new Racionalni(0.125);
                //Debug.Assert(rac.ToString() == "1 / 8");
                Console.WriteLine(rac);
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("GOTOVO!!!");
            Console.ReadKey();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Racionalni rac = new Racionalni(2, 3);
            // eksplicitna pretvorba
            long racKaoInt = (long)rac;
            Debug.Assert(racKaoInt == 0);
            Console.WriteLine(racKaoInt);

            double racKaoDouble = (double)rac;
            Debug.Assert(racKaoDouble == (2.0 / 3.0));
            Console.WriteLine(racKaoDouble);

            Console.ReadKey();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            Racionalni rac = new Racionalni(2, 3);

            // eksplicitna pretvorba
            //long racKaoInt = (long)rac;
            //Console.WriteLine(racKaoInt);

            //double racKaoDouble = (double)rac;
            //Console.WriteLine(racKaoDouble);

            Console.WriteLine("GOTOVO!!!!");
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            try
            {
                Racionalni rac = new Racionalni();
                // koristi implicitnu pretvorbu iz double
                rac = 0.1;
                Debug.Assert(rac.ToString() == "1 / 10");
                Console.WriteLine(rac);

                // koristi implicitnu pretvorbu iz int
                rac = 2;
                Debug.Assert(rac.ToString() == "2 / 1");
                Console.WriteLine(rac);
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("GOTOVO!!!");
            Console.ReadKey();
        }
コード例 #5
0
        static void Main(string[] args)
        {
            try
            {
                Racionalni rac = new Racionalni();
                // koristi implicitnu pretvorbu iz double
                rac = 0.1;
                Debug.Assert(rac.ToString() == "1 / 10");
                Console.WriteLine(rac);

                // koristi implicitnu pretvorbu iz double
                rac = 2;
                Debug.Assert(rac.ToString() == "2 / 1");
                Console.WriteLine(rac);
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("GOTOVO!!!");
            Console.ReadKey();
        }
コード例 #6
0
        static void Main(string[] args)
        {
            try
            {
                Racionalni rac = new Racionalni(25);
                Debug.Assert(rac.ToString() == "25 / 1");
                Console.WriteLine(rac);

                rac = new Racionalni(0.25);
                Debug.Assert(rac.ToString() == "1 / 4");
                Console.WriteLine(rac);

                rac = new Racionalni(0.125);
                Debug.Assert(rac.ToString() == "1 / 8");
                Console.WriteLine(rac);
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("GOTOVO!!!");
            Console.ReadKey();
        }