第10周实验报告3

来源:互联网 发布:linux安装wine 编辑:程序博客网 时间:2024/05/17 04:51
/* (程序头部注释开始)     * 程序的版权和版本声明部分     * 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;}