/*
*程序的版权和版本声明部分:
*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();
}
}
}
*样例输出:
*心得体会:六号说世事难料。