Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
4003CEM-inheritance/lab_date.h
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
51 lines (43 sloc)
955 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef DATE_H | |
#define DATE_H | |
#include <iostream> | |
#include <array> | |
/** Class to store dates **/ | |
class Date | |
{ | |
private: | |
static std::array<int,13> monthDays; | |
protected: | |
int day, month, year; | |
public: | |
Date( int _day=1, int _month=1, int _year=1970 ) | |
{ | |
day = _day; | |
month = _month; | |
year = _year; | |
} | |
/** method to move to the next date **/ | |
void forward() | |
{ | |
int numDays = monthDays[month]; | |
if( day == numDays ) // last day of month | |
{ | |
day = 1; | |
if( month == 12 ) // last month of the year | |
{ | |
month = 1; | |
year += 1; | |
} | |
else | |
month += 1; | |
} | |
else | |
day += 1; | |
} | |
void display() | |
{ | |
std::cout << day << "-" << month << "-" << year << std::endl; | |
} | |
}; | |
std::array<int,13> Date::monthDays { 0,31,28,31,30,31,30,31,31,30,31,30,31 }; | |
#endif |