gha890826

4/29課輔-將值傳入一併建構

May 13th, 2020 (edited)
1,037
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. //將值傳入一併建構
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. class time
  6. {
  7.     public:
  8.         time(int a,int b,int c)
  9.         {
  10.             cout<<"建構time\n";
  11.             hour=a;
  12.             min=b;
  13.             sec=c;
  14.         }
  15.         void show(){cout<<hour<<":"<<min<<":"<<sec<<endl;}
  16.     private:
  17.         int hour,min,sec;
  18. };
  19.  
  20. int main()
  21. {
  22.     time t1(1,2,3);
  23.     t1.show();
  24.     return 0;
  25. }
  26.  
  27. /*  time t1,t2(2),t3(3,3,3),t4(0,0,4);
  28.     t1.show();
  29.     t2.show();
  30.     t3.show();
  31.     t4.show();*/
Add Comment
Please, Sign In to add comment