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#使用多态求方形面积周长和圆的面积周长的更多相关文章

  1. [SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并

    [SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并 题目大意: 求\(n(n\le1000)\)个圆的面积并. 思路: 对于一个\( ...

  2. python脚本1_给一个半径求圆的面积和周长

    #给一个半径,求圆的面积和周长,圆周率3.14 r = int(input('r=')) print('area='+str(3.14*r*r)) print('circumference='+str ...

  3. JAVA求圆的面积

    import java.text.DecimalFormat;import java.util.Scanner; public class TheAreaOfCircle { public stati ...

  4. c语言求平面上2个坐标点的直线距离、求俩坐标直线距离作为半径的圆的面积、递归、菲波那次数列、explode

    #include <stdio.h> #include <math.h> #include <string.h> char explode( char * str ...

  5. HDU 3467 (求五个圆相交面积) Song of the Siren

    还没开始写题解我就已经内牛满面了,从晚饭搞到现在,WA得我都快哭了呢 题意: 在DotA中,你现在1V5,但是你的英雄有一个半径为r的眩晕技能,已知敌方五个英雄的坐标,问能否将该技能投放到一个合适的位 ...

  6. UVA-11983-Weird Advertisement(线段树+扫描线)[求矩形覆盖K次以上的面积]

    题意: 求矩形覆盖K次以上的面积 分析: k很小,可以开K颗线段树,用sum[rt][i]来保存覆盖i次的区间和,K次以上全算K次 // File Name: 11983.cpp // Author: ...

  7. hdu 1255 覆盖的面积(求覆盖至少两次以上的面积)

    了校赛,还有什么途径可以申请加入ACM校队?  覆盖的面积 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  8. Largest Rectangle in Histogram, 求矩形图中最大的长方形面积

    问题描述: Given n non-negative integers representing the histogram's bar height where the width of each ...

  9. YTU 2723: 默认参数--求圆的面积

    2723: 默认参数--求圆的面积 时间限制: 1 Sec  内存限制: 128 MB 提交: 206  解决: 150 题目描述 根据半径r求圆的面积, 如果不指定小数位数,输出结果默认保留两位小数 ...

随机推荐

  1. jquery判断页面滚动条(scroll)是上滚还是下滚

    单纯判断滚动条方向 function scroll( fn ) { var beforeScrollTop = document.body.scrollTop, fn = fn || function ...

  2. htmlspecialchars()函数

    htmlspecialchars() 函数把一些预定义的字符转换为 HTML 实体. 预定义的字符是: & (和号) 成为 & " (双引号) 成为 " ' (单引 ...

  3. MySQL 插入数据时,中文乱码???问题的解决

    在终端,mysql -u root -p 登录: show variables like 'character%'; 来查看当前数据库的相关编码集. client 为客户端使用的字符集. connec ...

  4. Linux_shell条件判断if中的-a到-z的意思

    [ -a FILE ]  如果 FILE 存在则为真.  [ -b FILE ]  如果 FILE 存在且是一个块特殊文件则为真.  [ -c FILE ]  如果 FILE 存在且是一个字特殊文件则 ...

  5. Android监听事件

    ListView事件监听: setOnItemSelectedListener 鼠标滚动时触发 setOnItemClickListener 点击时触发 EditText事件监听: setOnKeyL ...

  6. PHP and java

    问题补充: 为什么不选用优秀的ASP.NET,京东做的不是很成功嘛?-----------------------------------------------------------------首 ...

  7. Oracle 客户端 NLS_LANG 的设置(转)

    1. NLS_LANG 参数组成NLS_LANG参数由以下部分组成:NLS_LANG=<Language>_<Territory>.<Clients Characters ...

  8. 【HDOJ】1406 Ferry Loading III

    模拟,注意需要比较队头与当前时间的大小关系. #include <cstdio> #include <cstring> #include <cstdlib> #de ...

  9. BZOJ1119: [POI2009]SLO

    1119: [POI2009]SLO Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 379  Solved: 181[Submit][Status] ...

  10. BZOJ1639: [Usaco2007 Mar]Monthly Expense 月度开支

    1639: [Usaco2007 Mar]Monthly Expense 月度开支 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 529  Solved: ...