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;
} 展开
应用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;
} 展开
展开全部
我改了一下,已经能通过并且运行了:
#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;
}
#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;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#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;
}
改完了,能运行,自己看看
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;
}
改完了,能运行,自己看看
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询