第10周实验报告3

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

#include <iostream>
#include <cmath>

using namespace std;
const double PI = 3.14;

class point
{
public:
	point (int a = 0, int b = 0):x(a), y(b){}

	friend istream &operator >> (istream &, point &);

	friend ostream &operator << (ostream &, point &);

protected:
	
	int x;
	int y;
};

class yuan:public point
{
public:
	yuan(int a = 0, int b = 0, int c = 0):point (a, b), r(c){}

	double area()
	{
		return PI * r * r;
	}
	friend ostream &operator << (ostream &, yuan &);

	friend istream &operator >> (istream &, yuan &);

protected:
	
	int r;
};

class zhu:public yuan
{
public:
	zhu(int a = 0, int b = 0, int c = 0, int d = 0):yuan(a, b, c), high(d){}

	double TJ()
	{
		return area() * high;
	}
	friend ostream &operator << (ostream &, zhu &);

	friend istream &operator >> (istream &, zhu &);

protected:

	int high;
};

ostream &operator << (ostream & o, point &i)
{
	o << "point:(" << i.x << ',' << i.y << ')';

	return o;
}

ostream &operator << (ostream & o, yuan &i)
{
	o << "point:(" << i.x << ',' << i.y << ')' << "  R = " << i.r << " area = " << i.area();

	return o;
}

ostream &operator << (ostream & o, zhu &i)
{
	o << "point:(" << i.x << ',' << i.y << ')' << "  R = " << i.r << " high = " << i.high << " area = " << i.area() << " TJ = " << i.TJ ();

	return o;
}

istream &operator >> (istream & i, point &o)
{
	char a;

	i >> a >> o.x >> a >> o.y >> a;

	return i;
}

istream &operator >> (istream & i, yuan &o)
{
	char a;

	i >> a >> o.x >> a >> o.y >> a >> o.r;

	return i;
}

istream &operator >> (istream & i, zhu &o)
{
	char a;

	i >> a >> o.x >> a >> o.y >> a >> o.r >> o.high;

	return i;
}
int main()
{
	point a(1, 2);

	yuan b(2, 3, 4);

	zhu c(3, 4, 5, 6);

	cout << a << endl << b << endl << c << endl;

	cin >> a >> b >> c;

	cout << a << endl << b << endl << c;

	system ("pause");

	return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值