zoukankan      html  css  js  c++  java
  • 点Point 圆Circle 圆柱Cylinder的继承与派生

    #include <iostream.h>
    //using namespace std;
    class Point
    {
    private:
    	double x;
    	double y;
    public:
    	Point(double x1,double y1)
    	{
    		x=x1;
    		y=y1;
    	}
    	~Point()//析构函数
    	{ cout<<"The constructor of Point was called"<<endl; }
    
    
    };
    class Circle:public Point
    {
    public:
    	double r;
    	Circle(double x1,double y1,double r1):Point(x1,y1)//派生类构造函数
    	{
    		r=r1;//新增量
    	}
    	~Circle()
    	{
    		cout<<"The constructor of Circle was called"<<endl;
    	}
    };
    
    class Cylinder:public Circle
    {
    private:
    	double h;
    public:
    	Cylinder(double x1,double y1,double r1,double h1):Circle(x1,y1,r1)
    	{
    		h=h1;//新增量
    	}
    	~Cylinder()
    	{
    		cout<<"The constructor of Cylinder was called"<<endl;
    	}
    	double set_volume();//求体积
    	double set_area();//求面积
    	friend ostream &operator<<(ostream &output,Cylinder &);//重载输出流
    	//void show();
    };
    
    double Cylinder::set_area()
    {
    	return(2*3.14*r*(h+r));
    }
    double Cylinder::set_volume()
    {
    	return(3.14*r*r*h);
    }
    
    ostream &operator<<(ostream &output,Cylinder &c)
    {
    	output<<"The area of the Cylinder is "<<c.set_area()<<endl;
    	output<<"The volume of the Cylinder is "<<c.set_volume()<<endl;
    	return output;
    }
    int main()
    {
    	Cylinder c1(3.2,3,2,5);
    	c1.set_area();
    	c1.set_volume();
    	cout<<c1;
    	return 0;
    }

  • 相关阅读:
    ubuntu 下 apt-get update 错误
    'unable to run mksdcard sdk tool" when instll android studio on ubuntu14.10以后版本
    ubuntu下安装sougou
    ubuntu下安装jdk1.8.0_91
    ubuntu update时出现错误
    android studio中R文件变红并报错
    git使用
    Android新手须知
    css初级之框模型
    css初级之边框
  • 原文地址:https://www.cnblogs.com/IT-hexiang/p/4084634.html
Copyright © 2011-2022 走看看