[PHP]Здравствуйте. Столкнулся с проблемой при работе с классом (Время), что выводит или чушь или вообще ничего не выводит. Прописал (вроде бы) 1 функцию и 1 оператор.
Код C++.
Файл main.cpp
PHP код:
[CODE]//---------------------------------------------------------------------------
#include <iostream>
#include "ctime.h"
using namespace std;
using namespace std;
int main()
{
int h,m,s;
cout << "Enter hour: ";
cin >> h;
cout << "Enter minute: ";
cin >> m;
cout << "Enter seconds: ";
cin >> s;
CTime D(1,2,3);
cout<<"A:\n";
CTime A(h,m,s);
cout<< A<<endl;
cout<<"\nB:\n";
CTime B (15, 16, 20);
cout << B;
;
CTime C = A + B;
cout<<"\nC:\n";
cout << C;
C = A - B;
cout<<"\nC:\n";
cout << C;
C = B - A;
cout<<"\nC:\n";
cout << C;
if (A.isNight()) cout<<"\nNight\n";
if (A.isDay()) cout<<"\nDay\n";
if (A.isMorning()) cout<<"\nMorning\n";
if (A.isEvening()) cout<<"\nEvening\n";
cout << "\n" ;
if (A == B) cout<< "\nA==B\n";
else cout<<"\n A!=B \n";
CTime PrintT(A);
return 0;
}
//---------------------------------------------------------------------------
[/CODE]
И заголовочный файл:
PHP код:
[CODE]// ctime.h
#include <iostream.h>
class CTime {
private:
int hour; //?anu
int minute; //ieioou
int seconds; //naeoiau
public:
CTime( int, int, int );
~CTime();
CTime operator+ ( CTime ); //iia?aoi? nei?aiey
CTime operator- ( CTime ); //iia?aoi? au?eoaiey
bool operator==( CTime ); //iia?aoi? ?aaainoaa
bool operator> ( CTime ); //iia?aoi? n?aaiaiey
bool operator< ( CTime ); //iia?aoi? n?aaiaiey
friend ostream& operator<<(ostream&, const CTime&);
friend istream& operator>>(istream&, CTime&);
bool isNight (); //i?iaa?ea ia a?aiy aiy: Ii?u, Aaiu, Oo?i, Aa?a?
bool isDay ();
bool isMorning ();
bool isEvening ();
void PrintT ();
void Convert();
};
//////////////////////////////////////////////////////////
CTime :: CTime( int nHour, int nMunute, int nSeconds)
{
}
//////////////////////////////////////////////////////////
CTime :: ~CTime()
{
}
//////////////////////////////////////////////////////////
CTime CTime :: operator+( CTime tm )
{
CTime t( this -> hour, this -> minute,this -> seconds );
t.hour += tm.hour;
t.minute += tm.minute;
t.seconds += tm.seconds;
if (t.seconds >= 60) {
do {
t.seconds -= 60;
t.minute += 1;
} while (t.seconds >= 60);
}
if (t.minute >= 60) {
do {
t.minute -= 60;
t.hour += 1;
} while(t.minute >= 60);
}
if(t.hour >= 24) {
t.hour = t.hour % 24;
}
return t;
}
//////////////////////////////////////////////////////////
CTime CTime :: operator-( CTime tm )
{
CTime t(this->hour, this->minute, this->seconds);
t.hour -= tm.hour;
t.minute -= tm.minute;
t.seconds -= tm.seconds;
if(t.seconds < 0) {
t.seconds += 60;
t.minute -= 1;
}
if(t.minute < 0) {
t.minute += 60;
t.hour -= 1;
}
if(t.hour < 0) {
t.hour = -t.hour;
}
return t;
}
//////////////////////////////////////////////////////////
bool CTime :: operator==( CTime t )
{
return (this -> hour == t.hour && this -> minute == t.minute && this -> seconds == t.seconds);
}
//////////////////////////////////////////////////////////
bool CTime :: operator>( CTime t )
{
return (this -> hour > t.hour);
}
//////////////////////////////////////////////////////////
bool CTime :: operator<( CTime t )
{
return (this -> hour < t.hour);
}
//////////////////////////////////////////////////////////
bool CTime :: isNight()
{
return (this -> hour < 6);
}
//////////////////////////////////////////////////////////
bool CTime :: isMorning()
{
return (this -> hour >= 6 && this -> hour < 12);
}
//////////////////////////////////////////////////////////
bool CTime :: isDay()
{
return (this -> hour >= 12 && this -> hour < 18);
}
//////////////////////////////////////////////////////////
bool CTime :: isEvening ()
{
return (this -> hour >= 18 && (this -> hour < 23 && this -> minute < 59 && this -> seconds < 59));
}
//Вот я попытался функцией
void CTime :: PrintT ()
{
std::cout<<this -> hour<<":"<<this -> minute<<":"<<this -> seconds<<endl;
}
//Не работает :(
istream& operator>>(istream &input, CTime &t){
cout << "Enter hour: ";
input >> t.hour;
cout << "Enter minute: ";
input >> t.minute;
cout << "Enter seconds: ";
input >> t.seconds;
return input;
}
//А вот оператор
ostream& operator<<(ostream &output, const CTime &t){
output<<t.hour<<":"<<t.minute<<":"<<t.seconds<<endl;
return output;
}
void CTime :: Convert()
{
} [/CODE]
Заранее спасибо