c#编程题
c#编程题把定义平面直角坐标系上的一个点的类Cpoint作为基类,派生出描述一条直线的类Cline,再派生出一个矩形类Crect.要求成员函数能够求出两点间的距离,矩形的...
c#编程题 把定义平面直角坐标系上的一个点的类Cpoint作为基类,派生出描述一条直线的类Cline,再派生出一个矩形类Crect.要求成员函数能够求出两点间的距离,矩形的周长和面积等.构造完整的程序并设计一个测试程序.....在线等,绝对追加.也可以发邮箱15966910276@139.com
展开
3个回答
展开全部
class Program
{
static void Main(string[] args)
{
//定义一个点
Cpoint cpoint = new Cpoint(1,2);
Console.WriteLine("点的坐标为({0},{1})",cpoint.X,cpoint.Y);
//定义一条直线
Cline cline = new Cline(1, 1, 3, 3);
Console.WriteLine("直线的长度为{0}", cline.GetLength());
//定义一个矩形
Crect crect = new Crect(1, 1, 3, 3);
Console.WriteLine("矩形的周长为{0},面积为{1}", crect.GetLength(), crect.GetArea());
Console.ReadLine();
}
}
class Cpoint
{//点类
private double x;//坐标x轴的值
public double X
{
get { return x; }
set { x = value; }
}
private double y;//坐标y轴的值
public double Y
{
get { return y; }
set { y = value; }
}
public Cpoint()
{//没有参数的构造函数
this.X = 0;
this.Y = 0;
}
public Cpoint(double x, double y)
{//有参数的构造函数
this.X = x;
this.Y = y;
}
}
class Cline : Cpoint
{
//直线类
private Cpoint a = new Cpoint();//直线的一个端点
public Cpoint A
{
get { return a; }
set { a = value; }
}
private Cpoint b = new Cpoint();//直线的另一个端点
public Cpoint B
{
get { return b; }
set { b = value; }
}
//有参数的构造函数
public Cline(double a1, double a2, double b1, double b2)
{
A.X = a1;
A.Y = a2;
B.X = b1;
B.Y = b2;
}
//求直线长度
public double GetLength()
{
double m = A.X - B.X;
double n = A.Y - B.Y;
return Math.Sqrt(Math.Pow(m, 2) + Math.Pow(n, 2));
}
}
class Crect : Cpoint
{//矩形类
private Cpoint a = new Cpoint();//矩形的一个端点
public Cpoint A
{
get { return a; }
set { a = value; }
}
private Cpoint b = new Cpoint();//与a为对角的点
public Cpoint B
{
get { return b; }
set { b = value; }
}
//有参数的构造函数
public Crect(double a1, double a2, double b1, double b2)
{
A.X = a1;
A.Y = a2;
B.X = b1;
B.Y = b2;
}
//求周长
public double GetLength()
{
double m = Math.Abs(A.X - B.X);
double n = Math.Abs(A.Y - B.Y);
return 2.0 * (m + n);
}
//求面积
public double GetArea()
{
double m = Math.Abs(A.X - B.X);
double n = Math.Abs(A.Y - B.Y);
return m * n;
}
}
{
static void Main(string[] args)
{
//定义一个点
Cpoint cpoint = new Cpoint(1,2);
Console.WriteLine("点的坐标为({0},{1})",cpoint.X,cpoint.Y);
//定义一条直线
Cline cline = new Cline(1, 1, 3, 3);
Console.WriteLine("直线的长度为{0}", cline.GetLength());
//定义一个矩形
Crect crect = new Crect(1, 1, 3, 3);
Console.WriteLine("矩形的周长为{0},面积为{1}", crect.GetLength(), crect.GetArea());
Console.ReadLine();
}
}
class Cpoint
{//点类
private double x;//坐标x轴的值
public double X
{
get { return x; }
set { x = value; }
}
private double y;//坐标y轴的值
public double Y
{
get { return y; }
set { y = value; }
}
public Cpoint()
{//没有参数的构造函数
this.X = 0;
this.Y = 0;
}
public Cpoint(double x, double y)
{//有参数的构造函数
this.X = x;
this.Y = y;
}
}
class Cline : Cpoint
{
//直线类
private Cpoint a = new Cpoint();//直线的一个端点
public Cpoint A
{
get { return a; }
set { a = value; }
}
private Cpoint b = new Cpoint();//直线的另一个端点
public Cpoint B
{
get { return b; }
set { b = value; }
}
//有参数的构造函数
public Cline(double a1, double a2, double b1, double b2)
{
A.X = a1;
A.Y = a2;
B.X = b1;
B.Y = b2;
}
//求直线长度
public double GetLength()
{
double m = A.X - B.X;
double n = A.Y - B.Y;
return Math.Sqrt(Math.Pow(m, 2) + Math.Pow(n, 2));
}
}
class Crect : Cpoint
{//矩形类
private Cpoint a = new Cpoint();//矩形的一个端点
public Cpoint A
{
get { return a; }
set { a = value; }
}
private Cpoint b = new Cpoint();//与a为对角的点
public Cpoint B
{
get { return b; }
set { b = value; }
}
//有参数的构造函数
public Crect(double a1, double a2, double b1, double b2)
{
A.X = a1;
A.Y = a2;
B.X = b1;
B.Y = b2;
}
//求周长
public double GetLength()
{
double m = Math.Abs(A.X - B.X);
double n = Math.Abs(A.Y - B.Y);
return 2.0 * (m + n);
}
//求面积
public double GetArea()
{
double m = Math.Abs(A.X - B.X);
double n = Math.Abs(A.Y - B.Y);
return m * n;
}
}
展开全部
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Crect rect = new Crect() { X = 1, X2 = 2, Y = 0, Y2 = 1 };
Console.WriteLine(rect.Length);
Console.WriteLine(rect.Perimeter);
Console.WriteLine(rect.Area);
}
}
internal class Cpoint
{
public double X { get; set; }
public double Y { get; set; }
}
internal class Cline : Cpoint
{
public double X2 { get; set; }
public double Y2 { get; set; }
public double Length
{
get
{
return Math.Sqrt(Math.Pow(Math.Abs(X2 - X), 2.0) + Math.Pow(Math.Abs(Y2 - Y), 2.0));
}
}
}
internal class Crect : Cline
{
public double Perimeter
{
get
{
return 2 * (Math.Abs(X2 - X) + Math.Abs(Y2 - Y));
}
}
public double Area
{
get
{
return Math.Abs(X2 - X) * Math.Abs(Y2 - Y);
}
}
}
}
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Crect rect = new Crect() { X = 1, X2 = 2, Y = 0, Y2 = 1 };
Console.WriteLine(rect.Length);
Console.WriteLine(rect.Perimeter);
Console.WriteLine(rect.Area);
}
}
internal class Cpoint
{
public double X { get; set; }
public double Y { get; set; }
}
internal class Cline : Cpoint
{
public double X2 { get; set; }
public double Y2 { get; set; }
public double Length
{
get
{
return Math.Sqrt(Math.Pow(Math.Abs(X2 - X), 2.0) + Math.Pow(Math.Abs(Y2 - Y), 2.0));
}
}
}
internal class Crect : Cline
{
public double Perimeter
{
get
{
return 2 * (Math.Abs(X2 - X) + Math.Abs(Y2 - Y));
}
}
public double Area
{
get
{
return Math.Abs(X2 - X) * Math.Abs(Y2 - Y);
}
}
}
}
追问
调试了,好多错
追答
VS2010测试通过,你用的是低版本?
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
怎么你这么多题目啊,
你的cRect 是继承cline 呢还是CPoint
你的cRect 是继承cline 呢还是CPoint
追问
CPoint
追答
哦,好的。
上面的哥们很犀利了,已经能满足你的题目了,我不写了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询