lzth.net
当前位置:首页 >> C++题 设计一个基类ShApE,派生出圆形CirClE类,再分别派生出圆球类BAll, >>

C++题 设计一个基类ShApE,派生出圆形CirClE类,再分别派生出圆球类BAll,

#include#define pi 3.14159 using namespace std;//shape类 class shape{ public:virtual float area() const { return 0.0;}//虚函数 virtual float volume() const {return 0.0;}//虚函数 virtual void shapname() const =0;//纯虚函数 } ;//circle类 class circle :

#include <iostream>using namespace std;#define PI 3.1415class Shape//基类Shape{public: Shape() {} virtual ~Shape() {} virtual double GetArea()=0;};class Circle:public Shape//派生类Circle{public: Circle() { radius = 0; } ~Circle() {} double GetArea(

class point;class shape {public: virtual double circumference() = 0; virtual double area() = 0;};#define PI 3.14159class circle : public shape {private: point center; int radius;public: circle(const point &p, int r) : center(p), radius(r) {} virtual double

#include#includeusing namespace std;const double PI=3.1415927;class Shape{public: virtual double area()=0;};class Circle : public Shape{ double radius;public: Circle(double r=1){ radius=r; } double area(){ return PI*radius*radius; }};class Square :

楼上用的是java,既然说到基类和派生类,我想应该是指用C++实现,以下是我的方法: #include class Shape{ //这里可以自己添加数据成员或成员函数 }; class Rectangle:public Shape { double height,width; public: Rectangle(double h=1.0,double

#include&lt;iostream.h&gt;#include&lt;cmath&gt;const double pi=3.14;class Shape//抽象基类{public: virtual void display()=0;};class Point:public Shape{public: void display(){};};class Circle:public Point{private: double r;public: void set(double r) { r=r;}

#include const double PI=3.14;using namespace std; class Shape { public: Shape(){}; virtual double area()const{return 0.0;} }; class Circle:public Shape { public: Circle(double

class Shape { public: virtual double printArea()=0; }; class Rectangle : public Shape { public: Rectangle(double h, double w) : height(h), width(w){} double printArea(){ return height * width; } private: double height; double width; }; class Circle : public

#include#includeusing namespace std;const double pi=3.1415927;class shape{public: virtual double area()=0;};class circle : public shape{ double radius;public: circle(double r=1){ radius=r; } double area(){ return pi*radius*radius; }};class square :

相关文档
网站首页 | 网站地图
All rights reserved Powered by www.lzth.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com