求各位大神。帮忙

yd2011222 2015-05-06 10:17:21
#include<iostream>
#include <cmath>
using namespace std;

const double PI = 3.14159;
class Point
{
private:
double x, y;
public:
Point(double xx=0, double yy=0){
x = xx;
y = yy;
}
void set(double xx = 0, double yy = 0)
{
x = xx;
y = yy;
}

void display()
{
cout << "(" << x << "," << y << ")" << endl;
}
double getX(){

return x;
}
double getY(){
return y;
}
double distance(Point n){
double dx = x - n.x;
double dy = y - n.y;
return sqrt(dx*dx + dy*dy);

}
};

class Rectangle :public Point //矩形
{
protected:
double length, width;
Point center;
public:
Rectangle(double l=1, double w=1, double xx=0, double yy=0) :Point(xx, yy), length(l), width(w){}
void set(double l = 0, double w = 0, double xx = 0, double yy = 0)
{
Point::set(xx,yy);
length = l;
width = w;
}

double Area()
{
return length*width;
}

double Peri()
{
return (length + width) * 2;
}
Point getcenter(){
return center;
}

void display()
{
cout << "矩形的中心坐标:";
Point::display();
cout << "矩形的长度: " << length << endl;
cout << "矩形的宽度: " << width << endl;
}
};

class Circle : public Point //圆形
{
protected:
double radius;
Point center;
public:
Circle(double R=1, double xx=0, double yy=0) :Point(xx, yy), radius(R){}
void set(double R = 0, double xx = 0, double yy = 0)
{
Point::set(xx, yy);
radius = R;
}

double Area()
{
return PI*radius*radius;
}

double Peri()
{
return 2 * PI*radius;
}
Point getcenter(){
return center;
}
void display()
{
cout << "圆形的中心坐标::" ;
Point::display();
cout << "圆形的半径: " << radius << endl;

}
};

class Triangle : public Point // 三角形
{

protected:
double SideA, SideB, SideC;
double l;
Point center;

public:
Triangle(double sa=3, double sb=4, double sc=5, double xx=0, double yy=0) :Point(xx, yy), SideA(sa), SideB(sb), SideC(sc){}
void set(double sa = 0, double sb = 0, double sc = 0, double xx = 0, double yy = 0)
{
Point::set(xx, yy);
SideA = sa;
SideB = sb;
SideC = sc;
}

double Area()
{
l = (SideA + SideB + SideC) / 2;
return sqrt(l*(l - SideA)*(l - SideB)*(l - SideC));
}

double Peri()
{
return SideA + SideB + SideC;
}
Point center(){
return center;
}
void display()
{
cout << "三角形的中心坐标:" ;
Point::display();
cout << "三角形的三条边:" << SideA << " " << SideB << " " << SideC << endl;
}
};

class RecCuboid :public Rectangle //长方体
{
private:
double high;
public:
RecCuboid(double h=1, double l=1, double w=1, double xx=0, double yy=0) :Rectangle(l, w, xx, yy), high(h){}
void set(double h = 0, double l = 0, double w = 0, double xx = 0, double yy = 0)
{
Rectangle::set(l, w, xx, yy);
high = h;
}

double Volume()
{
cout << "长方体的体积 :" << length*width*high << endl;
return 0;
}
void display(){
Rectangle::display();
cout << "长方体的高度:" << high << endl;

}
};

class CirCuboid :public Circle //圆柱
{
private:
double high;
public:
CirCuboid(double h=1, double r=1, double xx=0, double yy=0) :Circle(r, xx, yy), high(h){}
void set(double h = 0, double r = 0, double xx = 0, double yy = 0)
{
Circle::set(r, xx, yy);
high = h;
}

double Volume()
{
cout << "圆柱的体积 :" << PI*radius*radius*high << endl;
return 0;
}
void display(){
Circle::display();
cout << "圆柱的高度:" << high << endl;

}
};

