点线面
时间: 1ms 内存:128M
描述:
定义一个点的类CPoint作为基类。派生出一条直线的类Cline,并定一个方法(Dis)可求出两点间的距离。请在此基础上再派生出一个矩形类CRect。要求成员函数能计算矩形的周长(Getlength)和面积(Getarea)等。构造完整的程序并设计一个测试程序进行测试。测试程序中调用类中相应方法,验证各方法的正确性。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
//
//
class Program
{
static void Main(string[] args)
{
CPoint p1 = new CPoint();
CPoint p4 = new CPoint();
int i;
int num= Convert.ToInt32(Console.ReadLine());
int num2= Convert.ToInt32(Console.ReadLine());
// Console.WriteLine(num);
p1.setPoint(num,num);
p4.setPoint(num2,num2);
CRect cr=new CRect();
Cline cl1 = new Cline();
Console.WriteLine("p1p2={0}",cl1.Dis(p1,p4));
Console.WriteLine("Perimeter and area={0},{1}", cr.Getlength(p1, p4), cr.Getarea(p1, p4));
Console.ReadKey();
}
}
}
输入:
两个int,num和num2.构成两个坐标p1(num,num)p2(num2,num2).
输出:
两行
第一行为p1 p2 的距离,
第二行为矩形的周长和面积。
示例输入:
1
2
示例输出:
p1p2=1.4142135623731
Perimeter and area=4,1
提示:
参考答案:
文章评论