第五周上机实践项目——C#之点、线、面

/*
*程序的版权和版本声明部分:
*Copyright(c)2013,烟台大学计算机学院学生
*All rights reserved.
*文件名称:C#之点、线、面
*作者:刘中林
*完成日期:2014年10月9日
*版本号:v0.1
*对任务及求解方法的描述部分:
*输入描述:
*问题描述:
*程序输入:自定义的点
*程序输出:两点之间的距离、矩形的周长和面积
*问题分析:
*算法设计:
*我的程序:
*/

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

namespace ConsoleApplication1
{
    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(2, 1);
            c3.setpoint(3, 2);
            Cline m = new Cline();
            Console.WriteLine("两点之间的距离为:{0}", m.distance(c1, c2));
            Cline m1 = new Cline();
            m.set_length(c1, c2);
            m1.set_length(c2, c3);
            CRect CR = new CRect();
            Console.WriteLine("矩形的周长为:{0}", CR.perimeter(m, m1));
            Console.WriteLine("矩形的面积为:{0}", CR.area(m, m1));
            Console.ReadKey();
        }
    }
    class CPoint
    {
        private int x;
        private int y;
        public CPoint(int x1,int y1)
        {
            x=x1;
            y=y1;
        }
        public CPoint()
        {

        }
        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
    {
        private double a;
        public Cline(double a1)
        {
            a = a1;
        }
        public Cline()
        {

        }
        public double distance(CPoint c1,CPoint c2)
        {
            return a = Math.Sqrt(Math.Pow(c1.get_x() - c2.get_x(),2) + Math.Pow(c2.get_y() - c2.get_y(),2));
        }
        public void set_length(CPoint c1,CPoint c2)
        {
            a = distance(c1, c2);
        }
        public double get_length()
        {
            return a;
        }
    }

    class CRect : Cline
    {
        private double m;
        private double n;
        public CRect(double a1,double b1)
        {
            m = a1;
            n = b1;
        }
        public CRect()
        {

        }
        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();
        }
    }
}

*样例输出:

*心得体会:六号说世事难料。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值