class TriCuboid :public Triangle //三菱住
{
private:
double high;
public:
TriCuboid(double h=1, double sa=3, double sb=4, double sc=5, double xx=0, double yy=0) :Triangle(sa, sb, sc, xx, yy), high(h){}
void set(double h = 1, double sa = 0, double sb = 0, double sc = 0, double xx = 0, double yy = 0)
{
Triangle::set(sa, sb, sc, xx, yy);
high = h;
}

double Volume()
{
cout << "三菱住的体积 :" << sqrt(0.33*l*(l - SideA)*(l - SideB)*(l - SideC))*high << endl;
return 0;
}
void display(){
Triangle::display();
cout << "三菱柱的高度:" << high << endl;

}
};
void display(Point &pp,int type){
Rectangle *pr;
Circle *pc;
Triangle *pt;
CirCuboid *pcu;//长方体、
RecCuboid *pcy;//圆柱
TriCuboid *ptr; //三菱柱
switch (type){
case 1:
pr = reinterpret_cast<Rectangle *>(&pp);
cout << "矩形的面积;" << pr->Area() <<"/t矩形的周长:"<<pr->Peri()<< endl;
break;
case 2:
pc = reinterpret_cast<Circle *>(&pp);
cout << "圆形的面积;" << pc->Area() << "/t圆形的周长:" << pc->Peri() << endl;
break;
case 3:
pt = reinterpret_cast<Triangle *>(&pp);
cout << "三角形的面积;" << pt->Area() << "/t三角形的周长:" << pt->Peri() << endl;
break;
case 11:
pcu = reinterpret_cast<CirCuboid *>(&pp);
cout << "长方体的体积:" << pcu->Volume() << endl;
break;
case 12:
pcy = reinterpret_cast<RecCuboid *>(&pp);
cout << "圆柱的体积:" << pcy->Volume() << endl;
break;
case 13:
ptr = reinterpret_cast<TriCuboid *>(&pp);
cout << "三菱柱的体积:" << ptr->Volume() << endl;
break;

}





}
double distance(const Point &rp1,const Point &rp2){
double dx = rp1.getX() - rp2.getX();
double dy = rp1.getY() - rp2.getY();
return sqrt(dx*dx + dy*dy);
}
int main()
{
Point objPoint;
objPoint.set(5.10);
cout << "点的坐标为:";
objPoint.display();
cout << " " << endl;

Rectangle objRectangle;
objRectangle.set(10, 15, 20, 40);
objRectangle.display();
cout << "矩形的面积:" << objRectangle.Area() << endl;
cout << "矩形的周长:" << objRectangle.Peri() <<endl;
cout << " " << endl;

Circle objCircle;
objCircle.set(10, 15, 30);
objCircle.display();
cout << "圆形的面积:" <<objCircle.Area()<< endl;
cout << "圆形的周长:" << objCircle.Peri() << endl;
cout << " " << endl;
Triangle objTriangle;
objTriangle.set(30, 35, 40, 15, 20);
objTriangle.display();
cout << "三角形的面积:" << objTriangle.Area() << endl;
cout << "三角形的周长:" << objTriangle.Peri() << endl;
cout << " " << endl;

RecCuboid objRecCuboid;
objRecCuboid.set(10, 15, 20, 40,16);
objRecCuboid.display();
cout << "长方体的体积:" << objRecCuboid.Volume() << endl;
cout << " " << endl;

CirCuboid objCirCuboid;
objCirCuboid.set(10,15,30,20);
objCirCuboid.display();
cout << "圆柱的体积:" <<objCirCuboid.Volume()<<endl;
cout << " " << endl;

TriCuboid objTriCuboid;
objTriCuboid.set(20, 25, 22,13, 10, 5);
objTriCuboid.display();
cout << "三菱柱的体积:" <<objTriCuboid.Volume() <<endl;
cout << " " << endl;

cout << "矩形中心和三角形中心的距离:" << distance(objRectangle, objTriangle) << endl;
cout << "圆形与三角形的距离:" << objCircle.distance(objTriangle) << endl;


cout << "利用全局函数显示信息:" << endl;
display(objRectangle, 1);
display(objCircle, 2);
display(objTriangle, 3);
}
总是提示错误信息:
1>g:\用vs编程的acm\派生类的继承,兼容类型\派生类的继承,兼容类型\派生类的继承和兼容类型.cpp(138): error C2365: “Triangle::center”: 重定义;以前的定义是“数据成员”
1> g:\用vs编程的acm\派生类的继承,兼容类型\派生类的继承,兼容类型\派生类的继承和兼容类型.cpp(116) : 参见“Triangle::center”的声明
1>g:\用vs编程的acm\派生类的继承,兼容类型\派生类的继承,兼容类型\派生类的继承和兼容类型.cpp(261): error C2662: “double Point::getX(void)”: 不能将“this”指针从“const Point”转换为“Point &”
1> 转换丢失限定符
1>g:\用vs编程的acm\派生类的继承,兼容类型\派生类的继承,兼容类型\派生类的继承和兼容类型.cpp(262): error C2662: “double Point::getY(void)”: 不能将“this”指针从“const Point”转换为“Point &”
1> 转换丢失限定符
...全文
174 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yd2011222 2015-05-07
  • 打赏
  • 举报
