#pragma once
class CCircle
{
public :
    
    double area();
    double girth();
    void SetRadius(double a);
    double get();
    double radius;
protected:
    const double pai = 3.14 ;
        
};
#pragma once
#include "CCircle.h"
class CCylinder:public CCircle
{
public:
    
    double LowArea();//底面积
    double LateralArea();//侧面积
    double SurfaceArea();//表面积
    double Volume();//体积
    void set(double);
    double get();
    CCylinder();
protected:
    double height;
    
    


};
#include "CCircle.h"
void CCircle::SetRadius(double a) {
    radius = a;
}
double CCircle::get() {
    return radius;

}
double CCircle::area() {
    double Area;
    Area = pai * radius*radius;
    return Area;

}
double CCircle::girth() {
    double Girth;
    Girth = 2 * pai*radius;
    return Girth;

}
#include "CCylinder.h"
#include"CCircle.h"
 CCylinder::CCylinder() {
    height = 0;
}
void CCylinder::set(double a) {
    height = a;
}
double CCylinder::get() {
    return height;
}
double CCylinder::LowArea(){
    double a=area();
    return a;

}//底面积
double CCylinder::LateralArea(){
    double a = girth();
    return a*height;

}//侧面积
double CCylinder::SurfaceArea() {
    double a = LateralArea();
    double b = LowArea();
    return a + b * 2;
}//表面积
double CCylinder::Volume() {
    return LowArea()*height;

}//体积
#include"CCircle.h"
#include"CCylinder.h"
#include<iostream>
using namespace std;
int main() {
    CCylinder b;
    b.SetRadius(1);
    b.set(1);
    cout << "面积为:" << b.area() << endl;
    cout << "周长为:" << b.girth() << endl;
    cout << "底面积为:" << b.LowArea() << endl;
    cout << "侧面积为:" << b.LateralArea() << endl;
    cout << "表面积为" << b.SurfaceArea() << endl;
    cout << "体积为" << b.Volume() << endl;
    return 0;
}
Last modification:May 11th, 2021 at 03:57 pm