---
title: "C++圆、长方体相关计算"
author: "mywebcode"
date: "2011-11-19T20:52:00Z"
tags: []
slug: "c"
draft: false
lastmod: "2013-05-08T10:13:37Z"
id: 1862482
url: "https://mywebcode.iteye.com/blog/1862482"
---

求圆的面积和周长  
#include&lt;iostream&gt;  
using namespace std;  
double const pi=3.141595653;  
class cir  
{ double r;  
public:  
cir(double);  
void s();  
void l();  
};  
cir::cir(double r0)  
{  
r=r0;  
}  
void cir::s()  
{  
cout&lt;&lt;pi\*r\*r&lt;&lt;endl;  
}  
void cir::l()  
{  
cout&lt;&lt;2\*pi\*r&lt;&lt;endl;  
}  
int main()  
{  
cir a(10.55);  
a.s();  
a.l();  
}  
求长方体的表面积和体积  
#include&lt;iostream&gt;  
using namespace std;  
class changfangti  
{ double c,k,g;  
public:  
changfangti(double,double,double);  
void s();  
void v();  
};  
changfangti::changfangti(double c0,double k0,double g0)  
{  
c=c0,k=k0,g=g0;  
}  
void changfangti::s()  
{  
cout&lt;&lt;c\*k\*2+c\*g\*2+k\*g\*2&lt;&lt;endl;  
}  
void changfangti::v()  
{  
cout&lt;&lt;c\*k\*g&lt;&lt;endl;  
}  
int main()  
{  
changfangti a(10,10,10);  
a.s();  
a.v();  
return 0;  
}