标签:
/* *Copyright (c) 2016,烟台大学计算机学院 *All rights reserved. *文件名称 : *作 者 : 李钊 *完成日期 : 2016年5月9号 *版 本 号 : v1.0 * *问题描述 : 点-圆-圆柱类族的设计 *输入描述 : *程序输出 :求出圆格柱体的表面积、体积并输出并且完成要求的计算任务 */ #include <iostream> using namespace std; class point { public: point(double x=0,double y=0); void setPoint(double,double); double getX( ) const {return x;} double getY( ) const {return y;} void show(); protected: double x; double y; }; point::point(double a,double b) { x=a; y=b; } void point::setPoint(double a,double b) { x=a; y=b; } void point::show() { cout<<"("<<x<<","<<y<<")"<<endl; } class Cirle:public point { protected: double banjing; public: Cirle(double x=0,double y=0,double r=0); void setbanjing(double); double getbanjing()const; double area()const; void show(); }; Cirle::Cirle(double a,double b,double c):point(a,b),banjing(c){} void Cirle::setbanjing(double c) { banjing=c; } double Cirle::area()const { double f; f=3.14*banjing*banjing; return f; } double Cirle::getbanjing()const { return banjing; } void Cirle::show() { cout<<"point:"<<" "<<"("<<x<<","<<y<<")"<<" "<<"banjing:"<<banjing<<" "<<area()<<endl; } class Yuanzhu:public Cirle { protected: double height; public: Yuanzhu(double x=0,double y=0,double r=0,double h=0); void seth(double); double geth()const; double area()const; double v()const; void show(); }; Yuanzhu::Yuanzhu(double a,double b,double c,double d):Cirle(a,b,c),height(d){} void Yuanzhu::seth(double h) { height=h; } double Yuanzhu::geth()const { return height; } double Yuanzhu::area()const { double o; o=2*Cirle::area()+2*3.14*banjing*height; return o; } double Yuanzhu::v()const { double t; t=Cirle::area()*height; return t; } void Yuanzhu::show() { cout<<"point:"<<" "<<"("<<x<<","<<y<<")"<<" "<<"banjing:"<<banjing<<" "<<"height:"<<height<<" "<<"area:"<<area()<<" "<<"V:"<<v()<<endl; } int main() { Yuanzhu f(3.3,4.4,5.5,6.6); f.show(); f.seth(7.7); f.show(); return 0; }
运行结果:
学习心得:
派生类的运用
标签:
原文地址:http://blog.csdn.net/l347037341/article/details/51356165