Difference: Lab7Startup (2 vs. 3)

Revision 32018-03-29 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="Fall2017"

Classes and Objects with friends

Goal

Enhance Date function with friend and operator methods

Steps

Changed:
<
<
  1. Start with the Date class developed previously in 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. Add a friend function "Date Add(Date d, int i) " that adds an integer i days to Date, and returns that date.
  4. Add a operator "==" if the two are equal.
  5. Add a "+" opperator that adds Date with an integer: d2 = d1 + 16;
>
>
1. Start with the Date class developed previously in 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?
Review these algorithms on computing years with leap year: link

Algorithms converted to friend functions: link


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 "+" opperator that adds Date with an integer: d2 = d1 + 16;

 
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback