体积

来源:互联网 发布:淘宝怎么修改折扣 编辑:程序博客网 时间:2024/04/28 00:28
02.* 程序的版权和版本声明部分:  03.* Copyright (c) 2011, 烟台大学计算机学院  04.* All rights reserved.  05.* 文件名称:test.cpp  06.* 作    者:刘芳07.* 完成日期:2014 年5 月25  日  08.* 版 本 号:v1.0  09.* 对任务及求解方法的描述部分: 10.* 输入描述:无  11.* 问题描述: 12.* 程序输出: 13.* 问题分析:略 14.* 算法设计:略  15.*/    #include <iostream>using namespace std;class Rectangle //矩形类{private:int length; //矩形的长和宽int width;public:Rectangle();Rectangle(int l,int w); //构造函数,l、w分别代表长和宽int getArea(); //求面积};class Bulk: public Rectangle //立方体类{public:Bulk(); //默认构造函数Bulk(int l, int w,int h); //带参数的构造函数int getVolume();private:int height; //高,长、宽继承自基类};//只提交begin到end部分的代码//*********** begin *************//Rectangle类的成员函数Rectangle::Rectangle():length(0),width(0){}Rectangle::Rectangle(int l,int w) {     length=l;    width=w; } int Rectangle::getArea() { double c;  c=length*width;   return c; }//Bulk类的成员函数Bulk::Bulk():Rectangle(),height(0){}Bulk::Bulk(int l, int w,int h):Rectangle(l,w),height(h){}int Bulk::getVolume(){double n;n=getArea();return n*height;};//*********** end ***************int main(){int x,y,z;cin>>x>>y>>z;Bulk b(x,y,z);cout<<b.getVolume()<<endl;return 0;}

0 0
原创粉丝点击