mian.cpp
#include "point.h"
#include "circle.h"
#include "cylinder.h"
#include
using namespace std;
int main()
{
/*
Point p(3.5,6.4);
cout<<"x="<
cout<<"p(new)"<
Circle c(3.5,6.4,8);
cout<
c.setRadius(7);
cout<
Cylinder cy1(3.5,6.4,5.2,10);
cout<
cy1.setRadius(10);
cy1.setPoint(10,5);
cout<
}
circle.cpp
#include
using namespace std;
#include "circle.h"
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 &p)
{
output<<"center=["<
}
Circle.h
#ifndef CIRCLE_H
#define CIRCLE_H
#include "point.h"
class Circle : public Point
{
public:
Circle(float x=0,float y=0,float r=0);
void setRadius(float);
float getRadius() const;
float area() const;
friend ostream & operator<<(ostream &,const Circle &);
protected:
float radius;
};
#endif
point.cpp
#include
using namespace std;
#include "point.h"
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)
{
output<<"["<
}
point.h
#ifndef _POINT_H
#define _POINT_H
#include
using namespace std;
class Point
{
public:
Point(float a,float b);
void setPoint(float a,float b);
float getX() const{return x;}
float getY() const{return y;}
friend ostream & operator <<(ostream &,const Point &);
protected :
float x;
float y;
};
#endif
cylinder.cpp
#include "cylinder.h"
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::getHeight() const{return height;}
float Cylinder::area() const{return 2*Circle::area()+3.14159*radius*radius;}
float Cylinder::volumn() const{return area()*height;}
ostream &operator <<(ostream &output,const Cylinder &p)
{
output<<"center=["<
}
cylinder.h
#ifndef CYLINDER_H
#define CYLINDER_H
#include "Circle.h"
class Cylinder : public Circle
{
public:
Cylinder(float x=0,float y=0,float r=0,float h=0);
void setHeight(float);
float getHeight() const;
float area() const;
float volumn() const;
friend ostream & operator<<(ostream &,const Cylinder &);
protected:
float height;
};
#endif