C++面向对象程序设计问题

题目:应用VC++6.0的编辑环境构造一个类Jhtx及其派生类,该类主要实现关于几何图形的基本操作。对于基类“几何图形”,有求面积、求体积的函数(纯虚函数),其派生类圆和... 题目:
应用VC++6.0的编辑环境构造一个类Jhtx及其派生类,该类主要实现关于几何图形的基本操作。对于基类“几何图形”,有求面积、求体积的函数(纯虚函数),其派生类圆和矩形主要有初始化(构造函数),求面积,求周长操作,类圆的派生类圆球和圆柱有求表面积、体积操作。 试在主函数中分别定义圆、圆球、圆柱以及矩形的对象,并调用其成员函数实现其相应操作。

以下是我的程序,但是有一些错误,都是相同的错误,请大家指教。
#include<iostream.h>
class Geometry{
public:
Geometry(double a,double b,double c)
{x=a,y=b,c=z;}
~Geometry(){};
virtual double GetArea()=0;
double GetPerimeter();
virtual double GetColume()=0;
virtual void Show()=0;
protected:
double x,y,z;
};
class Circle:public Geometry{
protected:
double r;
public:
Circle(double a):Geometry(a,0,0)
{r=a;}
~Circle(){};
double GetArea()
{return 3.14*r*r;}
double GetPerimeter()
{return 6.28*r;}
virtual double GetColume()
{return 0;}
void Show()
{cout<<"Area is:"<<GetArea()<<endl;
cout<<"Perimeter is:"<<GetPerimeter()<<endl;}
};
class Rectangle:public Geometry{
public:
Rectangle(double a,double b):Geometry(a,b,0)
{}
~Rectangle(){};
double GetArea()
{return x*y;}
double GetPerimeter()
{return x+y;}
virtual double Getolume()
{return 0;}
void Show()
{cout<<"Area is:"<<GetArea()<<endl;
cout<<"Perimeter is:"<<GetPerimeter()<<endl;}
};
class Ball:public Circle{
public:
Ball(double a):Circle(a)
{};
~Ball(){};
double GetArea()
{return 4*3.14*x*x;}
double GetColume()
{return (4/3)*3.14*x*x*x;}
double GetPerimeter()
{return 0;}
void Show()
{cout<<"Area is:"<<GetArea()<<endl;
cout<<"Getcolume is:"<<GetColume()<<endl;}
};
class Column:public Circle{
protected:
double h;
Column(double a,double h):Circle(a),h(h){}
~Column(){};
double GetArea()
{return 2*3.14*x*x+2*3.14*x*h;}
double GetColume()
{return 3.14*x*x*h;}
double GetPerimeter()
{return 0;}
void Show()
{cout<<"Area is:"<<GetArea()<<endl;
cout<<"Getcolume is:"<<GetColume()<<endl;}
};
int main()
{ Geometry *p;
Circle ob1(1);
Rectangle ob2(2,2);
Ball ob3(3);
Column ob4(4,3);
p=&ob1;
p->GetArea();
p->GetPerimeter();
p->Show();
p=&ob2;
p->GetArea();
p->GetPerimeter();
p->Show();
p=&ob3;
p->GetArea();
p->GetPerimeter();
p->Show();
p=&ob4;
p->GetArea();
p->GetPerimeter();
p->Show();
return 0;
}
展开
 我来答
