📄 pr11005.cpp
字号:
////////////////////////////////////////
// File Name: pr11005.cpp
////////////////////////////////////////
#include <iostream>
#include <ctime>
#include <stdio.h>
////////////////////////////////////////
// The Date class declaration.
////////////////////////////////////////
class Date
{
int mo, da, yr;
public:
Date(time_t); // conversion constructor function
void display();
};
////////////////////////////////////////
// The Date class definition.
////////////////////////////////////////
// Member function to display the date.
void Date::display()
{
char year[5];
if (yr < 10)
std::sprintf(year, "0%d", yr);
else
std::sprintf(year, "%d", yr);
std::cout << mo << '/' << da << '/' << year;
}
// Constructor conversion function.
Date::Date(time_t now)
{
std::tm* tim = std::localtime(&now);
da = tim->tm_mday;
mo = tim->tm_mon + 1;
yr = tim->tm_year;
if (yr >= 100)
yr -= 100;
}
////////////////////////////////////////
// The main() function.
////////////////////////////////////////
int main()
{
// Get today's date and time.
std::time_t now = std::time(0);
// Construct a Date object by invoking
// the conversion constructor.
Date dt(now);
// Display the date.
dt.display();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -