C++_數字時鐘軟件實現設計

利用C++學習內容,通過windows自帶函數實現一個簡易的時鐘

#include<iostream>
#include<windows.h> //延時與清屏頭文件 
using namespace std;
class time
{
	public:
		time(){year=0;month=0;day=0;hour=0;minute=0;sec=0;}//默認構造函數 
		time(int y,int mo,int d,int h ,int m,int s):year(y),month(mo),day(d),hour(h),minute(m),sec(s){}//構造函數重載 
		time operator++();//聲明運算符重載成員函數 
		void display()
			{
				cout<<"*********"<<year<<"-"<<month<<"-"<<day<<"**********"<<endl;
				cout<<"********"<<hour<<" : "<<minute<<" : "<<sec<<"********"<<endl;
			}//輸出時間格式 
	private:
		int year;
		int month;
		int day;
		int hour;
		int minute;
		int sec;	
};
time time::operator++()//定義運算符重載成員函數 
{
	if(++sec>=60)
	{
		sec-=60;
		++minute;
		if(minute>=60)
		{
			minute-=60;
			++hour;
			if(hour>=24)
        		{
        			hour-=24;
        			++day;
        			if(day>=30)
        			{
        				day-=30;
        				++month;
        				if(month>=12)
        				{
        					month-=12;
        					++year;
						}
					}
				}
		}
	}
	return *this;//返回當前對象值 
}
int main()
{
	int a,b,c,e,f,g,h;
	cout<<"請修改當前時間:(格式如下)\n";
	cout<<"2018 10 3 12 50 45\n";
	{
	cout<<"請輸入當前年份(2018):"<<endl;
	cin>>g;
	cout<<"請輸入當前月份(1~12):"<<endl; 
	cin>>e;
	cout<<"請輸入當前幾號(1~30):"<<endl;
	cin>>h;
	cout<<"請輸入現在時間(12 30 32):"<<endl;
	cin>>a>>b>>c;
	}
	
	{
		time time1(g,e,h,a,b,c);//如何向time1中輸入數據 
		for(int i=0;;i++)
		{	cout<<"*****歡迎進入家庭計時系統*****"<<endl;
			cout<<"*******假設每個月30天*******"<<endl; 
			++time1;
			time1.display() ;
			cout<<"***********designed by yuumoz.\n";
			Sleep(1000);
	     	system("CLS");
		}
	}
	return 0;
 } 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章