Пример #1
0
    static void Main()
    {
        ThreeD a = new ThreeD(1, 2, 3);
        ThreeD b = new ThreeD(10, 10, 10);
        ThreeD c = new ThreeD();

        Console.Write("Here is a: ");
        a.Show();
        Console.WriteLine();
        Console.Write("Here is b: ");
        b.Show();
        Console.WriteLine();

        c = a + b; // ThreeD + ThreeD
        Console.Write("Result of a + b: ");
        c.Show();
        Console.WriteLine();

        c = b + 10; // ThreeD + int
        Console.Write("Result of b + 10: ");
        c.Show();

        c = 15 + b; // int + ThreeD
        Console.Write("Result of 15 + b: ");
        c.Show();
    }
    static void Main()
    {
        ThreeD a = new ThreeD(1, 2, 3);
        ThreeD b = new ThreeD(10, 10, 10);
        ThreeD c = new ThreeD();

        Console.Write("Here is a: ");
        a.Show();
        Console.WriteLine();
        Console.Write("Here is b: ");

        b.Show();
        Console.WriteLine();

        c = a + b; // add a and b together
        Console.Write("Result of a + b: ");
        c.Show();
        Console.WriteLine();

        c = a + b + c; // add a, b, and c together
        Console.Write("Result of a + b + c: ");
        c.Show();
        Console.WriteLine();

        c = c - a; // subtract a
        Console.Write("Result of c - a: ");
        c.Show();
        Console.WriteLine();

        c = c - b; // subtract b
        Console.Write("Result of c - b: ");
        c.Show();
        Console.WriteLine();

        c = -a; // assign -a to c
        Console.Write("Result of -a: ");
        c.Show();
        Console.WriteLine();

        c = a++; // post-increment a
        Console.WriteLine("Given c = a++");
        Console.Write("c is ");
        c.Show();
        Console.Write("a is ");
        a.Show();


        // Reset a to 1, 2, 3
        a = new ThreeD(1, 2, 3);
        Console.Write("\nResetting a to ");
        a.Show();

        c = ++a; // pre-increment a
        Console.WriteLine("\nGiven c = ++a");
        Console.Write("c is ");
        c.Show();
        Console.Write("a is ");
        a.Show();
    }
    static void Main()
    {
        ThreeD a = new ThreeD(1, 2, 3);
        ThreeD b = new ThreeD(10, 10, 10);
        ThreeD c;

        Console.Write("Here is a: ");
        a.Show();
        Console.WriteLine();
        Console.Write("Here is b: ");
        b.Show();
        Console.WriteLine();
        c = a + b; // add a and b together
        Console.Write("Result of a + b: ");
        c.Show();
        Console.WriteLine();
        c = a + b; // add a and b together
        Console.Write("Result of a + b: ");
        c.Show();
        Console.WriteLine();
        c = a + b + c; // add a, b, and c together
        Console.Write("Result of a + b + c: ");
        c.Show();
        Console.WriteLine();
        c = c - a; // subtract a
        Console.Write("Result of c - a: ");
        c.Show();
        Console.WriteLine();
        c = c - b; // subtract b
        Console.Write("Result of c - b: ");
        c.Show();
        Console.WriteLine();
    }
    static void Main()
    {
        ThreeD a = new ThreeD(1, 2, 3);
        ThreeD b = new ThreeD(10, 10, 10);
        ThreeD c = new ThreeD();

        int i;

        Console.Write("Here is a: ");
        a.Show();
        Console.WriteLine();
        Console.Write("Here is b: ");
        b.Show();
        Console.WriteLine();

        c = a + b; // add a and b together
        Console.Write("Result of a + b: ");
        c.Show();
        Console.WriteLine();

        i = a; // convert to int
        Console.WriteLine("Result of i = a: " + i);
        Console.WriteLine();

        i = a * 2 - b; // convert to int
        Console.WriteLine("result of a * 2 - b: " + i);
    }
Пример #5
0
    static void Main()
    {
        ThreeD a = new ThreeD(1, 2, 3);
        ThreeD b = new ThreeD(10, 10, 10);
        ThreeD c = new ThreeD();

        int i;

        Console.Write("Here is a: ");
        a.Show();
        Console.WriteLine();
        Console.Write("Here is b: ");
        b.Show();
        Console.WriteLine();

        c = a + b; // add a and b together
        Console.Write("Result of a + b: ");
        c.Show();
        Console.WriteLine();

        i = (int)a;  // explicitly convert to int -- cast required
        Console.WriteLine("Result of i = a: " + i);
        Console.WriteLine();

        i = (int)a * 2 - (int)b; // casts required
        Console.WriteLine("result of a * 2 - b: " + i);
    }
    static void Main()
    {
        ThreeD a = new ThreeD(5, 6, 7);
        ThreeD b = new ThreeD(10, 10, 10);
        ThreeD c = new ThreeD(0, 0, 0);

        Console.Write("Here is a: ");
        a.Show();
        Console.Write("Here is b: ");
        b.Show();
        Console.Write("Here is c: ");
        c.Show();
        Console.WriteLine();

        if (a)
        {
            Console.WriteLine("a is true.");
        }
        else
        {
            Console.WriteLine("a is false.");
        }
        if (b)
        {
            Console.WriteLine("b is true.");
        }
        else
        {
            Console.WriteLine("b is false.");
        }
        if (c)
        {
            Console.WriteLine("c is true.");
        }
        else
        {
            Console.WriteLine("c is false.");
        }

        Console.WriteLine();
        Console.WriteLine("Control a loop using a ThreeD object.");
        do
        {
            b.Show();
            b--;
        } while(b);
    }
    static void Main()
    {
        ThreeD a = new ThreeD(5, 6, 7);
        ThreeD b = new ThreeD(10, 10, 10);
        ThreeD c = new ThreeD(0, 0, 0);

        Console.Write("Here is a: ");
        a.Show();
        Console.Write("Here is b: ");
        b.Show();
        Console.Write("Here is c: ");
        c.Show();
        Console.WriteLine();
        if (!a)
        {
            Console.WriteLine("a is false.");
        }
        if (!b)
        {
            Console.WriteLine("b is false.");
        }
        if (!c)
        {
            Console.WriteLine("c is false.");
        }
        Console.WriteLine();
        if (a & b)
        {
            Console.WriteLine("a & b is true.");
        }
        else
        {
            Console.WriteLine("a & b is false.");
        }
        if (a & c)
        {
            Console.WriteLine("a & c is true.");
        }
        else
        {
            Console.WriteLine("a & c is false.");
        }
        if (a | b)
        {
            Console.WriteLine("a | b is true.");
        }
        else
        {
            Console.WriteLine("a | b is false.");
        }
        if (a | c)
        {
            Console.WriteLine("a | c is true.");
        }
        else
        {
            Console.WriteLine("a | c is false.");
        }
    }
    static void Main()
    {
        ThreeD a = new ThreeD(5, 6, 7);
        ThreeD b = new ThreeD(10, 10, 10);
        ThreeD c = new ThreeD(1, 2, 3);
        ThreeD d = new ThreeD(6, 7, 5);

        Console.Write("Here is a: ");
        a.Show();
        Console.Write("Here is b: ");
        b.Show();
        Console.Write("Here is c: ");
        c.Show();
        Console.Write("Here is d: ");
        d.Show();
        Console.WriteLine();

        if (a > c)
        {
            Console.WriteLine("a > c is true");
        }
        if (a < c)
        {
            Console.WriteLine("a < c is true");
        }
        if (a > b)
        {
            Console.WriteLine("a > b is true");
        }
        if (a < b)
        {
            Console.WriteLine("a < b is true");
        }
        if (a > d)
        {
            Console.WriteLine("a > d is true");
        }
        else if (a < d)
        {
            Console.WriteLine("a < d is true");
        }
        else
        {
            Console.WriteLine("a and d are same distance from origin");
        }
    }
    static void Main()
    {
        ThreeD a = new ThreeD(5, 6, 7);
        ThreeD b = new ThreeD(10, 10, 10);
        ThreeD c = new ThreeD(0, 0, 0);

        Console.Write("Here is a: ");
        a.Show();
        Console.Write("Here is b: ");
        b.Show();
        Console.Write("Here is c: ");
        c.Show();
        Console.WriteLine();

        if (a)
        {
            Console.WriteLine("a is true.");
        }
        if (b)
        {
            Console.WriteLine("b is true.");
        }
        if (c)
        {
            Console.WriteLine("c is true.");
        }
        if (!a)
        {
            Console.WriteLine("a is false.");
        }
        if (!b)
        {
            Console.WriteLine("b is false.");
        }
        if (!c)
        {
            Console.WriteLine("c is false.");
        }
        Console.WriteLine();
        Console.WriteLine("Use & and |");
        if (a & b)
        {
            Console.WriteLine("a & b is true.");
        }
        else
        {
            Console.WriteLine("a & b is false.");
        }
        if (a & c)
        {
            Console.WriteLine("a & c is true.");
        }
        else
        {
            Console.WriteLine("a & c is false.");
        }
        if (a | b)
        {
            Console.WriteLine("a | b is true.");
        }
        else
        {
            Console.WriteLine("a | b is false.");
        }
        if (a | c)
        {
            Console.WriteLine("a | c is true.");
        }
        else
        {
            Console.WriteLine("a | c is false.");
        }
        Console.WriteLine();
        // Now use short-circuit ops.
        Console.WriteLine("Use short-circuit && and ||");
        if (a && b)
        {
            Console.WriteLine("a && b is true.");
        }
        else
        {
            Console.WriteLine("a && b is false.");
        }
        if (a && c)
        {
            Console.WriteLine("a && c is true.");
        }
        else
        {
            Console.WriteLine("a && c is false.");
        }
        if (a || b)
        {
            Console.WriteLine("a || b is true.");
        }
        else
        {
            Console.WriteLine("a || b is false.");
        }
        if (a || c)
        {
            Console.WriteLine("a || c is true.");
        }
        else
        {
            Console.WriteLine("a || c is false.");
        }
    }