B 继承 圆到圆柱体

B 继承 圆到圆柱体

Circle圆形类定义如下:

class Circle
{
public:
protected:
};

#include <iostream>
#include <iomanip>
using namespace std;

#define PI 3.14

class Circle
{
public:
protected:
};

//将程序需要的其他成份写在下面，只提交begin到end部分的代码
//******************** begin ********************

//********************* end ********************

int main()
{
double r,h;

cout<<setiosflags(ios::fixed);
cout<<setprecision(2);

cin>>r;
Circle c(r);
cout<<c.area()<<endl;

cin>>r>>h;
Cylinder cy(r,h);
cout<<cy.area()<<" "<<cy.volume()<<endl;

return 0;
}

圆的面积

``````1
2 2.5``````

``````3.14
56.52 31.40``````

``````#include<stdio.h>
int main()
{
float pi=3.14,a,b,c;
scanf("%f",&a);
scanf("%f %f",&b,&c);
printf("%.2f\n%.2f %.2f\n",pi*a*a,2*pi*b*c+2*pi*b*b,pi*b*b*c);

}``````

``````
#include <iostream>
#include <iomanip>
using namespace std;

#define PI 3.14

class Circle
{
public:
protected:
};
class Cylinder
{
public:
Cylinder(double a,double b)
{
r=a;
h=b;
}
double area(){return (2*PI*r*r+2*PI*r*h);}
double volume(){return (PI*r*r*h);}
double r,h;
};
int  main()
{
double r,h;
cout<<setiosflags(ios::fixed);
cout<<setprecision(2);

cin>>r;
Circle c(r);
cout<<c.area()<<endl;

cin>>r>>h;
Cylinder cy(r,h);
cout<<cy.area()<<" "<<cy.volume()<<endl;

return 0;
}
``````