Category : C++ Source Code
Archive   : TEACHCPP.ZIP
Filename : EX07014.CPP
// Friend classes, forward reference
#include
// -------- Julian date class
class Julian {
int da, yr;
public:
Julian() {}
Julian(int d, int y) { da = d; yr = y;}
void display() {cout << '\n' << yr << '-' << da;}
friend class Date; // <--- forward reference to class
};
// ------- date class
class Date {
int mo, da, yr;
public:
Date(int m, int d, int y) { mo = m; da = d; yr = y; }
operator Julian();
};
static int dys[] = {31,28,31,30,31,30,31,31,30,31,30,31};
// ---- member conversion function (Julian <- Date)
Date::operator Julian()
{
Julian jd(0, yr);
for (int i = 0; i < mo-1; i++)
jd.da += dys[i];
jd.da += da;
return jd;
}
main()
{
Date dt(11,17,89);
Julian jd;
jd = dt;
jd.display();
}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/