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. 《python基础教程》笔记之 抽象

    创建函数 记录函数,在函数的开头写下字符串,它就会作为函数的一部分进行存储,这称为文档字符串,如 def square(x): 'Caculates the square of the number ...

  2. poj 3335 Rotating Scoreboard

    http://poj.org/problem?id=3335 #include <cstdio> #include <cstring> #include <algorit ...

  3. intrins.h 里面的函数都有什么,功能是什么?

    是c51中的intrins.h库 _crol_  字符循环左移 _cror_ 字符循环右移 _irol_   整数循环左移 _iror_  整数循环右移 _lrol_   长整数循环左移 _lror_ ...

  4. 一道考验你设计能力的C++编程题

    http://www.cppblog.com/weiym/archive/2012/06/12/178472.html

  5. Qt on Android

    Qt on Android Episode 7(翻译) http://blog.csdn.net/foruok/article/details/46323129 Android基础整理之四大组件Act ...

  6. Go语言环境配置 Sublime Text + GoSublime+ gocode + MarGo组合

    买来<Go Web编程>一书学习Go语言,结果按照书中的步骤搭建,发现部分站点已经失效了,查了网上好多教程也没有人能够说清楚如何搭建.还是自己动手找方法吧,经过自己的不懈努力终于搭建好了. ...

  7. 【转】C语言文件操作解析(三)

    原文网址:http://www.cnblogs.com/dolphin0520/archive/2011/10/07/2200454.html C语言文件操作解析(三) 在前面已经讨论了文件打开操作, ...

  8. 【转】ActionBar的基本用法

    原文网址:http://irtutsk.iteye.com/blog/2117707 ActionBar的组成: [1]AppIcon:标题区,显示应用程序图标和标题,也可以自定义. [2]ViewC ...

  9. ASP.NET获取IP的6种方法(转载于LanceZhang's Tech Blog)

    服务端: //方法一 HttpContext.Current.Request.UserHostAddress; //方法二 HttpContext.Current.Request.ServerVari ...

  10. chinaOS

    从舆论上和政策规定上来推广操作系统,这对国产操作系统而言是好事,还是坏事? 从某种程度上来说,这是好事 运用行政的力量,率先在国家机关中普及国产操作系统确实是件好事,首先是确保了国家信息安全,其次则能 ...