| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 801 人关注过本帖
标题:自编的"sun公司面试题"程序,并有问题请教!
只看楼主 加入收藏
单调黑白
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2007-10-4
收藏
 问题点数:0 回复次数:1 
自编的"sun公司面试题"程序,并有问题请教!

//LF_DateTime.h

#include <time.h>

class CLF_DateTime
{
private:

struct tm *local;

public:
CLF_DateTime(int year, int month, int day,int hour, int min,int sec);
~CLF_DateTime(void);
void display(char * strdisplay);
void setdisplay(char * setstrdisplay);
};


//LF_DateTime.cpp

#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-1900;//struct tm中定义的年成员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)
{
cout<<"Your input date and time is: ";
strftime(strdisplay,80,"%Y-%m-%d %H:%M:%S",local);
cout<<strdisplay<<endl;
system("pause");

}
void CLF_DateTime::setdisplay(char * setstrdisplay)
{
cout<<"Provide rounding:";

if (local->tm_sec>=30&&local->tm_sec<=60)
{
local->tm_min+1&&local->tm_sec==00;
strftime(setstrdisplay,80,"%Y-%m-%d %H:%M:%S",local);
cout <<setstrdisplay<<endl;
system("pause");

else if(local->tm_sec<30&&local->tm_sec>=0)

local->tm_min&&local->tm_sec==00;
strftime(setstrdisplay,80,"%Y-%m-%d %H:%M:%S",local);
cout <<setstrdisplay<<endl;
system("pause");
}
else
cout <<"Input wrong!please input again!"<<endl;
exit(1);

}

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


pa = new CLF_DateTime(2007,11,8,14,50,20);
pa->display(testdisplay);
pa->setdisplay(testdisplay);
return 0;
}



//请大家看看这个程序本身我编的有没有什么问题?我运行的时候总是报"'Debug\TestDateTime.pch' precompiled header file is from a previous version of the compiler, or the precompiled header is C++ and you are using it from C (or vice versa)"错.谢谢!

搜索更多相关主题的帖子: sun公司 int DateTime CLF void 
2007-11-13 11:43
overcome
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-3-11
收藏
得分:0 

编译器版本错误,换一个编译器试试

2007-11-15 14:32
快速回复:自编的"sun公司面试题"程序,并有问题请教!
数据加载中...
 
   



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

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