| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 486 人关注过本帖
标题:我的库Time 有些错误,怎么改正?
只看楼主 加入收藏
abcef2006
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-11-3
收藏
 问题点数:0 回复次数:0 
我的库Time 有些错误,怎么改正?

/*Time.h 头文件*/
#include <iostream>
struct Time
{
unsigned hour,
Minute;
char AMorPM;
unsigned milTime;
};
void set(Time &t,unsigned hours,unsigned minutes,char AMPM);
void display(const Time &t,ostream &out);
void advance(Time & t,unsigned hours,unsigned minutes);
bool lessThan(const Time &t1,const Time &t2);


/* Time.cpp */
// Time.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "iostream"
using namespace std;
#include "Time.h"

int toMilitary(unsigned hours,unsigned minutes,char AMPM);
void toStandard(unsigned military,unsigned &hours,unsigned &minutes,char &AMPM);
void set(Time &t,unsigned &hours,unsigned &minutes,char AMPM)
{
if(hours>=1&&hours<=12&&minutes>=0&&minutes<=59&(AMPM=='A'||AMPM=='p'))
{
t.hours=hours;
t.minutes=minutes;
t.AMorPM=AMPM;
t.milTime=toMilitary(hours,minutes,AMPM);
}
else
cerr<<" ***Can't set time with these values***\n"
}

void display(const Time &t,ostream &out)
{
cout<<t.hour<<':'
<<(t,minutes<10 ?""<<t.minute
<<' '<<t.AMorPM<<'.M.'
<<t.milTime<<" mil.Time";
}
void advance(Time &t,unsigned &hours,unsigned minutes)
{
t.milTime+=100*hours+minutes;
unsigned milHours=t.milTimes/100;
unsigned milMins=t.milTime%100;
milHours+=milMins/60;
milMins%=60;
milHours%=24;
t.milTime=100*milHours+milMins;
toStandard(t.milTime,t.hour,t.minute,t.AMorPM);
}

bool lessThan(const Time &t1,const Time &t2)
{
return (t1.milTime<t2.milTime);
}

int toMilitary(unsigned hours,unsigned minutes,char AMPM)
{
if(hours==12)
hours=0;
return hours*100+minutes+(AMPM=='P'?1200:0);
}

void toStandard(unsigned military,unsigned &hours,unsigned &minutes,char &AMPM)
{
hours=(military/100)%12;
if(hours==0)
hours=12;
minutes=military%100;
AMPM=(military/100)<12?'a':'p';
}


int _tmain(int argc, _TCHAR* argv[])
{

return 0;
}

生成时的错误提示:
错误 1 error C2065: “Time”: 未声明的标识符 c:\users\a\documents\visual studio 2005\projects\adts-119\time\time.cpp 11
错误 2 error C2065: “t”: 未声明的标识符 c:\users\a\documents\visual studio 2005\projects\adts-119\time\time.cpp 11
错误 3 error C2062: 意外的类型“unsigned int” c:\users\a\documents\visual studio 2005\projects\adts-119\time\time.cpp 11
错误 4 error C2143: 语法错误 : 缺少“;”(在“{”的前面) c:\users\a\documents\visual studio 2005\projects\adts-119\time\time.cpp 12
错误 5 error C2447: “{”: 缺少函数标题(是否是老式的形式表?) c:\users\a\documents\visual studio 2005\projects\adts-119\time\time.cpp 12
错误 6 error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int c:\users\a\documents\visual studio 2005\projects\adts-119\time\time.cpp 24
错误 7 error C2143: 语法错误 : 缺少“,”(在“&”的前面) c:\users\a\documents\visual studio 2005\projects\adts-119\time\time.cpp 24
错误 8 error C2228: “.hour”的左边必须有类/结构/联合 c:\users\a\documents\visual studio 2005\projects\adts-119\time\time.cpp 26
错误 9 error C2065: “minutes”: 未声明的标识符 c:\users\a\documents\visual studio 2005\projects\adts-119\time\time.cpp 27
错误 10 error C2228: “.minute”的左边必须有类/结构/联合 c:\users\a\documents\visual studio 2005\projects\adts-119\time\time.cpp 28
错误 11 error C2228: “.AMorPM”的左边必须有类/结构/联合 c:\users\a\documents\visual studio 2005\projects\adts-119\time\time.cpp 28
错误 12 error C2228: “.milTime”的左边必须有类/结构/联合 c:\users\a\documents\visual studio 2005\projects\adts-119\time\time.cpp 29
错误 13 error C2143: 语法错误 : 缺少“,”(在“;”的前面) c:\users\a\documents\visual studio 2005\projects\adts-119\time\time.cpp 29
错误 14 error C2143: 语法错误 : 缺少“)”(在“}”的前面) c:\users\a\documents\visual studio 2005\projects\adts-119\time\time.cpp 30
错误 15 error C2143: 语法错误 : 缺少“;”(在“)”的前面) c:\users\a\documents\visual studio 2005\projects\adts-119\time\time.cpp 30
错误 16 error C2062: 意外的类型“unsigned int” c:\users\a\documents\visual studio 2005\projects\adts-119\time\time.cpp 31
错误 17 error C2143: 语法错误 : 缺少“;”(在“{”的前面) c:\users\a\documents\visual studio 2005\projects\adts-119\time\time.cpp 32
错误 18 error C2447: “{”: 缺少函数标题(是否是老式的形式表?) c:\users\a\documents\visual studio 2005\projects\adts-119\time\time.cpp 32
错误 19 error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int c:\users\a\documents\visual studio 2005\projects\adts-119\time\time.cpp 43
错误 20 error C2143: 语法错误 : 缺少“,”(在“&”的前面) c:\users\a\documents\visual studio 2005\projects\adts-119\time\time.cpp 43
错误 21 error C2065: “t1”: 未声明的标识符 c:\users\a\documents\visual studio 2005\projects\adts-119\time\time.cpp 45
错误 22 error C2228: “.milTime”的左边必须有类/结构/联合 c:\users\a\documents\visual studio 2005\projects\adts-119\time\time.cpp 45
错误 23 error C2065: “t2”: 未声明的标识符 c:\users\a\documents\visual studio 2005\projects\adts-119\time\time.cpp 45
错误 24 error C2228: “.milTime”的左边必须有类/结构/联合 c:\users\a\documents\visual studio 2005\projects\adts-119\time\time.cpp 45


测试Time的驱动程序:
// adts-119.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"

#include "iostream"
using namespace std;
#include "Time.h"
int _tmain(int argc, _TCHAR* argv[])
{
Time mealTime,
goToWorkTime;
set(mealTime,5,30,'P');
cout<<"We'll be eating at ";
display(mealTime,cout);
cout<<endl;
set(goToWorkTime,5,30,'P');
cout<<"You leave for work at ";
display(goToWorkTime,cout);
cout<<endl;
if(lessThan(mealTime,goToWorkTime))
cout<<"If you hurry ,you can eat first.\n";
else
cout<<"Sorry you can't eat with us.\n";
advance(goToWorkTime,0,30);
cout<<"You boss called.You go in later at ";
display(goToWorkTime,cout);
cout<<endl;
if(lessThan(mealTime,goToWorkTime))
cout<<"If you hurry ,you can eat first.\n";
else
cout<<"Sorry you can't eat with us .\n";
cout<<endl;


return 0;
}


搜索更多相关主题的帖子: Time 
2007-11-03 16:35
快速回复:我的库Time 有些错误,怎么改正?
数据加载中...
 
   



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

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