コード例 #1
0
        //static void Main1(string[] args)
        static void Fractionn()
        {
            Fraction complex = new Fraction();

            complex.a1 = 1;
            complex.b1 = 5;
            complex.c1 = 3;
            complex.d1 = 3;

            Fraction result1 = complex.Summ(complex);

            Console.WriteLine(result1.ToString());

            Fraction result2 = complex.Minus(complex);

            Console.WriteLine(result2.ToString());


            Fraction result3 = complex.Mult(complex);

            Console.WriteLine(result3.ToString());


            Fraction result4 = complex.Div(complex);

            Console.WriteLine(result4.ToString());
            Console.Read();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Struct:");

            Complex x1 = new Complex(4, 5);

            Console.WriteLine(x1.Print());

            Complex x2 = new Complex(2, -5);

            Console.WriteLine(x2.Print());

            Console.WriteLine();
            Console.WriteLine("Class:");

            ComplexClass y1 = new ComplexClass(3, 1);

            Console.WriteLine(y1.Print());

            ComplexClass y2 = new ComplexClass(8, -9);

            Console.WriteLine(y2.Print());

            Console.WriteLine();
            Console.WriteLine("Enter sub if you want to substruct this numbers, mul to multiply:");
            string command = Console.ReadLine();

            switch (command)
            {
            case "sub":  Console.WriteLine("Substruct:");
                Console.WriteLine("Struct:");
                Complex res1 = Complex.Sub(x1, x2);
                Console.WriteLine(res1.Print());
                Console.WriteLine("Class:");
                ComplexClass result1 = ComplexClass.Sub(y1, y2);
                Console.WriteLine(result1.Print());
                break;

            case "mul":  Console.WriteLine("Multiply:");
                Console.WriteLine("Struct:");
                ComplexClass result = ComplexClass.Mul(y1, y2);
                Console.WriteLine(result.Print());
                Console.WriteLine("Class:");
                ComplexClass result2 = ComplexClass.Mul(y1, y2);
                Console.WriteLine(result2.Print());
                break;

            default: Console.WriteLine("Incorrect command");
                break;
            }

            Console.WriteLine("Enter numbers or 0 to exit:");
            int  number  = 1;
            bool success = false;
            int  res     = 0;

            while (number != 0)
            {
                success = int.TryParse(Console.ReadLine(), out number);
                if (success)
                {
                    res += number;
                }
                else
                {
                    number = 1;
                }
            }
            Console.WriteLine("Result:" + res.ToString());

            Console.WriteLine();
            Console.WriteLine("Fraction:");

            Fraction f1 = new Fraction(1, 2);

            Console.WriteLine(f1.Print());
            Fraction f2 = new Fraction(2, 4);

            Console.WriteLine(f2.Print());
            Console.WriteLine("Sum:");
            Fraction resultf1 = Fraction.Sum(f1, f2);

            Console.WriteLine(resultf1.Print());
            Console.WriteLine("Sub:");
            Fraction resultf2 = Fraction.Sub(f1, f2);

            Console.WriteLine(resultf2.Print());
            Console.WriteLine("Mul:");
            Fraction resultf3 = Fraction.Mul(f1, f2);

            Console.WriteLine(resultf3.Print());
            Console.WriteLine("Div:");
            Fraction resultf4 = Fraction.Div(f1, f2);

            Console.WriteLine(resultf4.Print());
        }