求助,各位大佬帮忙看看怎么修改,总是报错
一个Time类,需要重载构造函数,并且进行加减运算,Time.h:
#ifndef TIME_H
#define TIME_H
class Time
{
int hour;
int minute;
int second;
public:
~Time(void);
Time();
Time(int,int,int);
void init(int,int,int);
void plus(Time& t);
void minus(Time& t);
void print_hms();
};
#endif;
Time.cpp:
#include "StdAfx.h"
#include "Time.h"
#include <iostream>
using namespace std;
Time::~Time(void)
{
}
Time::Time(int h,int m,int s)
{
init(h,m,s);
}
Time::Time()
{
hour=12;
minute=30;
second=30;
}
void Time::init(int h,int m,int s)
{
second=s%60;
minute=(m+s/60)%60;
hour=(h+m/60)%24;
}
void Time::Plus(Time& t)
{
hour=hour+t.hour;
minute=minute+t.minute;
second=second+t.second;
init(hour,minute,second);
}
void Time::minus(Time& t)
{
int sum=(second+60*minute+3600*hour)-(t.second+60*t.minute+3600*t.hour);
second=sum%60;
minute=(sum/60)%60;
hour=(sum/3600)%24;
init(hour,minute,second);
}
void Time::print_hms()
{
cout<<hour<<"-"<<minute<<"-"<<second<<endl;
}
ttt2:
#include "stdafx.h"
#include <iostream>
#include "Time.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
Time time1,time2(11,22,33);
int h,m,s,h2,m2,s2;
cout<<"按照时分秒输出:\n";
time1.print_hms();
time2.print_hms();
cout<<"请输入时间(时、分、秒):\n";
cin>>h>>m>>s;
time1.init(h,m,s);
cout<<"请输入时间为:\n";
cout<<"时分秒:";
time1.print_hms();
cout<<"请输入第二个时间:";
cin>>h2>>m2>>s2;
time2.init(h2,m2,s2);
cout<<"请选择运算类型:";
char i;
cin>>i;
cout<<"运算结果为:";
switch(i)
{
case '+':
{
time1.plus(time2);
time1.print_hms();
break;
}
case '-':
{
time1.minus(time2);
time1.print_hms();
break;
}
default:
cout<<"ERROR!!\n";
}
return 0;
}
下面是报错
各位大佬求助,怎么搞??