| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1564 人关注过本帖
标题:这是SUN公司的一道改错的题!请大家踊跃发表意见
取消只看楼主 加入收藏
单调黑白
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2007-10-4
收藏
 问题点数:0 回复次数:2 
这是SUN公司的一道改错的题!请大家踊跃发表意见

//"LF_DateTime.h"

#include <time.h>

class CLF_DateTime
{
private:
struct tm *local;
time_t t;
char str[80];
public:
CLF_DateTime(int year, int month, int day,int hour, int min,int sec);
~CLF_DateTime();
void display();
};

#include "LF_DateTime.h"
#include <time.h>
#include <iostream>

using namespace std;

CLF_DateTime::CLF_DateTime(int year, int month, int day,int hour, int min,int sec)
{
local = new tm;
local->tm_year = year;
local->tm_mon = month;
local->tm_mday = day;
local->tm_hour =0;
local->tm_min =0;
local->tm_sec =0;

}

CLF_DateTime::~CLF_DateTime(void)
{
delete(local);
}

void CLF_DateTime::display()
{

strftime(str*,80,"%Y-%m-%d %H:%M:%S",local);
cout<<"Your input time is:"<<str<<endl;
}
int main()
{

CLF_DateTime str(2005,10 ,01 , 11,50,23);

str.display();

return 0;
}

搜索更多相关主题的帖子: int SUN DateTime CLF 踊跃 
2007-11-08 10:43
单调黑白
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2007-10-4
收藏
得分:0 
回复:(单调黑白)这是SUN公司的一道改错的题!请大家...

谢谢大家的踊跃发言!
我也分析出来了一些错误,但还是不全,最后是由本论坛"yijing21"给出了最好的答案 他的修改如下:

//LF_DateTime.h

class CLF_DateTime
{
private:
struct tm *local;
//time_t t;
// char str[80];
public:
CLF_DateTime(int year, int month, int day,int hour, int min,int sec);
~CLF_DateTime(void);
void display(char * strdisplay);
};


//LF_DateTime.cpp


#include <time.h>
#include <iostream>

using namespace std;

CLF_DateTime::CLF_DateTime(int year, int month, int day,int hour, int min,int sec)
{
local = new tm;
local->tm_year = year-1900;//tm_year是从1900年起开始计算 也就是说他显示2007时tm_year值并不是2007
local->tm_mon = month-1;//月份可见definition里有说明是[0,11]所以比现实小了一个月
local->tm_mday = day;
local->tm_hour =hour;
local->tm_min =min;
local->tm_sec =sec;

}

CLF_DateTime::~CLF_DateTime(void)
{
delete(local);
}

void CLF_DateTime::display(char * strdisplay)
{

strftime(strdisplay,80,"%Y-%m-%d %H:%M:%S",local);//这里并未用到str[80]
cout<<strdisplay<<endl;


}

int main()
{
CLF_DateTime *pa;
char testdisplay[100];


pa = new CLF_DateTime(2005,10,01,11,50,35);
pa->display(testdisplay);
//cout<<testdisplay<<endl;//重复输出

return 0;
}

大家继续往下看:
此题到此并未完,这只是第一步!
接下来的要求:
1.尝试把时间精确到微秒.
2.将存储的日期时间 四舍五入精确的分钟.for exemple:"2005-10-01 11:51:00.0000".
3.对比存储的日期时间和四舍五入后的日期时间,舍存储的日期时间(a),四舍五入后的日期时间(b)
Results:
(a>b,result=1)
(a=b,result=0)
(a<b,result=-1)

至此,此题完全解完!(要求要在原题的基础上做修改)

请大家继续关注此题并踊跃发言!谢谢!



雕刻单调的人生
2007-11-08 15:35
单调黑白
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2007-10-4
收藏
得分:0 
回复:(单调黑白)这是SUN公司的一道改错的题!请大家...
应该是可以 但我也还没想到 后面我都不太知道怎么做了 请高手指教!

雕刻单调的人生
2007-11-09 09:54
快速回复:这是SUN公司的一道改错的题!请大家踊跃发表意见
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016474 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved