标题:自编的"sun公司面试题"程序,并有问题请教!
取消只看楼主
单调黑白
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2007-10-4
 问题点数:0 回复次数:0 
自编的"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



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-185728-1-1.html




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

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