1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
#include <iostream>
using namespace std;
struct Date
{
int day;
int month;
int year;
};
//prototype
int timeComparison(const Date *d, const Date *e);
/*************************************
* Function: main
* Description:
**************************************/
int main()
{
//variables
Date d1;
Date e1;
Date d2;
Date e2;
Date d3;
Date e3;
//days = 1-30, months = 1-12, years = -5000 - 5000
d1.day = 6, d1.month = 4, d1.year = 1990;
e1.day = 14, e1.month = 12, e1.year = 2004;
d2.day = 29, d2.month = 12, d2.year = 2014;
e2.day = 14, e2.month = 12, e2.year = 2014;
d3.day = 21, d3.month = 7, d3.year = 2004;
e3.day = 21, e3.month = 7, e3.year = 2004;
timeComparison(&d1, &e1);
timeComparison(&d2, &e2);
timeComparison(&d3, &e3);
return 0;
}
/*************************************
* Function: timeComparison
* Description:
* Input:
* Output:
**************************************/
int timeComparison(const Date *d, const Date *e)
{
//variables
int lowerTime = 1;
int equalTime = 0;
int higherTime = -1;
if (d->year > e->year)
{
return lowerTime;
}
if (d->year < e->year)
{
return higherTime;
}
if (d->year == e->year)
{
if (d->month > e->month)
{
return lowerTime;
}
}
if (d->year == e->year)
{
if (d->month < e->month)
{
return higherTime;
}
}
if (d->year == e->year)
{
if (d->month == e->month)
{
if (d->day > e->day)
{
return lowerTime;
}
}
}
if (d->year == e->year)
{
if (d->month == e->month)
{
if (d->day < e->day)
{
return higherTime;
}
}
}
if (d->year == e->year)
{
if (d->month == e->month)
{
if (d->day == e->day)
{
return equalTime;
}
}
}
}
|