WV.47-两点之间的距离

问题及代码:
/*   
*Copyright (c)2015,烟台大学计算机与控制工程学院   
*All rights reserved.   
*文件名称:days.cpp   
*作    者:单昕昕   
*完成日期:2015年2月7日   
*版 本 号:v1.0   
*   
*问题描述:求输入两点间的距离。
*程序输入:两点。
*程序输出:两点间的距离。  
*/ 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Test
{
    public class Program
    {
        public class Point
        {
            public int x, y;
            public Point(int x, int y)
            {
                this.x = x;
                this.y = y;
            }
            public double distance(Point p)
            {
                return Math.Sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
            }
        }
        class Test
        {
            static void Main()
            {
                int a, b, c, d;
                Console.WriteLine("请输入p1的坐标");
                a = int.Parse(Console.ReadLine());
                b = int.Parse(Console.ReadLine());
                Point p1 = new Point(a, b);
                Console.WriteLine("请输入p2的坐标");
                c = int.Parse(Console.ReadLine());
                d = int.Parse(Console.ReadLine());
                Point p2 = new Point(c, d);
                double distance_ = p1.distance(p2);
                Console.Write("点p1(" + p1.x + "," + p1.y + ")");
                Console.Write("和点p2(" + p1.x + "," + p1.y + ")");
                Console.WriteLine("间的距离=" + distance_);
                Console.ReadLine();
            }
        }
    }
}



运行结果:


知识点总结:

对象的创建与使用。

声明和使用方法。


学习心得:

类名 对象名=new 类名(参数表)//创建对象

对象名 .属性 //访问对象属性

对象.方法名(参数列表)//调用对象方法

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值