C#--4週目の実験--タスク4--座標点を記述するCPointクラスを定義し、直線クラスClineを派生し、矩形クラスCRectを派生し、いくつかの機能を実現する.

2983 ワード

/* (        )
 *             
 * Copyright (c) 2011,             
 * All rights reserved.
 *     :          CPoint ,      Cline,       CRect,                  。
 *    :     
 *     : 2012   09   22  
 *      : V1.0 
 *              
 *     :
 *     :
 *     :
 *          
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Four__week
{
    class Program
    {
        static void Main(string[] args)
        {
            CPoint c1 = new CPoint();
            CPoint c2 = new CPoint();
            CPoint c3 = new CPoint();
            c1.setpoint(1, 1);
            c2.setpoint(4, 5);
            c3.setpoint(4, 1);
            Cline m = new Cline();
            Console.WriteLine("        :{0}", m.distence(c1, c2));
            Cline m1 = new Cline();
            m.set_length(c3, c2);
            m1.set_length(c1, c3);
            CRect CR = new CRect();
            Console.WriteLine("      :{0}", CR.perimeter(m, m1));
            Console.WriteLine("      :{0}", CR.area(m, m1));
            Console.ReadKey(true);
        }
    }

    class CPoint
    {
        private int x;
        private int y;

        public CPoint(int x1,int y2)
        {
            x = x1;
            y = y2;
        }

        public CPoint()
        {
            x = 60;
            y = 75;

        }

        public void display()
        {
            Console.WriteLine("x = {0}   y = {1}",x,y);
        }
        public void setpoint(int x1, int y1)
        {
            x = x1;
            y = y1;
        }
        public int get_x()
        {
            return x;
        }
        public int get_y()
        {
            return y;
        }
    }

    class Cline:CPoint
    {
        public double a;
        public Cline(int a1)
        {
            a = a1;
        }
        public Cline()
        {
            a = 0;
        }
        public double distence(CPoint c1,CPoint c2)
        {
            return a = Math.Sqrt((Math.Pow((c1.get_x()-c2.get_x()),2)+Math.Pow((c1.get_y()-c2.get_y()),2)));
        }
        public double get_length()
        {
            return a;
        }
        public void set_length(CPoint c1, CPoint c2)
        {
            a = distence(c1,c2);
        }
    }
    class CRect:Cline
    {
        public double m;
        public double n;
        public CRect(double a1,double b1)
        {
            m = a1;
            n = b1;
        }
        public CRect()
        {
            m = 0;
            n = 0;
        }
        public double perimeter(Cline c1,Cline c2)
        {
            return m = 2 * (c1.get_length() + c2.get_length());
        }

        public double area(Cline c1, Cline c2)
        {
            return n = c1.get_length() * c2.get_length();
        }
    }
}

 
実行結果:
 
経験の蓄積
1.上のプログラムはまだ少し完璧ではありません.主に派生クラスの構造関数の部分です.Baseに関連しているので、BaseとThisの違いを学んでから改善し続けます.
2.感覚はC++と大同小異.