作业帮 > 综合 > 作业

定义一个时间类,能根据系统当前时间计算年龄.类中包含年月日.

来源:学生作业帮 编辑:搜搜考试网作业帮 分类:综合作业 时间:2024/06/08 03:04:30
定义一个时间类,能根据系统当前时间计算年龄.类中包含年月日.
定义一个时间类,能根据系统当前时间计算年龄.类中包含年月日.
#ifndef _DATE_TIME_H
#define _DTTE_TIME_H
#include
int get_year(){
\x09time_t t;
\x09struct tm *l;\x09
\x09t = time(&t);
\x09l = localtime(&t);\x09
return (l->tm_year + 1900);}
int get_month(){
\x09time_t t;
\x09struct tm *l;\x09
\x09t = time(&t);
\x09l = localtime(&t);
return (l->tm_mon+1);}
int get_day(){
\x09time_t t;
\x09struct tm *l;\x09
\x09t = time(&t);
\x09l = localtime(&t);
return (l->tm_mday);}
int get_hour(){
\x09time_t t;
\x09struct tm *l;\x09
\x09t = time(&t);
\x09l = localtime(&t);
return (l->tm_hour);}
int get_minuts(){
\x09time_t t;
\x09struct tm *l;\x09
\x09t = time(&t);
\x09l = localtime(&t);
return (l->tm_min);}
int get_seconds(){
\x09time_t t;
\x09struct tm *l;\x09
\x09t = time(&t);
\x09l = localtime(&t);
return (l->tm_sec);}
int get_week(){
\x09time_t t;
\x09struct tm *l;\x09
\x09t = time(&t);
\x09l = localtime(&t);
return (l->tm_wday);}

#endif 再答: 上面是用c写的,没有用类
再答: 类可以这么写。。。
再答: class Time{
int year(){
return get_year();}
int month(){
return get_month();}
int day(){
return get_day();}
};
省略掉。。。。。。了
再答: Time t;
int year=t.year();
这个是实例。。。哈哈
再问: 呵呵。年龄呢?系统时间?
再答: 啊。。。。
再答: 真贪婪。。。
再答: 写个函数得了
void age(int year){
Time t;
return t.year()-year;
}