//name: Time Convertor
//purpose: 将以秒为单位的时间转化为日时分秒的时间
//author: Ashitaka
#include <iostream>
using namespace std;
const int SECOND{ 1 }; //C++推荐使用const而非#define(C)
const int MINUTE{ SECOND * 60 };
const int HOUR{ MINUTE * 60 };
const int DAY{ HOUR * 24 };
int main(void)
{
unsigned long long second, temp; //temp为了储存second的值因为second变化看
unsigned int minute, hour, day;
cout << "Enter the number of seconds:__________\b\b\b\b\b\b\b\b\b\b"; //利用回车符\b可以制造出在线段上输入的效果
cin >> second;
temp = second;
day = second / DAY; //second = second / DAY + second % DAY
second %= DAY;
hour = second / HOUR;
second %= HOUR;
minute = second / MINUTE;
second %= MINUTE;
cout << temp << " seconds = " << day << " day " //展现C++以分号为代码行结束标志的特性
<< hour << " hour " << minute << " minute "
<< second << " second " << endl; //同时实际观察的代码行不应当过长由此影响阅读
cin.get();
cin.get();
return 0;
}
[C++]时间转化器
最新推荐文章于 2024-06-25 15:55:27 发布