zoukankan      html  css  js  c++  java
  • 使用默认参数的构造函数

     1 #include <iostream>
     2 
     3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     4 using namespace std;
     5 
     6 class Box
     7 {
     8     public:
     9         Box(int h=10,int w=10,int len=10);
    10         int volume();
    11     private:
    12         int height;
    13         int width;
    14         int length;
    15 };
    16 
    17 Box::Box(int h,int w,int len)
    18 {
    19     height=h;
    20     width=w;
    21     length=len;
    22 }
    23 
    24 int Box::volume()
    25 {
    26     return(height*width*length);
    27 }
    28 
    29 int main(int argc, char** argv) {
    30     Box box1;
    31     cout<<"The volume of box1 is"<<box1.volume()<<endl;
    32     Box box2(15);
    33     cout<<"The volume of box2 is"<<box2.volume()<<endl;
    34     Box box3(15,30);
    35     cout<<"The volume of box3 is"<<box3.volume()<<endl;
    36     Box box4(15,30,20);
    37     cout<<"The volume of box4 is"<<box4.volume()<<endl;
    38     return 0;
    39 }
  • 相关阅读:
    CodeForces 834C
    HDU 6048
    HDU 6052
    HDU 6036
    HDU 6042
    HDU 2614 Beat(DFS)
    UESTC 1272 Final Pan's prime numbers(乱搞)
    HDU 2064 汉诺塔III(递归)
    HDU 2102 A计划(DFS)
    HDU 1069 I Think I Need a Houseboat(模拟)
  • 原文地址:https://www.cnblogs.com/borter/p/9401882.html
Copyright © 2011-2022 走看看