?? 6_10.cpp
字號:
#include<iostream.h>
class clock //時鐘類的定義
{
public:
clock(int h=0,int m=0,int s=0);//構造函數
void SetTime(int m=0,int s=0);
void ShowTime();
void ShowTime()const;//常成員函數
private:
const int hour;//常數據成員
int minute;
int second;
};
//時鐘類的實現
clock::clock(int h,int m,int s):hour(h)
{
minute=m>=0&&m<60?m:0;
second=s>=0&&s<60?s:0;
}
void clock::SetTime(int m, int s)
{
minute=m>=0&&m<60?m:0;
second=s>=0&&s<60?s:0;
}
void clock::ShowTime()
{
cout<<"調用普通成員函數顯示:"<<endl;
cout<<hour<<":"<<minute<<":"<<second<<endl;
}
void clock::ShowTime()const
{
cout<<"調用常成員函數顯示:"<<endl;
cout<<hour<<":"<<minute<<":"<<second<<endl;
}
//主函數
int main()
{
const clock s(7,30,30);//常對象
clock t;
cout<<"第一次顯示時間"<<endl;
s.ShowTime();
t.ShowTime();
cout<<"第二次顯示時間"<<endl;
t.SetTime(20,50);
s.ShowTime();
t.ShowTime();
return(0);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -