當前位置:編程學習大全網 - 網站源碼 - 定義壹個Box(盒子)類,在該類包括以下內容: (1)私有數據成員(lengh、width、height); (2)...

定義壹個Box(盒子)類,在該類包括以下內容: (1)私有數據成員(lengh、width、height); (2)...

#include?<iostream>

using?namespace?std;

class?Box?{

private?:

int?length;

int?width;

int?heigth;

public?:

Box(int?len?=?0,int?w?=?0,int?h?=?0);

void?print();

int?volume();

~Box()?{}

};

Box::Box(int?len,int?w,int?h)?{

length?=?len;

width?=?w;

heigth?=?h;

}

void?Box::print()?{

cout?<<?length?<<?","?<<?width?<<?","?<<?heigth?<<?endl;

}

int?Box::volume()?{

return?length?*?width?*?heigth;

}

int?main()?{

Box?A(2,3,5);

A.print();

cout?<<?A.volume()?<<?endl;

return?0;

}

  • 上一篇:我是壹個從未接觸過面向對象編程的人,現在直接學C#,在學習的過程中最應該註意什麽怎麽去學,請高手指點
  • 下一篇:內存測試源代碼
  • copyright 2024編程學習大全網