要求定义一个描述形状的抽象类shape,类内包括求面积的area和求各图形总面积的total函数。
1.从shape派生出三角形,圆形,正方形类,要求类中有构造函数,修改显示成元值的函数,求面积的函数。2.写main()函数,计算三边为7,8,9的三角形,边长为9.9的...
1.从shape派生出三角形,圆形,正方形类,要求类中有构造函数,修改显示成元值的函数,求面积的函数。
2.写main()函数,计算三边为7,8,9的三角形,边长为9.9的正方形和半径为4的圆形(必须调用total函数计算) 诸位大侠帮忙忙吧。。。考试要用。。。谢谢啦
程序问题不大,关键是total函数,怎么在shape类中声明定义,以及是在main函数中,怎样调用。。。谢谢大家,希望可以针对问题。。。 展开
2.写main()函数,计算三边为7,8,9的三角形,边长为9.9的正方形和半径为4的圆形(必须调用total函数计算) 诸位大侠帮忙忙吧。。。考试要用。。。谢谢啦
程序问题不大,关键是total函数,怎么在shape类中声明定义,以及是在main函数中,怎样调用。。。谢谢大家,希望可以针对问题。。。 展开
展开全部
class Trapezoid : public Shape
{
private:
double top;
double bottom;
double height;
public:
Trapezoid(double t, double b, double h)
{
top = t;
bottom = b;
height = h;
}
double Area()
{
return (top + bottom) * height / 2;
}
};
#define PI 3.1415926
class Circle : public Shape
{
private:
double r;
public:
Circle(double r)
{
this->r = r;
}
double Area()
{
return PI * r * r;
}
};
class Triangle : public Shape
{
private:
double bottom;
double height;
public:
Triangle(double b, double h)
{
bottom = b;
height = h;
}
double Area()
{
return bottom * height / 2;
}
};
{
private:
double top;
double bottom;
double height;
public:
Trapezoid(double t, double b, double h)
{
top = t;
bottom = b;
height = h;
}
double Area()
{
return (top + bottom) * height / 2;
}
};
#define PI 3.1415926
class Circle : public Shape
{
private:
double r;
public:
Circle(double r)
{
this->r = r;
}
double Area()
{
return PI * r * r;
}
};
class Triangle : public Shape
{
private:
double bottom;
double height;
public:
Triangle(double b, double h)
{
bottom = b;
height = h;
}
double Area()
{
return bottom * height / 2;
}
};
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
public abstract class Shapes
{
protected int _xval;
protected int _yval;
protected int _width;
protected int _height;
public abstract void draw();
}
public class Circle:Shapes
{
public Circle(int xvalue, int yvalue, int widthvalue, int heightvalue)
{
this._xval = xvalue;
this._yval = yvalue;
this._width = widthvalue;
this._height = heightvalue;
}
public override void draw()
{
Console.WriteLine("用于绘制圆的值为:");
Console.WriteLine("x坐标={0}",this._xval);
Console.WriteLine("y坐标={0}",this._yval);
Console.WriteLine("宽={0}", this._width);
Console.WriteLine("高={0}", this._height);
}
}
class Program
{
static void Main(string[] args)
{
Circle c = new Circle(2,2,5,5);
c.draw();
Console.Read();
}
}
}
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
public abstract class Shapes
{
protected int _xval;
protected int _yval;
protected int _width;
protected int _height;
public abstract void draw();
}
public class Circle:Shapes
{
public Circle(int xvalue, int yvalue, int widthvalue, int heightvalue)
{
this._xval = xvalue;
this._yval = yvalue;
this._width = widthvalue;
this._height = heightvalue;
}
public override void draw()
{
Console.WriteLine("用于绘制圆的值为:");
Console.WriteLine("x坐标={0}",this._xval);
Console.WriteLine("y坐标={0}",this._yval);
Console.WriteLine("宽={0}", this._width);
Console.WriteLine("高={0}", this._height);
}
}
class Program
{
static void Main(string[] args)
{
Circle c = new Circle(2,2,5,5);
c.draw();
Console.Read();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询