第十周任务3

/* (程序头部注释开始) 
* 程序的版权和版本声明部分 
* Copyright (c) 2011, 烟台大学计算机学院学生  
* All rights reserved. 
* 文件名称:                               
* 作    者:  杨建和                
* 完成日期:   2012   年  4 月 23 日 
* 版 本 号:           
 * 对任务及求解方法的描述部分 
* 输入描述: 

* 问题描述:* 程序头部的注释结束 

*/ 

#include <iostream>
#include <cmath>
using namespace std;
const double pi = 3.1415926;
class Point
{
 protected:
  double x,y;
 public:
  Point(double x0,double y0):x(x0),y(y0){}
  double get_x();
  double get_y();
  ~Point(){}
};
double Point::get_x()
{
	return x;
}
double Point::get_y()
{
	return y;
}
  

class Circle:public Point
{
protected:
	double r;
public:
	Circle(double x0,double y0,double r0):Point(x0,y0),r(r0){}
	double get_r();
	double Area();
	double Clength();
	~Circle(){}
};
double Circle::get_r()
{
	return r;
}

double Circle::Area()
{
	return pi*get_r()*get_r();
}

double Circle::Clength()
{
	return 2*pi*get_r();
}


class Cylinder:public Circle
{
protected:
	double h;
public:
	Cylinder(double x0,double y0,double r0,double h0):Circle(x0,y0,r0),h(h0){}
	double get_h();
    double Biao_area();
    double Volume();
    ~Cylinder(){}
    friend istream& operator >> (istream& input, Cylinder &c1);  
    friend ostream& operator << (ostream& output, Cylinder &c1);  
};
double Cylinder::get_h()
{
	return h;
}
double Cylinder::Biao_area()
{
	return 2*Area()+Clength()*get_h();
}
double Cylinder::Volume()
{
	return Area()*get_h();
}

ostream& operator << (ostream& output, Cylinder &c1)  
{  
 output << "圆柱底面○的圆心为:" << "(" << c1.get_x() << "," << c1.get_y() << ")" << endl;  
 output << "圆柱底面○的半径为:" << c1.get_r() << endl;          
 output << "圆柱底面○的面积为:" << c1.Area() << endl;           
 output << "圆柱底面○的周长为:" << c1.Clength() << endl;  
 output << "圆柱的高为:" << c1.get_h() <<endl;  
 output << "圆柱的表面积为:" << c1.Biao_area() << endl;  
 output << "圆柱的体积为:" <<c1.Volume() << endl;            
 return output;  
}  

 istream& operator >> (istream& input, Cylinder &c1) 
{ 
 cout << "请输入一个圆柱底面○的圆心坐标(x和y之间用空格隔开):"; 
 input >> c1.x >> c1.y; 
 cout << endl; 
 cout << "请输入一个圆柱底面○的半径:"; 
 cout << c1.r;
 cout << endl; 
 cout << "请输入一个圆柱的高"; 
 input >> c1.h;  
 return input; 
}

 int main()  
 {  
	 Cylinder c1(1,2,3,4);  
	 cout << c1;  
	 system("pause");     
	 return 0;  
 }  




感言:继承就是在原来的类里面在加上自己的新内容。。。老师,在做时遇到了一个错误,就是先定义一个Cylinder 类,然后再cin;出现 'Cylinder' : no appropriate default constructor available  这样一个错误,原因是没有构造默认函数,这是为什么呢?


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值