Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Box{
- public:
- //定義資料
- int h, w, d;
- //定義行為
- int volume(){
- return h*w*d;
- }
- void print(){
- cout<<"h:"<<h<<", w:"<<w<<", d:"<<d<<", volume:"<<volume()<<endl;
- }
- };
- int main(){
- Box b1;
- b1.h=100;
- b1.w=50;
- b1.d=30;
- cout<<"b1的體積="<<b1.volume()<<endl;
- //
- Box b2;
- b2.h=60;
- b2.w=30;
- b2.d=30;
- b2.print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement