This Blog is dedicated to Sir Johnson Lin
Learn flow chart from C language , master C with the chart!

C++ 基本 使用類別 C++ basic function ,class introduction



D:\cppCodes\HelloClassKid\HelloClassKid.c++
 1 //++++++++++++++++++++++++++
 2  //      HelloClassKid.cpp
 3  //++++++++++++++++++++++++++
 4  
 5  ///#include header
 6  #include <iostream>
 7  #include <string>
 8  
 9  ///Using
10  using namespace std;
11  
12  ///Class Cellphone
13  class Cellphone //function is method , variable is member
14  {
15      ///Public
16      public:
17      string brand = "APPLE";
18      void outlook() { cout << "cool ! " ; }
19      void display() { cout << "shine ! \n" ; }
20      
21      ///+
22  }; //end class include semi colon
23  
24  ///mainentry
25  int main()
26  {
27      ///declare
28      Cellphone myPhone;
29      
30      ///display  myPhone .brand
31      cout << myPhone.brand << " is ";
32      
33      ///myphone .outlook
34      myPhone.outlook();
35      
36      ///myphone .display
37      myPhone.display();
38      
39      ///mainend
40      return 0;
41  } //main_end
42  

@ 下載程式碼 Download source code

沒有留言:

張貼留言