// C9_3.cpp : Defines the entry point for the console application. // 利用類別顯示時間 #include "stdafx.h" #include #include class date //類別名稱 { private: unsigned int my,mm,md; public: void set_date(int y,int m,int d) //自外界取得資料 { my = y; //引數傳入資料成員 mm = m; md = d; } void list_date() { cout << "民國 " << my-1911 //輸出資料成員內容 << " 年 " << mm << " 月 " << md << " 日 " << endl; } }; int main(int argc, char* argv[]) { int year,month,day; date Date1; //物件宣告 Date1.set_date(1998,11,25); //呼叫物件成員函式 Date1.list_date(); cout << endl << "請輸入西元 年 月 日 ? "; cin >> year >> month >> day; Date1.set_date(year,month,day); Date1.list_date(); getch(); return 0; }