gha890826

大一期中考-6

Apr 18th, 2020 (edited)
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class Student//新建一個Student類別
  5. {
  6. public://public的
  7.     int age;
  8.     void output()//新建一個output()函數
  9.     {
  10.         cout << "age=" << age << endl;
  11.     }
  12. };
  13.  
  14. int main()
  15. {
  16.     Student S1;//新建一個Student物件S1
  17.     S1.age = 19;//將S1的age設為19
  18.     S1.output();//呼叫S1的output()
  19.  
  20.     system("pause");
  21.     return 0;
  22. }
Add Comment
Please, Sign In to add comment