# 圆柱体的C++

C代码：
#include <stdio.h>
#define PI 3.1415926
int main()
{
int r,h;
double area,V,basal_area,lateral_area;
double C;
scanf("%d %d",&r,&h);
basal_area=PI*r*r;
C=2*PI*r;
lateral_area=C*h;
area=basal_area*2+lateral_area;
V=basal_area*h;
printf("basal_area:%.2lf\n",basal_area);
printf("lateral_area:%.2lf\n",lateral_area);
printf("area:%.2lf\n",area);
printf("V:%.2lf\n",V);
return 0;
}
C++代码：
#include <iostream>
#include <iomanip>
using namespace std;
#define PI 3.1415926
/******************/

class Cylinder
{
public:
double area,V,basal_area,lateral_area;
void calculate(......)
{
}
void display()
{
}
};
/*******************/
int main()
{
Cylinder c;
int r,h;
cin>>r>>h;
c.calculate(r,h);
c.display();
return 0;
}

``````1 2
``````

``````basal_area:3.14
lateral_area:12.57
area:18.85
V:6.28
``````

``````#include <stdio.h>
#define PI 3.1415926
int main()
{
int r,h;
double area,V,basal_area,lateral_area;
double C;
scanf("%d %d",&r,&h);
basal_area=PI*r*r;
C=2*PI*r;
lateral_area=C*h;
area=basal_area*2+lateral_area;
V=basal_area*h;
printf("basal_area:%.2lf\n",basal_area);
printf("lateral_area:%.2lf\n",lateral_area);
printf("area:%.2lf\n",area);
printf("V:%.2lf\n",V);
return 0;
}``````

``````
#include <iostream>
#include <iomanip>
using namespace std;
#define PI 3.1415926
class Cylinder
{
public:
double area,V,basal_area,lateral_area;
void calculate(int r,int h)
{
double C;
basal_area=PI*r*r;
C=2*PI*r;
lateral_area=C*h;
area=basal_area*2+lateral_area;
V=basal_area*h;
}
void display()
{
cout<<setiosflags(ios::fixed)<<setprecision(2);
cout<<"basal_area:"<<basal_area<<endl;
cout<<"lateral_area:"<<lateral_area<<endl;
cout<<"area:"<<area<<endl;
cout<<"V:"<<V<<endl;
}
};

int main()
{
Cylinder c;
int r,h;
cin>>r>>h;
c.calculate(r,h);
c.display();
return 0;
}
``````