点线面

2020年1月17日 1575点热度 0人点赞 0条评论

点线面

时间: 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

提示:

参考答案:

解锁文章

没有看到答案?微信扫描二维码可免费解锁文章

微信扫描二维码解锁

使用微信扫描二维码打开广告页面后可以立即关闭,再刷新此页面即可正常浏览此文章

所跳转广告均由第三方提供,并不代表本站观点!

已经扫描此二维码?点此立即跳转

code

这个人很懒,什么都没留下

文章评论