March 29, 2011

一般時間運作-先輸入(時 分 秒)


/*許巧慧--B09902147--資工一丙**
*------------第1版------------*
*類別和物件:----------一般時間*/
#include<iostream>
#include <windows.h>
#include <time.h>
using namespace std;
/*元素:秒second 分minute 時hour*/
class Time
{
private: 
  int second;
  int minute;
  int hour;
public:
  Time(int=0,int=0,int=0);
  void setTime(int,int,int);
  void sethour(int);
  void setminute(int);
  void setsecond(int);
  void cal_time();
  int gethour();
  int getminute();
  int getsecond();
  void print_time();
};
/*建構子:初始值自己設*/
Time::Time(int h,int m,int s) 
{
  setTime(h,m,s);       
}         
/*設訂時間*/
void Time::setTime(int h,int m,int s) 
{
  sethour(h);
  setminute(m);
  setsecond(s);

/*時分秒的格式*/ 
void Time::sethour(int h)
{
 hour=h;
}
void Time::setminute(int m)
{
minute=m;
}

void Time::setsecond(int s)
{
  second=s;
}
/*時間的規格*/
void Time::cal_time()
{
  second++;
   if(second>=60) 
   {
     second=0;
     minute++;
   }
   if(minute>=60) 
   {
     minute=0;
     hour++;
   if(hour>=24)
   {
    hour=0;
   }
  }
}
/*回傳時間*/ 
int Time::gethour()
{
  return hour;
}
int Time::getminute()
{
  return minute;
}
int Time::getsecond()
{
  return second;
}
/*顯示時間*/ 
void Time::print_time()
{   
   system("cls");
   cout << "  " << hour << ":" << minute << ":" << second << "\n" ;


int main(void)
{
 int h,m,s;
 Time t;  
 cout<<" 請輸入現在時間 (時 分 秒) \n";
 cin>>h>>m>>s;
 t.setTime(h,m,s); 

  while(1)
  {
     t.print_time();
     Sleep(1000);
     t.cal_time();
  } 
system("pause");
return 0;    
}

0推薦此文章
Today's Visitors: 0 Total Visitors: 14
Personal Category: 學校專業課程(作業) c++ Topic: learning / education / linguistic
Previous in This Category: 撲克牌   Next in This Category: c++ memory matching game 記憶配對數字遊戲
[Trackback URL]

Post A Comment









Yes No



Please input the magic number:

( Prevent the annoy garbage messages )
( What if you cannot see the numbers? )
Please input the magic number

誰來收藏
Loading ...
unlog_NVPO 0