冰山珀西
推荐于2016-04-13 · TA获得超过3392个赞
知道小有建树答主
回答量:1673
采纳率:0%
帮助的人:445万
展开全部
我改了一下,已经能通过并且运行了:
#include<iostream.h>
class Geometry{
public:
Geometry(double a,double b,double c)
{x=a,y=b,c=z;}
~Geometry(){};
virtual double GetArea()=0;
virtual double GetPerimeter()=0;//这里有改动
virtual double GetColume()=0;
virtual void Show()=0;
protected:
double x,y,z;
};
class Circle:public Geometry{
protected:
double r;
public:
Circle(double a):Geometry(a,0,0)
{r=a;}
~Circle(){};
double GetArea()
{return 3.14*r*r;}
double GetPerimeter()
{return 6.28*r;}
virtual double GetColume()
{return 0;}
void Show()
{cout<<"Area is:"<<GetArea()<<endl;
cout<<"Perimeter is:"<<GetPerimeter()<<endl;}
};
class Rectangle:public Geometry{
public:
Rectangle(double a,double b):Geometry(a,b,0)
{}
~Rectangle(){};
double GetArea()
{return x*y;}
double GetPerimeter()
{return x+y;}
virtual double GetColume()//这里有改动
{return 0;}
void Show()
{cout<<"Area is:"<<GetArea()<<endl;
cout<<"Perimeter is:"<<GetPerimeter()<<endl;}
};
class Ball:public Circle{
public:
Ball(double a):Circle(a)
{};
~Ball(){};
double GetArea()
{return 4*3.14*x*x;}
double GetColume()
{return (4/3)*3.14*x*x*x;}
double GetPerimeter()
{return 0;}
void Show()
{cout<<"Area is:"<<GetArea()<<endl;
cout<<"Getcolume is:"<<GetColume()<<endl;}
};
class Column:public Circle{
public://这里改为public
double h;
Column(double a,double h):Circle(a),h(h){}
~Column(){};
double GetArea()
{return 2*3.14*x*x+2*3.14*x*h;}
double GetColume()
{return 3.14*x*x*h;}
double GetPerimeter()
{return 0;}
void Show()
{cout<<"Area is:"<<GetArea()<<endl;
cout<<"Getcolume is:"<<GetColume()<<endl;}
};
int main()
{ Geometry *p;
Circle ob1(1);
Rectangle ob2(2,2);
Ball ob3(3);
Column ob4(4,3);
p=&ob1;
p->GetArea();
p->GetPerimeter();
p->Show();
p=&ob2;
p->GetArea();
p->GetPerimeter();
p->Show();
p=&ob3;
p->GetArea();
p->GetPerimeter();
p->Show();
p=&ob4;
p->GetArea();
p->GetPerimeter();
p->Show();
return 0;
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
jaybestwang
2011-11-09 · TA获得超过4106个赞
知道小有建树答主
回答量:940
采纳率:0%
帮助的人:706万
展开全部
#include<iostream>
using namespace std;

class Geometry{
public:
Geometry(double a,double b,double c)
{x=a,y=b,c=z;}
virtual ~Geometry(){};
virtual double GetArea()=0;
virtual double GetPerimeter()=0;
virtual double GetColume()=0;
virtual void Show()=0;
protected:
double x,y,z;
};
class Circle:public Geometry{
protected:
double r;
public:
Circle(double a):Geometry(a,0,0)
{r=a;}
virtual ~Circle(){};
double GetArea()
{return 3.14*r*r;}
double GetPerimeter()
{return 6.28*r;}
virtual double GetColume()
{return 0;}
void Show()
{cout<<"Area is:"<<GetArea()<<endl;
cout<<"Perimeter is:"<<GetPerimeter()<<endl;}
};
class Rectangle:public Geometry{
public:
Rectangle(double a,double b):Geometry(a,b,0)
{}
~Rectangle(){};
double GetArea()
{return x*y;}
double GetPerimeter()
{return x+y;}
virtual double GetColume()
{return 0;}
void Show()
{cout<<"Area is:"<<GetArea()<<endl;
cout<<"Perimeter is:"<<GetPerimeter()<<endl;}
};
class Ball:public Circle{
public:
Ball(double a):Circle(a)
{};
~Ball(){};
double GetArea()
{return 4*3.14*x*x;}
double GetColume()
{return (4/3)*3.14*x*x*x;}
double GetPerimeter()
{return 0;}
void Show()
{cout<<"Area is:"<<GetArea()<<endl;
cout<<"Getcolume is:"<<GetColume()<<endl;}
};
class Column:public Circle{
public:
double h;
Column(double a,double h):Circle(a){
this->h = h;
}
~Column(){};
double GetArea()
{return 2*3.14*x*x+2*3.14*x*h;}
double GetColume()
{return 3.14*x*x*h;}
double GetPerimeter()
{return 0;}
void Show()
{cout<<"Area is:"<<GetArea()<<endl;
cout<<"Getcolume is:"<<GetColume()<<endl;}
};
int main()
{ Geometry *p;
Circle ob1(1);
Rectangle ob2(2,2);
Ball ob3(3);
Column ob4(4,3);
p=&ob1;
p->GetArea();
p->GetPerimeter();
p->Show();
p=&ob2;
p->GetArea();
p->GetPerimeter();
p->Show();
p=&ob3;
p->GetArea();
p->GetPerimeter();
p->Show();
p=&ob4;
p->GetArea();
p->GetPerimeter();
p->Show();
return 0;
}
改完了,能运行,自己看看
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式