網路教學(e-Learning)校園社群(e-Community)服務台(e-Service)系所班網(e-Class)登入
位置: 陳安邦 > C++
W10 2
by 陳安邦 2015-11-19 16:48:22, 回應(0), 人氣(131)
#include <cstdlib>//含括指令標頭檔 
#include <iostream>//含括指令標頭檔 

using namespace std;//使用名稱空間std 
class CWin// 定義視窗類別class
{
      private: 
             char id;//宣告字元變數id 
             int width;//宣告整數變數width
             int height;//宣告整數變數height
      public:
             int area()//設公有函數area() 
             {
                 return width*height;//回傳面積算式      
             }
             void showarea(void)//設公有函數showarea
             {
                  cout <<"window id="<<id<<", width="<< width <<", height="<< height <<", area=" << area()<<endl;//印出結果 
             }
                  void setdate(char i, int w,int h)// 設公有函數setdate
                  { 
                       id=i;
                       width=w;
                       height=h;
                   }  
                    
};
             
int main(int argc, char *argv[])
{
CWin win1;
win1.setdate('A',50,40);
win1.showarea();//印出結果 


    system("PAUSE");
    return EXIT_SUCCESS;