31.01.2014 Views

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

4.3 Arithmetic Operations<br />

date D + int d returns the date d days after D.<br />

date D − int d returns the date d days before D.<br />

<strong>The</strong> related operators ++, −−, +=, −= and all comparison operators are also provided.<br />

int<br />

D − const date& D2 returns the difference between D and D2 in days.<br />

int D.days until(const date& D2)<br />

returns D2 −D.<br />

int D.months until(const date& D2 )<br />

int D.years until(const date& D2 )<br />

4.4 Miscellaneous Predicates<br />

bool date :: is valid(int d, month m, int y)<br />

if D2 ≥ D then max{m : D.add to month(m) ≤<br />

D2 } is returned; otherwise the result is<br />

−D2.months until(D).<br />

if D2 ≥ D then max{y : D.add to year(y) ≤ D2 } is<br />

returned; otherwise the result is −D2.years until(D).<br />

returns true iff d.m.y represents a valid date.<br />

bool<br />

date :: is valid(string d, bool swallow = true)<br />

returns true iff d represents a valid date. If swallow<br />

is true the swallow format (cf. set date) is used, otherwise<br />

the current input format is tried.<br />

bool date :: is leap year(int y)<br />

bool D.is last day in month( )<br />

5. Example<br />

returns true iff y is a leap year.<br />

let D be d.m.y; the function return true iff d is the<br />

last day in the month m of the year y.<br />

We count the number of Sundays in the days from now to 1.1.2010 using the following<br />

code chunk:<br />

int number_of_Sundays = 0;<br />

for (date D; D

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!