#include"iostream" using namespace std; class Shape { public: virtual float area()const { return 0.0; } virtual float volume()const { return 0.0; } virtual void shapeName()const = 0; }; class Point :public Shape { protected: float x, y; public: Point(float = 0, float = 0); void setPoint(float, float); float getX()const { return x;} float getY()const { return y; } virtual void shapeName()const { cout << "Point: ";} friend ostream & operator<<(ostream&, const Point &); }; Point::Point(float a, float b) { x = a; y = b; } void Point::setPoint(float a, float b) { x = a; y = b; } ostream & operator<<(ostream &output, const Point &p) { return output; } class Circle:public Point { public: Circle(float x = 0,float y = 0,float r = 0); void setRadius(float); float getRadius() const; virtual float area() const; virtual void shapeName() const { cout << "Circle:"; } friend ostream &operator<<(ostream &, const Circle &); protected: float radius; }; Circle::Circle(float a, float b, float r) : Point(a, b),radius(r) {} void Circle::setRadius(float r) {radius = r;} float Circle::getRadius() const { return radius; } float Circle::area() const { return 3.14159 * radius * radius; } ostream &operator<<(ostream &output,const Circle &c) { output << "[" << c.x << "," << c.y << "],r=" << c.radius; return output; } class Cylinder : public Circle { public: Cylinder(float x = 0, float y = 0, float r = 0, float h = 0); void setHeight(float); virtual float area() const; virtual float volume() const; virtual void shapeName() const { cout<<"Cylinder:"; } friend ostream &operator<<(ostream &, const Cylinder&); protected: float height; }; Cylinder::Cylinder(float a, float b, float r, float h): Circle(a, b, r), height(h) {} void Cylinder::setHeight(float h) { height = h; } float Cylinder :: area() const{return 2 * Circle::area() + 2 * 3.14159 * radius * height;} float Cylinder :: volume() const { return Circle::area() * height; } ostream &operator << (ostream &output, const Cylinder& cy) { output << "[" << cy.x << "," << cy.y << "],r=" << cy.radius << ",h=" << cy.height; return output; } int main() { Point point(3.2, 4.5); Circle circle(2.4, 1.2, 5.6); Cylinder cylinder(3.5, 6.4, 5.2, 10.5); point.shapeName(); cout << point<<endl; circle.shapeName(); cout<< circle << endl; cylinder.shapeName(); cout << cylinder << endl << endl; Shape * pt; pt = &point; pt->shapeName(); cout << "x=" << point.getX() << ",y=" << point.getY() << "\narea=" << pt->area() << "\nvolume=" << pt->volume() << "\n\n"; pt = &circle; pt->shapeName(); cout << "x=" << circle.getX() << ",y=" << circle.getY() << "\narea=" << pt->area() << "\nvolume=" << pt->volume() << "\n\n"; pt=&cylinder; pt->shapeName(); cout << "x=" << cylinder.getX() << ",y=" << cylinder.getY() << "\narea=" << pt->area() << "\nvolume=" << pt->volume() << "\n\n"; return 0; }为什么第一个Point不能输出数据

时间: 2023-06-27 11:04:13 浏览: 29
在你的代码中,第一个Point对象的输出运算符重载函数operator<<没有实际的输出语句,所以调用该函数时没有任何输出。你需要在该函数中添加输出语句,例如: ```c++ ostream & operator<<(ostream &output, const Point &p) { output << "[" << p.x << "," << p.y << "]"; return output; } ``` 这样就能正确输出第一个Point对象的数据了。

最新推荐

chromedriver_mac64_79.0.3945.36.zip

chromedriver可执行程序下载,请注意对应操作系统和浏览器版本号,其中文件名规则为 chromedriver_操作系统_版本号,比如 chromedriver_win32_102.0.5005.27.zip表示适合windows x86 x64系统浏览器版本号为102.0.5005.27 chromedriver_linux64_103.0.5060.53.zip表示适合linux x86_64系统浏览器版本号为103.0.5060.53 chromedriver_mac64_m1_101.0.4951.15.zip表示适合macOS m1芯片系统浏览器版本号为101.0.4951.15 chromedriver_mac64_101.0.4951.15.zip表示适合macOS x86_64系统浏览器版本号为101.0.4951.15 chromedriver_mac_arm64_108.0.5359.22.zip表示适合macOS arm64系统浏览器版本号为108.0.5359.22

STM32+红外模块控制格力空调

STM32+红外模块控制格力空调

Android游戏-魔法方块游戏源码(java实现,可作学习及课设使用,附运行教程)

【安卓程序——魔法方块游戏】 (1)一个包含源代码和全部配置文件的完整安卓工程包。此程序是一个经典的魔法方块游戏,它可以在安卓设备上运行,无论是手机还是平板电脑。这个程序非常适合初学者学习安卓开发,也可以供大家自行娱乐,或者作为课程设计项目。 (2)使用Java语言编写,采用了安卓开发的基础框架,包括活动(Activity)、意图(Intent)、广播接收器(Broadcast Receiver)等组件。通过此程序,初学者可以了解安卓开发的基本概念和基本操作,掌握如何使用Java语言开发安卓应用程序。 (3)源代码和配置文件完整,包括了所有必要的文件和资源。这使得学习者可以全面了解程序的各个部分,从界面设计到游戏逻辑的实现,以及如何进行调试和测试。 (4)本程序经过测试,可以保证在安卓设备上正常运行,另外附带了一份详细的运行教程,如果学习者在运行程序时遇到任何问题,可以随时联系博主进行咨询和解决。

chromedriver_linux64_70.0.3538.67.zip

chromedriver可执行程序下载,请注意对应操作系统和浏览器版本号,其中文件名规则为 chromedriver_操作系统_版本号,比如 chromedriver_win32_102.0.5005.27.zip表示适合windows x86 x64系统浏览器版本号为102.0.5005.27 chromedriver_linux64_103.0.5060.53.zip表示适合linux x86_64系统浏览器版本号为103.0.5060.53 chromedriver_mac64_m1_101.0.4951.15.zip表示适合macOS m1芯片系统浏览器版本号为101.0.4951.15 chromedriver_mac64_101.0.4951.15.zip表示适合macOS x86_64系统浏览器版本号为101.0.4951.15 chromedriver_mac_arm64_108.0.5359.22.zip表示适合macOS arm64系统浏览器版本号为108.0.5359.22

chromedriver_win32_95.0.4638.69.zip

chromedriver可执行程序下载,请注意对应操作系统和浏览器版本号,其中文件名规则为 chromedriver_操作系统_版本号,比如 chromedriver_win32_102.0.5005.27.zip表示适合windows x86 x64系统浏览器版本号为102.0.5005.27 chromedriver_linux64_103.0.5060.53.zip表示适合linux x86_64系统浏览器版本号为103.0.5060.53 chromedriver_mac64_m1_101.0.4951.15.zip表示适合macOS m1芯片系统浏览器版本号为101.0.4951.15 chromedriver_mac64_101.0.4951.15.zip表示适合macOS x86_64系统浏览器版本号为101.0.4951.15 chromedriver_mac_arm64_108.0.5359.22.zip表示适合macOS arm64系统浏览器版本号为108.0.5359.22

分布式高并发.pdf

分布式高并发

基于多峰先验分布的深度生成模型的分布外检测

基于多峰先验分布的深度生成模型的似然估计的分布外检测鸭井亮、小林圭日本庆应义塾大学鹿井亮st@keio.jp,kei@math.keio.ac.jp摘要现代机器学习系统可能会表现出不期望的和不可预测的行为,以响应分布外的输入。因此,应用分布外检测来解决这个问题是安全AI的一个活跃子领域概率密度估计是一种流行的低维数据分布外检测方法。然而,对于高维数据,最近的工作报告称,深度生成模型可以将更高的可能性分配给分布外数据,而不是训练数据。我们提出了一种新的方法来检测分布外的输入,使用具有多峰先验分布的深度生成模型。我们的实验结果表明,我们在Fashion-MNIST上训练的模型成功地将较低的可能性分配给MNIST,并成功地用作分布外检测器。1介绍机器学习领域在包括计算机视觉和自然语言处理的各个领域中然而,现代机器学习系统即使对于分

阿里云服务器下载安装jq

根据提供的引用内容,没有找到与阿里云服务器下载安装jq相关的信息。不过,如果您想在阿里云服务器上安装jq,可以按照以下步骤进行操作: 1.使用wget命令下载jq二进制文件: ```shell wget https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 -O jq ``` 2.将下载的jq文件移动到/usr/local/bin目录下,并添加可执行权限: ```shell sudo mv jq /usr/local/bin/ sudo chmod +x /usr/local/bin/jq ``` 3.检查j

毕业论文java vue springboot mysql 4S店车辆管理系统.docx

包括摘要,背景意义,论文结构安排,开发技术介绍,需求分析,可行性分析,功能分析,业务流程分析,数据库设计,er图,数据字典,数据流图,详细设计,系统截图,测试,总结,致谢,参考文献。

"结构化语言约束下的安全强化学习框架"

使用结构化语言约束指导安全强化学习Bharat Prakash1,Nicholas Waytowich2,Ashwinkumar Ganesan1,Tim Oates1,TinooshMohsenin11马里兰大学,巴尔的摩县(UMBC),2美国陆军研究实验室,摘要强化学习(RL)已经在解决复杂的顺序决策任务中取得了成功,当一个定义良好的奖励函数可用时。对于在现实世界中行动的代理,这些奖励函数需要非常仔细地设计,以确保代理以安全的方式行动。当这些智能体需要与人类互动并在这种环境中执行任务时,尤其如此。然而,手工制作这样的奖励函数通常需要专门的专业知识,并且很难随着任务复杂性而扩展。这导致了强化学习中长期存在的问题,即奖励稀疏性,其中稀疏或不明确的奖励函数会减慢学习过程,并导致次优策略和不安全行为。 更糟糕的是,对于RL代理必须执行的每个任务,通常需要调整或重新指定奖励函数。另一