回复
谢谢。。解决了 那个\用vs编程的acm\派生类的继承,兼容类型\派生类的继承,兼容类型\派生类的继承和兼容类型.cpp(138): error C2365: “Triangle::center”: 重定义;以前的定义是“数据成员” 1> g:\用vs编程的acm\派生类的继承,兼容类型\派生类的继承,兼容类型\派生类的继承和兼容类型.cpp(116) : 参见“Triangle::center”的声明 是那个成员函数和数据成员 的同名了。。谢谢了,。谢谢大神
brookmill 2015-05-07
  • 打赏
  • 举报
回复
Point center(){ // 改成getcenter return center; } double getX() { 改成 double getX() const { double getY() { 改成 double getY() const { http://blog.csdn.net/lihao21/article/details/8634876
内容概要:本文围绕“光伏-储能-数据中心”系统的容量优化配置展开研究,旨在通过构建数学模型并结合Matlab编程实现,对园区内光伏发电、储能设备与数据中心算力负荷之间的多能互补关系进行协同优化。研究综合考虑可再生能源出力的波动性、储能系统的充放电特性以及数据中心的动态用电需与算力调度特性,建立以最小化综合成本、降低碳排放强度、提升能源自给率等为目标的多目标优化模型,并采用先进的智能优化算法(如粒子群、灰狼、鲸鱼等)进行解,从而确定光伏装机容量与储能系统配置的最优方案。文中提供了完整的Matlab代码实现流程,涵盖数据预处理、模型构建、算法解与结果可视化全过程,属于综合能源系统与信息基础设施深度融合的前沿交叉课题。; 适合人群:具备电力系统、能源工程、自动化或计算机等相关专业背景,熟悉Matlab编程与基本优化算法原理,从事新能源利用、绿色数据中心、综合能源系统规划与低碳调度等方向的研究生、科研人员及工程技术人员。; 使用场景及目标:① 掌握光伏-储能-数据中心耦合系统的建模思路与多能流协同机制;② 学习基于Matlab的多目标容量优化配置方法与智能算法应用技巧;③ 为工业园区、数字经济园区及绿色数据中心的能源系统规划、节能减排与可持续运行提供科学决策依据和技术解决方案。; 阅读建议:建议结合所提供的Matlab代码,深入理解目标函数设计、约束条件设定及算法实现细节,可通过调整负荷参数、改变气候数据、引入新的优化目标或约束条件等方式进行拓展性实验,以深化对系统特性的认知并提升实际科研与工程应用能力。

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