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日

悬赏问题

  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写