Donnerstag, 14. Juli 2011

Blatt 6 PRG

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CirclePoint
{
    class Rectangle
    {

        private double a, b;
        private int x, y;
        private Point p ;


        public Rectangle(double seiteA, double seiteB, Point anfangsPunkt)
        {
            a = seiteA; b = seiteB; p = anfangsPunkt;

            Console.WriteLine("Rechteck mit a = {0}, b = {1} an der Stelle ({2},{3}) erzeugt", a, b, p.Xprop, p.Yprop);
        }

        public Point PointProp
        {
            get { return p; }
            set { p = value; }
        }


        public double SideA
        {
            get { return a; }
            set { a = value; }
        }

        public double SideB
        {
            get { return b; }
            set { b = value; }
        }

        public void Move( int dx, int dy)
        {
        
                        
            p.Xprop += dx;
            p.Yprop += dy;
        }


        public double Flaeche(Rectangle rechteck)
        {
            return rechteck.SideA * rechteck.SideB;
        }
    }
}

-----------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CirclePoint
{
    class Program
    {
        public static void Main(string[] args)
        {


            Point daul = new Point(100, 100);
            Rectangle schmidt = new Rectangle(10, 10, daul);
            Console.WriteLine(schmidt.PointProp.Xprop);

            schmidt.Move(13, 100);

            Console.WriteLine(schmidt.PointProp.Xprop+";"+schmidt.PointProp.Yprop);


            // Circle a = new Circle( 1, 1, 1.0 );
            // Circle b = new Circle( 1, -1, 10.0 );

            //if (a.IsDisjoint(b)) Console.WriteLine("a und b sind disjunkt");
            //else Console.WriteLine("a und b sind NICHT disjunkt");

            //for ( int d = 0; d <= 9; d++ )
            //{
            //a.move( 2, 2 );
            //if (a.IsDisjoint(b))
            //   Console.WriteLine("a und b sind disjunkt");
            //else
            //    Console.WriteLine("a und b sind NICHT disjunkt");
            //}
           
           
            //Point position = new Point(1,1);
            //Rectangle rechteck = new Rectangle(10,30,position);
            //Console.WriteLine(rechteck.Flaeche(rechteck));

            //int k = 30;
            //int l = 30;
            //rechteck.Move(k, l);
            //Console.WriteLine("Die neuen Koordinaten  sind ({0}, {1}):", k,l);
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
            //Circle eins = new Circle(0, 0, 3.0);
            //Circle zwei = new Circle(3, 0, 4.0);
            //Circle drei = new Circle(0, 3, 5.0);
            //Point a = new Point(0, 0);
           

            //Console.WriteLine("\n-Punkt- -Kreis1- -Kreis2- -Kreis3-");

            //int x = 2, y = 0;
            //Console.Write(" (" + x + ", " + y + ") ");
            //if (eins.isOutside(x, y)) Console.Write(" AUSSEN  ");
            //else Console.Write(" INNEN   ");
            //if (zwei.isOutside(x, y)) Console.Write(" AUSSEN  ");
            //else Console.Write(" INNEN   ");
            //if (drei.isOutside(x, y)) Console.Write(" AUSSEN  ");
            //else Console.Write(" INNEN   ");
            //Console.WriteLine();

            //x = 2; y = 7;
            //Console.Write(" (" + x + ", " + y + ") ");
            //if (eins.isOutside(x, y)) Console.Write(" AUSSEN  ");
            //else Console.Write(" INNEN   ");
            //if (zwei.isOutside(x, y)) Console.Write(" AUSSEN  ");
            //else Console.Write(" INNEN   ");
            //if (drei.isOutside(x, y)) Console.Write(" AUSSEN  ");
            //else Console.Write(" INNEN   ");
            //Console.WriteLine();

            //x = 2; y = 9;
            //Console.Write(" (" + x + ", " + y + ") ");
            //if (eins.isOutside(x, y)) Console.Write(" AUSSEN  ");
            //else Console.Write(" INNEN   ");
            //if (zwei.isOutside(x, y)) Console.Write(" AUSSEN  ");
            //else Console.Write(" INNEN   ");
            //if (drei.isOutside(x, y)) Console.Write(" AUSSEN  ");
            //else Console.Write(" INNEN   ");
            //Console.WriteLine();
        }

    }
}
.-----------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CirclePoint
{
    class Point
    {
        private int x, y;

       
        public Point(int ix, int iy)
        {   x = ix; y = iy;
            Console.WriteLine("Punkt ("+x+", "+y+") erzeugt");
        }

        public int Xprop
        {
            get { return x; }
            set { x = value; }
        }


        public int Yprop
        {
            get { return y; }
            set { y = value; }
        }
    }
}

---------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CirclePoint
{
    class Circle
    {
        private int x, y;
        private double radius;

        public Circle(int ix, int iy, double ir)
        {
            x = ix; y = iy; radius = ir;
            Console.WriteLine("Kreis erzeugt: M = (" + x + ", " + y +
                               "), Radius: " + radius);

            if (radius == 2)
            {
                Console.WriteLine(" *");
                Console.WriteLine("* *");
                Console.WriteLine(" *");
            }
            else if (radius == 4)
            {
                Console.WriteLine(" **");
                Console.WriteLine("*  *");
                Console.WriteLine(" **");
            }
           

           
          
        }

        public double getRadius() { return radius; }

        public double Radius
        {
            get { return radius; }
            set { radius = value; }
        }


        public int Xmittel
        {
            get { return x; }
            set { x = value; }
        }



        public int Ymittel
        {
            get { return y; }
            set { y= value; }
        }

        public void grow(double dr) { radius += dr; }

        public void move(int dx, int dy) { x += dx; y += dy; }

       public  bool isOutside(int px, int py)
        {
            return Math.Sqrt((px - x) * (px - x) + (py - y) * (py - y)) > radius;
        }


       public bool IsDisjoint(Circle c)
       {

           return Math.Sqrt ((x - c.Xmittel) * (x - c.Xmittel) + (y - c.Ymittel) * (y - c.Ymittel))> radius + c.Radius;
       }

   
    }
}

Keine Kommentare:

Kommentar veröffentlichen