Tags: %TAGME{ tpaction="" web="SCMP118" tag="" }% view all tags

Classes and Objects with friends


Enhance Date function with friend and operator methods


1. Start with the Date class. A copy is here : DateClass

2. Add a friend function "bool Equals(Date a, Date b)" that returns true if the dates are equal

3. Can we do arithmetic with dates?

  • Days between to dates?
  • Add days to date to get new date
  • check if a date is real
  • what about leap year?
Algorithms on computing years with leap year: LeapYear

Algorithms converted to friend functions: link

Complete Code from class: https://repl.it/@JimSkon/DateExample-2
Add a friend function "Date Add(Date d, int i) " that adds an integer i days to Date, and returns that date.
Add a operator "==" if the two are equal.
Add a "-" operator that subtracts two Dates, returning the number of days between.

Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r6 - 2019-11-05 - JimSkon
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback