C#用类的继承计算球表面积和体积
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/17 14:15:51
精确的球的表面积计算公式:球的表面积=4πr^2,r为球半径,公式唯一.精确的球的体积计算公式:V球=(4/3)πr^3,r为球半径,公式唯一.
namespaceEX1_4{publicclassshape{publicdoublePI=3.14;}publicclassRectangle:shape{publicintx,y,s,l;pub
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceConsoleApplic
classShape{voidarea(){}voidcircle(){}}publicclassTriangleextendsShape{floatarea(floati,floatj){retur
图形抽象类的代码:abstractclassMyShape{abstractintcalGirth();//求周长abstractdoublecalSquare();//求面积}三角形类的实现:pub
#include#definepi3.14usingnamespacestd;classCyuan{public:\x05Cyuan(doubler)\x05{\x05\x05R=r;\x05}\x0
S=4πR^2
publicclassCubeextendsSquareimplementsVolume{@OverridepublicdoublegetArea(){return6*width*width;
classSharp{publicvirtualSun(){}}classSharp_Par1:Sharp{publicPointP1,P2,P2;publicoveridesSun(){}}再问:完
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceCompare_Numbe
#include#include#defineN3.14159//宏定义π=3.14159usingnamespacestd;//定义基类classbase{protected:doubler;//
和圆锥体类publicclassDu{\x05publicstaticvoidmain(String[]args){\x05}}classRectangle{\x05protecteddoublele
protectedintSum(){intSum100=0;for(inti=1;i再问:这个好像不是c#吧?我要的是c#语句哦!cy语言我不懂呢!谢谢再答:这个不是C#语言?很肯定的告诉你,这个是C
利用数组的方法int[]numbers=newint[]{123,232,545.};intcount=0,sum=0;foreach(intninnumbers){if(n>=500){sum=n;
x=a%b;z=a/b;前提是都是整型(int)的,不带小数点的再问:a/b不就是会有小数了么?如何取整数?再答:inta=37627;intb=60;x=a%b;z=a/b;定义成int型之后,就不
#include#include#defineN3.1415usingnamespacestd;classHeight{private:floath;public:Height(floath):h
盒子类:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceClassLibr
intsum=0;for(inti=1;i
#include"iostream.h"classCircle//基类圆{public:doubler;public:voidprint(){cout
#include#includeusingnamespacestd;classCcircle{protected:floatr;public:};classCsphere:publicCcircle{