March 29, 2011

時間倒數-先輸入(時 分 秒)


/*許巧慧--B09902147--資工一丙**
*------------第2版------------*
*類別和物件:----------時間倒數*/
#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 print_time();
  void setreciprocal(int,int,int); //倒數時間 
  void sethour2(int);
  void setminute2(int);
  void setsecond2(int);
  int gethour2();
  int getminute2();
  int getsecond2(); 
  void cal_time2();
};
/*建構子*/
Time::Time(int h,int m,int s) 
{
  setreciprocal(h,m,s);   // 倒數時間運作  
}         
/*設定倒數時間*/
void Time::setreciprocal(int h,int m,int s) 
{
  sethour2(h);
  setminute2(m);
  setsecond2(s);
}

void Time::sethour2(int h)
{
hour=h;     
}
void Time::setminute2(int m)
{
minute=m;     
}
void Time::setsecond2(int s)
{
second=s;     
}
/*時間的規格*/
void Time::cal_time2()
{
if(second>0)
  {   
  second--;
  }
  if(second<=0&&minute>0) 
  {
    second=59;
    minute--;
  }
  if(minute<=0&&hour>0) 
  {
    minute=59;
    hour--;
   if(hour<=0) 
   {
   hour=0;            
   } 
 }
}
/*回傳倒數時間*/
int Time::gethour2()
{
  return hour;
}
int Time::getminute2()
{
  return minute;
}
int Time::getsecond2()
{
  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.setreciprocal(h,m,s);
  while(1)
  {
     t.print_time();
     Sleep(1000);   
     t.cal_time2(); 
  } 
system("pause");
return 0;    
}

0推薦此文章
Today's Visitors: 0 Total Visitors: 10
Personal Category: Uncategorized Articles Topic: learning / education / linguistic
[Trackback URL]

Reply
  • 1樓

    1樓搶頭香

    ヽ(´・∀・`@)ノ ァリ ヽ(@´・∀・`)ノ ヵ゙ト v(@´・∀・`@)v йё!!!

  • 巫建宏 at May 31, 2013 10:19 AM comment | email Homepage
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