C#使用多态求方形面积周长和圆的面积周长
class class1
{
public static void Main(string[] args)
{
//使用多态求矩形面积与周长和圆的面积与周长
Shape cl = new Circle();
double clarea = cl.GetArea();
double clpar = cl.GetPerimeter();
Console.WriteLine("这个圆的面积是{0},周长是{1}", Math.Round(clarea, ), Math.Round(clpar, )); Shape sq = new Square(, );
double sqarea = sq.GetArea();
double sqpar = sq.GetPerimeter();
Console.WriteLine("这个方形的面积是{0},周长是{1}", Math.Round(sqarea, ), Math.Round(sqpar, ));
Console.ReadKey();
} } //声明一个抽像类
public abstract class Shape
{
public abstract double GetArea();
public abstract double GetPerimeter();
} class Circle:Shape
{
private double _r; public double R
{
get {
return _r;
}
set {
_r = value;
}
} public Circle(double r)
{
this.R = r;
}
public override double GetArea()
{
return Math.PI * this.R * this.R;
} public override double GetPerimeter()
{
return * Math.PI * this.R;
}
} class Square : Shape
{
private double _height;
private double _width; public double Height
{
get
{
return _height;
}
set
{
_height = value;
}
} public double Width
{
get {
return _width;
}
set {
_width = value;
}
}
public Square(double w, double h)
{
this.Height = h;
this.Width = w;
}
public override double GetArea()
{
return this.Width * this.Height;
} public override double GetPerimeter()
{
return (this.Width + this.Height) * ;
}
}
C#使用多态求方形面积周长和圆的面积周长的更多相关文章
- [SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并
[SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并 题目大意: 求\(n(n\le1000)\)个圆的面积并. 思路: 对于一个\( ...
- python脚本1_给一个半径求圆的面积和周长
#给一个半径,求圆的面积和周长,圆周率3.14 r = int(input('r=')) print('area='+str(3.14*r*r)) print('circumference='+str ...
- JAVA求圆的面积
import java.text.DecimalFormat;import java.util.Scanner; public class TheAreaOfCircle { public stati ...
- c语言求平面上2个坐标点的直线距离、求俩坐标直线距离作为半径的圆的面积、递归、菲波那次数列、explode
#include <stdio.h> #include <math.h> #include <string.h> char explode( char * str ...
- HDU 3467 (求五个圆相交面积) Song of the Siren
还没开始写题解我就已经内牛满面了,从晚饭搞到现在,WA得我都快哭了呢 题意: 在DotA中,你现在1V5,但是你的英雄有一个半径为r的眩晕技能,已知敌方五个英雄的坐标,问能否将该技能投放到一个合适的位 ...
- UVA-11983-Weird Advertisement(线段树+扫描线)[求矩形覆盖K次以上的面积]
题意: 求矩形覆盖K次以上的面积 分析: k很小,可以开K颗线段树,用sum[rt][i]来保存覆盖i次的区间和,K次以上全算K次 // File Name: 11983.cpp // Author: ...
- hdu 1255 覆盖的面积(求覆盖至少两次以上的面积)
了校赛,还有什么途径可以申请加入ACM校队? 覆盖的面积 Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- Largest Rectangle in Histogram, 求矩形图中最大的长方形面积
问题描述: Given n non-negative integers representing the histogram's bar height where the width of each ...
- YTU 2723: 默认参数--求圆的面积
2723: 默认参数--求圆的面积 时间限制: 1 Sec 内存限制: 128 MB 提交: 206 解决: 150 题目描述 根据半径r求圆的面积, 如果不指定小数位数,输出结果默认保留两位小数 ...
随机推荐
- phpcms v9为联动菜单字段添加验证提醒功能 解决标题不能为空
v9系统中,如果你在模型中添加了联动菜单字段就算你在字段设置中设置了最小值为1,提交内容之前你不选择联动菜单中的值,也不会出现类似类似“标题不能为空”这样的提示下面提供解决办法打开phpcms\lib ...
- Jquery插件模版
;(function($){ $.fn.jcDate = function(options) { var defaults = { IcoClass : "jcDateIco", ...
- 不能将值 NULL 插入列 'ID',表 'EupStoreDemoDB.dbo.OrderDiary';列不允许有 Null 值。INSERT 失败。
MVC,使用EF构建实体.将数据存入数据库,执行到_db.SaveChange()时,会报如下错误:
- IE11新特性 -- Internet Explorer 11:请不要再叫我IE
Internet Explorer 11 中的一些新特性,包括对WebGL 的支持.预抓取.预渲染.flexbox.mutationobservers 以及其他一些 Web 标准的支持.但是更有趣的是 ...
- 08 - 删除vtkDataObject中的SetWholeExtent() 方法 VTK 6.0 迁移
VTK6 引入了许多不兼容的变.其中之一是删除vtkDataObject中所有有关管道的方法.其中之一就是SetWholeExtent().SetWholeExtent()方法先前被用来管理结构话数据 ...
- 04 - 替换vtkDataObject中的GetPipelineInformation 和GetExecutive 方法 VTK 6.0 迁移
VTK6 引入了许多不兼容的变.其中之一是删除vtkDataObject中所有有关管道的方法.其中的两个方法就是GetPipelineInformation() 和 GetExecutive().这些 ...
- Ubuntu 下对ADT 添加别名(alias)
1:~$ vim .bashrc 2:在打开的.bashrc文件中加入: alias adt='./adt-bundle-linux-x86-20130729/eclipse/eclipse' 3:保 ...
- 在同一上机器上建立两个SVN服务
最快的三步: 1,SVNADMIN CREATE NAME 2, 改写CONF目录下的相关三个文件. 3,重写一个SVN的启动脚本,指定这个SVN不同的目录及端口号. [general] ### Th ...
- atof
So given a string like "2.23" your function should return double 2.23. This might seem eas ...
- 51单片机C语言学习笔记3: 存储器结构
MCS-51单片机在物理结构上有四个存储空间: 1.片内程序存储器2.片外程序存储器3.片内数据存储器4.片外数据存储器 但在逻辑上,即从用户的角度上,8051单片机有三个存储空间: 1.片内外统一编 ...