m0_63133201 2022-05-29 19:49 采纳率: 87%
浏览 14
已结题

没有提醒错误,运行不了

没有显示错误,程序运行不了

#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();
}
问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
  • 写回答

1条回答 默认 最新

  • 浪客 2022-05-29 20:58
    关注

    display()没有实现。
    好几个float函数没有返回值

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 6月7日
  • 已采纳回答 5月30日
  • 创建了问题 5月29日

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP