Файл интерфейса
Как подлючить файл интерфейса?
В самом начале программы стоит директива: #include "dtime.h" - это не помогает.
Файл интерфейса:
#ifndef dtime_h
#define dtime_h
#include <iostream.h>
#include <ctype.h>
#include <stdlib.h>
#include <conio.h>
class DigitalTime
{
public:
DigitalTime();
DigitalTime(int hourPar, int minPar);
// Inizial. object znacheniem time 0:00 (polnochb)
getHour() const;
getMin() const;
void advance(int minAdded); // Uvelich. time na minAdded minyt
void advance(int hourAdded, int minAdded);
// Uvelich. time na houtAdded chasov and minAdded minyt
friend int operator ==(const DigitalTime& time1, const DigitalTime& time2);
friend istream& operator >>(istream& ins, DigitalTime& objectPar);
friend ostream& operator <<(ostream& outs, const DigitalTime& objectPar);
private:
int hour;
int min;
static void readHour(int& houtPar);
// Time in 24-om formate. Enter hour
static void readMin(int& minPar);
// Enter min
static int digitalToInt(char cPar);
// Perevod iz char in int
};
#endif
Файл реализации:
#include <iostream.h>
#include <ctype.h>
#include <stdlib.h>
#include "dtime.h"
DigitalTime :: DigitalTime() : hour(0), min(0)
{}
DigitalTime :: DigitalTime(int hourPar, int minPar)
{
if (hourPar < 0 || hour > 24 || minPar < 0 || minPar > 59)
{
cout << "Illegal argument to DigitalTime constructor.\n";
exit(1);
}
else
{
hour = hourPar;
min = minPar;
}
if (hour == 24) hour = 0;
}
int DigitalTime :: getHour() const
{
return hour;
}
int DigitalTime :: getMin() const
{
return min;
}
void DigitalTime :: advance(int minAdded)
{
int grossMin = min + minAdded;
min = grossMin % 60;
int hourAdjustment = grossMin / 60;
hour = (hour + hourAdjustment) % 24;
}
void DigitalTime :: advance(int hourAdded, int minAdded)
{
hour = (hour + hourAdded) % 24;
advance(minAdded);
}
istream& operator >>(istream& ins, DigitalTime& objectPar)
{
DigitalTime :: readHour(objectPar.hour);
DigitalTime :: readMin(objectPar.min);
return ins;
}
ostream& operator <<(ostream& outs, const DigitalTime& objectPar)
{
outs << objectPar.hour << ':';
if (objectPar.min < 10)
outs << '0';
outs << objectPar.min;
return outs;
}
int operator ==(const DigitalTime& time1, const DigitalTime& time2)
{
return (time1.hour == time2.hour && time1.min == time2.min);
}
void DigitalTime :: readHour(int& hourPar)
{
char c1, c2;
cin >> c1 >> c2;
if ( ! (isdigit(c1) && (isdigit(c2) || c2 == ':') ) )
{
cout << "Error illegal input to readHour.\n";
exit(1);
}
if (isdigit(c1) && c2 == ':')
{
hourPar = DigitalTime :: digitalToInt(c1);
}
else
{
hourPar = DigitalTime :: digitalToInt(c1) * 10 + DigitalTime :: digitalToInt(c2);
cin >> c2;
if (c2 != ':')
{
cout << "Error illegal input to readhour.\n";
exit(1);
}
}
if (hourPar == 24) hourPar = 0;
if (hourPar < 0 || hourPar > 23)
{
cout << "Error illegal input to readHour.\n";
exit(1);
}
}
void DigitalTime :: readMin(int& minPar)
{
char c1, c2;
cin >> c1 >> c2;
if ( ! (isdigit(c1) && isdigit(c2)) )
{
cout << "Error illegal input to readMin.\n";
exit(1);
}
minPar = digitalToInt(c1) * 10 + digitalToInt(c2);
if (minPar < 0 || minPar > 59)
{
cout << "Error illegal input to readMin.\n";
exit(1);
}
}
int DigitalTime :: digitalToInt(char c)
{
return (int(c) - int('0'));
}
Файл приложения:
#include <iostream.h>
#include <conio.h>
#include "dtime.h"
int main()
{
clrscr();
DigitalTime clock, oldClock;
cout << "You may write midnight as either 0:00 or 24:00,\n"
<< "but, I will always write it as 0:00.\n"
<< "Enter the time in 24 hour notation: ";
cin >> clock;
oldClock = clock;
clock.advance(15);
if (clock == oldClock)
cout << "Something is wrong.";
cout << "You entered " << oldClock << endl
<< "15 min later the time will be "
<< clock << endl;
clock.advance(2, 15);
cout << "2 hours and 15 min after that\n"
<< "the time will be "
<< clock << endl;
return 0;
}
Если у тя есть коды дай я ппросмотрю
Код:
#include<dtime.h>
Не получиться выложи полные исходники.