看板 NTUBIME101HW 關於我們 聯絡資訊
#include "stdafx.h" #include "iostream" #include "iomanip" using namespace std; //class declaration section class Date { private: int month; int day; int year; public: Date(); //constructor ~Date();//destructor void showdate(); }; //class implementation Date::Date() //user-defined default constructor { cout<<" *** A Date object is being initialized ***\n"; month=1; day=1; year=2010; } Date ::~Date() //user-defined default destructor { cout<<" *** A Date object is going out of existance *** \n"; } void Date ::showdate() { cout<<" The Date object is " <<setfill('0') <<setw(2) << month<< '/' <<setw(2) << day << '/' <<setw(2) <<year %100 ; //extract the last 2 year digits return; } int _tmain(int argc, _TCHAR* argv[]) { const int NUMDATES =5; Date thedate[NUMDATES]; for(int i=0;i< NUMDATES ;i++) { thedate[i].showdate(); cout<<endl; } system("pause"); return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.168.35.142
lty518:我照著打出來了 01/12 12:59
※ 編輯: lty518 來自: 118.168.35.142 (01/12 16:44) ※ 編輯: lty518 來自: 118.168.35.142 (01/12 16:49)