没有显示错误,程序运行不了
#pragma once
class Shape
{
public:
virtual float get_surface();//表面积
virtual float get_volume();//体积
virtual void setput();//输入
virtual void display();//输出
Shape();
~Shape();
};
class Cylinder :public Shape
{
private:
float r;
float h;
public:
Cylinder();
float get_surface();//表面积
float get_volume();//体积
void setput();//输入
void display();//输出
~Cylinder();
};
class Sphere :public Shape
{
private:
float r;
public:
Sphere();
float get_surface();//表面积
float get_volume();//体积
void setput();//输入
void display();//输出
~Sphere();
};
class Cube :public Shape
{
private:
float b;
public:
Cube();
float get_surface();//表面积
float get_volume();//体积
void setput();//输入
void display();//输出
~Cube();
};
#include<iostream>
using namespace std;
#include"b.h"
float Shape::get_surface()
{
return 0.0;
}
float Shape::get_volume()
{
return 0.0;
}
void Shape::setput()
{
cout << "NULL" << endl;
}
void Shape::display()
{
cout << "NULL" << endl;
}
Shape::Shape()
{
cout << "Shape 构造函数" << endl;
}
Shape:: ~Shape()
{
cout << "Shape 析构函数" << endl;
}
Cylinder::Cylinder()
{
r = 0.0;
h = 0.0;
}
void Cylinder::setput()
{
cout << "输入圆柱的边长" << endl;
cin >> r;
cout << "输入圆柱的高" << endl;
cin >> h;
}
float Cylinder::get_surface()
{
cout << 3.14 * 2 * r * r + 2 * 3.14 * r * h << endl;
}
float Cylinder::get_volume()
{
cout << 3.14 * r * r * h << endl;
}
Cylinder::~Cylinder()
{
cout << "Cylinder 析构函数" << endl;
}
Sphere::Sphere()
{
r = 0.0;
}
void Sphere::setput()
{
cout << "输入球体的边长" << endl;
cin >> r;
}
float Sphere::get_surface()
{
cout << 4 * 3.14 * r * r << endl;
}
float Sphere::get_volume()
{
cout << (4.0 / 3) * 3.14 * r * r * r << endl;
}
Sphere::~Sphere()
{
cout << "Sphere析构函数" << endl;
}
Cube::Cube()
{
b = 0.0;
}
void Cube::setput()
{
cout << "输入正方体的边长" << endl;
cin >> b;
}
float Cube::get_surface()
{
cout << 6 * b * b << endl;
}
float Cube::get_volume()
{
cout << b * b * b << endl;
}
Cube::~Cube()
{
cout << "Cube析构函数" << endl;
}
int main()
{
Cylinder c;
c.setput();
c.get_volume();
c.get_surface();
Sphere s;
s.setput();
s.get_volume();
s.get_surface();
Cube cu;
cu.setput();
cu.get_volume();
cu.get_surface();
}