老师布置的作业..AB行都是自己写的..程序运行不出来.谁教教我..不甚感激....
#include
#include
#include
#include
class Time{
public: Time(char* s=NULL);void operator+(Time& ti);
void operator-(Time& ti);void Display();
protected:int hour;int minute;int second;
};
Time::Time(char* s)
{ char str[9]={0};char t[3]={0};
if(s)
strncpy(str, s, 8);
else
_strtime(str);
hour=atoi(strncpy(t,str,2))%24;
minute=atoi(strncpy(t,&str[3],2))%60;
second=atoi(strncpy(t,&str[6],2))%60;
}
void Time::operator +(Time& ti)
{
return Time(hour+& ti.hour,minute+& ti.minute,second+& ti.second); .........A
}
void Time::operator -(Time& ti)
{
return Time(hour-& ti.hour,minute-& ti.minute,second-& ti.second); .........B
}
void Time::Display()
{ char result[9]="XX:XX:XX";
result[0]='0'+hour%10;
result[1]='0'+hour/10;
result[3]='0'+minute%10;
result[4]='0'+minute/10;
result[6]='0'+second%10;
result[7]='0'+second/10;
cout <}
void main()
{
Time a;
Time b("02:15:30");
a+b;
a.Display();
}
--------------------next---------------------
G:\Personal\new\桌面\Cpp2.cpp(22) : error C2661: 'Time::Time' : no overloaded function takes 3 parameters
没有被重载的函数来包含那3个变量!
G:\Personal\new\桌面\Cpp2.cpp(26) : error C2113: pointer can only be subtracted from another pointer
指针只能从另一个指针来相减!
G:\Personal\new\桌面\Cpp2.cpp(26) : error C2113: pointer can only be subtracted from another pointer
指针只能从另一个指针来相减!
G:\Personal\new\桌面\Cpp2.cpp(26) : error C2113: pointer can only be subtracted from another pointer
指针只能从另一个指针来相减!
G:\Personal\new\桌面\Cpp2.cpp(26) : error C2661: 'Time::Time' : no overloaded function takes 3 parameters
没有被重载的函数来包含那3个变量!
G:\Personal\new\桌面\Cpp2.cpp(36) : error C2065: 'resule' : undeclared identifier
未申报的标识符!
建议你仔细查下程序,你没有定义申明重载函数,而且指针运算有错误!
--------------------next---------------------
阅读(2099) | 评论(0) | 转发(0) |