class Box

/** 将头文件和源代码分开可以提高效率 便于管理

     定义类 (数据成员 成员函数 构造函数)

     创建对象

*/

//Box.h

class Box{

      public:

             double length; //数据成员

             double width;

             double height; 

             box();//构造函数            

             Box(double lengthValue,double widthValue,double heightValue);

             double volume();//成员函数

              };//注意 一定要加上分号 否则编译器无法通过  

//Box.cpp

 #include <iostream>

#include "Box.h"

using namespace std;

Box::Box(){

            length=width=height=1.0;

            }

Box::Box(double lengthValue,double widthValue,double heightValue){

                 length=lengthValue;

                 width=widthValue;

                height=heightValue;

                }

                double Box::volume(){

                                     return length*width*height;

                 }

//main.cpp

#include <iostream>

 #include "Box.h"

using namespace std;

int main(int argc, char *argv[]){

         Box firstBox;

         Box smailBox(50.0,60.0,70.0);

         cout<<" The Smail Box object is By "

                <<smailBox.length<<" by "

                <<smailBox.width<<" by "

               <<smailBox.height

               <<endl;

          cout<<"smail Box Volume is "

                 <<smailBox.volume();

                 system("PAUSE"); //暂停控制台界面

                 return EXIT_SUCCESS;//退出程序

 }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值