網路教學(e-Learning)校園社群(e-Community)服務台(e-Service)系所班網(e-Class)登入
位置: 陳安邦 > C++
W17 實作1
by 陳安邦 2016-01-07 14:50:50, 回應(0), 人氣(276)
#include <cstdlib>
#include <iostream>

using namespace std;
class father
{

 
 public:
        char id;
        int width,height;
        father(char i='D',int w=10,int h=10):id(i),width(w),height(h)
        {
        cout << "father()建構元件被呼叫了..." << endl;
        }
        void showmember(void)
        {
        cout << "window" << id << ":";
        cout << "width" << width << ",height" << height << endl;    
        }     
        
};
class son : public father
{
      private:
              char text[20];
      public:
             son(char *tx)
             {
             cout << "son()建構元件被呼叫了..." << endl;
             strcpy(text,tx);         
             }
             void showtext()
             {
             cout << "text = " << text << endl;     
             }
             
};
int main(int argc, char *argv[])
{
    father f('A',50,60);
    son txt("HALLO C++");
    
    f.showmember();
    txt.showmember();
    txt.showtext();
    
    
     
     
     
    system("PAUSE");
    return EXIT_SUCCESS;
}