定义一个类,封装矩形的长和宽;在定义一个类,继承自定义的这个类,在继承类中根据基类中封装的矩形的长和宽求矩形的面积。
2017-10-12 15:28
363 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 封装长方体
{
class Rectangle
{
protected double width;
protected double height;
public double Width
{
get { return this.width; }
set { this.width = value; }
}
public double Height
{
get { return this.height; }
set { this.height = value; }
}
public double getArea()
{
return this.height * this.width;
}
public void display()
{
Console.WriteLine("长度:{0}", height);
Console.WriteLine("宽度:{0}", width );
Console.WriteLine("面积:{0}", getArea ());
}
}
class Program
{
static void Main(string[] args)
{
Rectangle r = new Rectangle();
r.Width = 4.5;
r.Height = 3.5;
r.display();
Console.ReadKey();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 封装长方体
{
class Rectangle
{
protected double width;
protected double height;
public double Width
{
get { return this.width; }
set { this.width = value; }
}
public double Height
{
get { return this.height; }
set { this.height = value; }
}
public double getArea()
{
return this.height * this.width;
}
public void display()
{
Console.WriteLine("长度:{0}", height);
Console.WriteLine("宽度:{0}", width );
Console.WriteLine("面积:{0}", getArea ());
}
}
class Program
{
static void Main(string[] args)
{
Rectangle r = new Rectangle();
r.Width = 4.5;
r.Height = 3.5;
r.display();
Console.ReadKey();
}
}
}
相关文章推荐
- 编写一个程序定义抽象类有他派生五个派生类 圆 正方形 矩形 梯形 三角形用函数分别求面积 总面积 要求用基类指针数组
- 在程序中定义一个基类Person类,由这个基类派生出Teacher(教师)类和Leader(领导)类。采用多继承的方式由这两个类派生出Teacher_Leader类。并且满足以下要求:
- 写一个程序,定义抽象基类Shape,由它派生出3个派生类,Circle(圆形)、Rectangle(矩形)、Triangle(三角形)。用如下的main()函数,求出定义的几个几何体的面积和。
- 已知一个抽象类Shapge,该类中有一个方法GetArea。 要求定义一个Rectangle类,继承Shape类,实现GetArea方法计算矩形面积。
- 写一个程序,定义抽象基类Shape,由它派生出3个派生类,Circle(圆形)、Rectangle(矩形)、Triangle(三角形)。用如下的main()函数,求出定义的几个几何体的面积和
- 【java学习记录】7.定义一个接口ArearInterface,其中包含一个方法,计算面积三角形、矩形、圆形的面积
- 《第十三周任务三》写一个程序,定义抽象基类Shape,由它派生出3个派生类,Circle(圆形)、Rectangle(矩形)、Triangle(三角形)。用如下的mian()函数,求出定义的几个几何体
- 飛飛(四十七)定义抽象基类Shape,由它派生出3个派生类,Circle(圆形)、Rectangle(矩形)、Triangle(三角形)。用如下的main()函数,求出定义的几个几何体的面积和。
- OC继承(写一个图形类,实现三角形,矩形和三角形求面积和周长)
- 【java学习记录】2.定义一个计算矩形面积、立方体和球体体积的类,该类完成计算的方法用静态方法实现
- 工厂模式:封装对象的创建(一、在基类中定义一个静态成员函数)
- 2016/1/18 更正补充 2016/1/17 矩形面积 1,构造方法初始化 长和宽 ,2, 定义成员方法求矩形面积
- 给你一个单词a,如果通过交换单词中字母的顺序可以得到另外的单词b,那么定义b是a的兄弟单词。现在给你一个字典,用户输入一个单词,让你根据字典找出这个单词有多少个兄弟单词。
- 4.根据下面的主类,编写一个立方体类Cube,该类中有求矩形面积area()和体积volume()的方法,而且每种方法都有一个无参的和有参的方法构成过载。
- 作业2:设计并测试一个名为Rectangle的矩形类,其属性为矩形的左下角与右上角两个点的坐标,根据坐标能计算出矩形的面积
- C++设计并测试一个名为Rectangle的矩形类,其属性为矩形的左下角与右下角两个点的坐标,根据坐标计算矩形的面积
- 定义一个矩形类(Rectangle),私有数据成员为矩形的长度( len)和宽度(wid),缺省构造函数置len和wid为0,有参构造函数置len和wid为对应形参的值,另外还包括求矩形周长、面积
- 第十三周【任务三】【任务3】写一个程序,定义抽象基类Shape,由它派生出3个派生类,Circle(圆形)、Rectangle(矩形)、Triangle(三角形)。
- 尝试编写一个矩形类,将长与宽作为矩形类的属性,在构造方法中将长。宽初始化,定义一个成员方法求此矩形的面积。
- 写一个程序,定义抽象基类Shape,由它派生出3个派生类: Circle(圆形)、Rectangle(矩形)、Triangle(三角形)