WV.47-两点之间的距离
来源:互联网 发布:mysql is ix 编辑:程序博客网 时间:2024/05/08 10:35
问题及代码:
运行结果:
/* *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 类名(参数表)//创建对象
对象名 .属性 //访问对象属性
对象.方法名(参数列表)//调用对象方法
0 0
- WV.47-两点之间的距离
- 两点之间的距离
- 两点之间的距离
- 两点之间的距离
- 求两点之间的距离
- 求两点之间的距离
- 求两点之间的距离
- 求两点之间的距离
- 求两点之间的距离
- 计算两点之间的距离
- 计算两点之间的距离
- 获取两点之间的距离
- 计算两点之间的距离
- 4.22两点之间的距离
- 计算两点之间的距离
- 求两点之间的距离
- 【2025】两点之间的距离
- 计算两点之间的距离
- poj2406--Power Strings+KMP求周期
- jQuery基础课程学习笔记
- IAR Build error: Multiple tools write to the same file
- 关于Linux下面文件的存放
- spoon+robotium+jenkins进行自动化持续回归测试
- WV.47-两点之间的距离
- 操作系统之初探
- 17、增加、修改列以及表属性修改操作讲解
- C#异步加载数据:BackgroundWorker的使用
- UISwitch
- css控制div位置
- poj1328Radar Installation
- NS3的安装(二)
- Android GPS架构分析详解