?? 4_1.cpp
字號:
#include<iostream.h>
class clock //時鐘類的定義
{
public: //公有成員函數(shù)
void SetTime(int h=0, int m=0, int s=0);
void ShowTime();
private: //私有數(shù)據(jù)成員
int hour;
int minute;
int second;
};
//時鐘類成員函數(shù)的具體實現(xiàn)
void clock::SetTime(int h, int m, int s)
{
hour=h>=0&&h<24?h:0;//過濾非法數(shù)據(jù)
minute=m>=0&&m<60?m:0;
second=s>=0&&s<60?s:0;
}
inline void clock::ShowTime()
{
cout<<hour<<":"<<minute<<":"<<second<<endl;
}
//主函數(shù)
int main()
{
clock s; //定義clock對象s
cout<<"第一次設置時間并顯示:"<<endl;
s.SetTime(); //設置時間為默認值
s.ShowTime(); //顯示時間
cout<<"第二次設置時間并顯示:"<<endl;
s.SetTime(10,30,30); //設置時間為10時30分30秒
s.ShowTime(); //顯示時間
return(0);
//s.hour;
//cout<<"size of class Clock is: "<<sizeof(s)<<endl;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -