Advertisement
Guest User

halp.h

a guest
Mar 1st, 2015
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include "myTime.h"
  4. using namespace std;
  5.  
  6. #ifndef MYDATE_H
  7. #define MYDATE_H
  8.  
  9. class myDate
  10. {
  11.  public:
  12.   //Default constructor
  13.   //Description: sets month to 1, day to 1, year to 2015
  14.   //Parameters: none
  15.   myDate();
  16.  
  17.   //sets and gets perform as expected
  18.   void setMonth(int mnth);
  19.   void setDay(int dy);
  20.   void setYear(int yr);
  21.   void setTime(const myTime &tm);
  22.  
  23.   int getMonth() const;
  24.   int getDay() const;
  25.   int getYear() const;
  26.   myTime getTime() const;
  27.  
  28.   //relational operators: compare full date and time
  29.   //A later date/time is "greater" than an earlier one
  30.   bool operator==(const myDate &date) const;
  31.   bool operator<(const myDate &date) const;
  32.   bool operator>(const myDate &date) const;
  33.   bool operator<=(const myDate &date) const;
  34.   bool operator>=(const myDate &date) const;
  35.   bool operator!=(const myDate &date) const;
  36.  
  37.   //Name: compareDates
  38.   //Description: It will compare two dates, not including the times
  39.   //Parameters:  myDate secondDate - IN - the date to compare
  40.   //Return: -1 if the instance is ealier than secondDate
  41.   //         0 if the instance is the same date as secondDate
  42.   //         1 if the instance is later than the secondDate
  43.   int compareDates(const myDate &secondDate) const;
  44.  
  45.   //Name: operator+=
  46.   //Description: Moves the date a head days days
  47.   //Parameters:  days, the number of days to advance the date
  48.   //Return: the instance of the object
  49.   myDate &operator+=(int days);
  50.  
  51.   //Name: toLongDate
  52.   //Description: creates a string for the date using the actual month name
  53.   //             for example 1/2/2012 would return January 2, 2012
  54.   //Return: the long version of the date
  55.  string toLongDate();
  56.  
  57.  private:
  58.   int month, day, year;
  59.   myTime theTime;
  60.  
  61.   //Name: isLeapYear
  62.   //Description: Determines if the year is a leap year
  63.   //A year is a leap year under the following rules:
  64.   //if not divisible by 4, it is not a leap year
  65.   //if divisible by 4 and not 100, it is a leap year
  66.   //if divisible by 4 and 100, it must be be divisible by
  67.   //400 to be a leap year
  68.   //Parameters: none
  69.   //Return: true if leap year, false otherwise
  70.   bool isLeapYear() const;
  71.  
  72.   //Name: daysInMonth
  73.   //Description: uses the month and year to determine the total days
  74.   //Paraemters: none
  75.   //Return: the number of days in the month of the instance
  76.   //remember that February depends on if it is a leap year
  77.   int daysInMonth() const;
  78.  
  79.  
  80.   //Name:convertIntToString
  81.   //Description: Code included for your convenience: YOU DO NOT HAVE TO WRITE THIS FUNCTION
  82.   //This function will return the string version of the integer it is passed
  83.   //Parameters: int i - the interger to convert
  84.   //Return: the string corresponding to the integer i
  85.   string convertIntToString(int i)
  86.   {
  87.     string s;
  88.     stringstream out;
  89.     out << i;
  90.     s = out.str();
  91.     return s;
  92.   }
  93.  
  94. };
  95.  
  96. //Name: operator<<
  97. //Description: writes out the date in the form month/day/year hours:minutes
  98. //Parameters:  ostream output - IN/OUT the stream written to
  99. //             myDate date - IN - the date to write
  100. //Return:     ostream - the stream written to
  101. ostream &operator<<(ostream &output, const myDate &date);
  102.  
  103. //Name: operator>>
  104. //Description: Expects the user to enter a date in the form month/day/year
  105. //             reads ONLY the date part not the time
  106. //Parameters:  istream input - IN/OUT the stream read from
  107. //             myDate date - OUT the date to fill
  108. //Return:     istream - the stream read from
  109. istream &operator>>(istream &input, myDate &date);
  110.  
  111.  
  112.  
  113. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement