《计算圆的周长和面积C++(3页).doc》由会员分享,可在线阅读,更多相关《计算圆的周长和面积C++(3页).doc(3页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、-计算圆的周长和面积C+-第 3 页#include#includeusing namespace std;const double PI=3.141593;class Circlepublic:Circle()R=1;n=counter+;Circle(int r)R=r;n=counter+;Circle();Circle(const Circle&obj)R=obj.R;n=counter+;void SetR(int r);int GetR();double GetGirth();double GetArea();static int GetCounter();int GetN();v
2、oid Print();friend void CompareS(Circle &c1,Circle &c2);private:int R;int n;static int counter;int Circle:counter=0;Circle:Circle()coutnendl;counter-;void Circle:SetR(int r)R=r;int Circle:GetR()return R;double Circle:GetGirth()return 2*PI*R;double Circle:GetArea()return PI*R*R;int Circle:GetCounter(
3、)return counter;int Circle:GetN()return n;void Circle:Print()coutCircle:GetN():endl;cout=Circle:GetR()endl;cout=Circle:GetArea()endl;cout=Circle:GetGirth()endl;coutc2.GetArea()coutc1.nendl;else if(c1.GetArea()c2.GetArea()coutc2.nendl;elsecoutc1.nc2.nendl;coutPrint();delete c4;/5Circle shuzu5;int i;for(i=0;i5;i+)shuzui.SetR(rand()%10+1);shuzui.Print();/5Circle *p=new Circle5;for(i=0;i5;i+)pi.SetR(rand()%10+1);pi.Print();delete p;return 0;