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求圆的面积, 如果不指定小数位数,输出结果默认保留两位小数 ...
随机推荐
- java Socket 长连接 心跳包 客户端 信息收发 demo
今天写了个socket的测试小程序,代码如下 import java.io.IOException; import java.io.InputStream; import java.io.Output ...
- css3动画和jquery动画使用中要注意的问题
前一阵子写demo的时候遇到这样一个问题,就是给元素添加css3或者jquery动画时,在动画结束前不能准确取到元素的css属性. 1. css3动画讨论 先看代码: html: <div id ...
- Java Tomcat 中调用.net DLL的方法
近日一个java的项目,客户要求项目中必须使用其提供的加密机制,扔给了两个.net写的DLL.网络上搜了一圈也没找到啥东西,甚至看到人扬言此事绝无可能.郁闷当中考虑了一个思路.用C#做一个Com,调用 ...
- python之socket编程
本章内容 1.socket 2.IO多路复用 3.socketserver Socket socket起源于Unix,而Unix/Linux基本哲学之一就是“一切皆文件”,对于文件用[打开][读写][ ...
- C程序设计语言练习题1-19
练习1-19 编写函数reverse(s),将字符串s中的字符顺序颠倒过来.使用该函数编写一个程序,每次颠倒一个输入行中的字符顺序.代码如下: #include <stdio.h> // ...
- C语言文件操作解析(五)之EOF解析(转载)
C语言文件操作解析(五)之EOF解析 在C语言中,有个符号大家都应该很熟悉,那就是EOF(End of File),即文件结束符.但是很多时候对这个理解并不是很清楚,导致在写代码的时候经常出错,特 ...
- java之多线程的理解
线程的属性 (1)线程的状态 线程在它的生命周期中可能处于以下几种状态之一: New(新生):线程对象刚刚被创建出来: Runnable(可运行):在线程对象上调用start方法后,相应线程便 ...
- 无递归 A星寻路算法
整理硬盘的时候,发现我早些年写的A星寻路算法.特放上来,待有缘人拿去,无递归噢,性能那是杠杠的. 码上伺候 public class Node { public int X { get; set; } ...
- Jackknife,Bootstraping, bagging, boosting, AdaBoosting, Rand forest 和 gradient boosting的区别
引自http://blog.csdn.net/xianlingmao/article/details/7712217 Jackknife,Bootstraping, bagging, boosting ...
- RAILS ON
我是按照下面这个URL来轻快安装的. http://lxiaodao.iteye.com/blog/1579992 (1)RVM官方网站应该是改版过一次, 使用 curl -L https://get ...