Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. class Box{
  4. public:
  5. //定義資料
  6. int h, w, d;
  7. //定義行為
  8. int volume(){
  9. return h*w*d;
  10. }
  11. void print(){
  12. cout<<"h:"<<h<<", w:"<<w<<", d:"<<d<<", volume:"<<volume()<<endl;
  13. }
  14. };
  15.  
  16. int main(){
  17. Box b1;
  18. b1.h=100;
  19. b1.w=50;
  20. b1.d=30;
  21. cout<<"b1的體積="<<b1.volume()<<endl;
  22. //
  23. Box b2;
  24. b2.h=60;
  25. b2.w=30;
  26. b2.d=30;
  27. b2.print();
  28.  
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement