-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDate.cpp
44 lines (41 loc) · 1021 Bytes
/
Date.cpp
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
#define _CRT_SECURE_NO_WARNINGS
#include "Date.h"
#include <iostream>
using namespace std;
namespace votes
{
Date::Date()
{
_day = 1;
_month = 1;
_year = 1900;
}
Date::Date(int day ,int month , int year)
{
string errorName;
if (year < 0)
throw (errorName = "Year can't be a negative number");
if (month < 1 || day > maxDayPerMonth[month] || day < 1)
throw (errorName = "Date wasn't valid, out of the calander");
_day = day;
_month = month;
_year = year;
}
void Date::saveDate(ostream& out) const
{
out.write(rcastcc(&_day), sizeof(_day));
out.write(rcastcc(&_month), sizeof(_month));
out.write(rcastcc(&_year), sizeof(_year));
}
void Date::loadDate(istream& in)
{
in.read(rcastc(&_day), sizeof(_day));
in.read(rcastc(&_month), sizeof(_month));
in.read(rcastc(&_year), sizeof(_year));
}
ostream& operator<<(ostream& os, const Date& date)
{
os << "The Election Date is: " << date.getDay() << "/" << date.getMonth() << "/" << date.getYear() << endl;
return os;
}
}