Large negative number output

When printday is called is see my variables initalize to the required dates, during the debug process, however it prints a large negative number, and I dont understand why this is happening. The second print is fine and I have no issues, besides the first print.

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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include <iostream>
#include <string>
using namespace std;


class Time
{
public:
	void setTime (int hr, int min);
	void getTime(int &hr, int &min);
	void printTime();
	Time(int hr, int min);
	Time();
private:
	int hour;
	int minute;
};

class Date
{
public:
	void setDate(int month = 1, int day = 1, int yr = 2000);
	void  getDate(int &m, int &d, int &y);
	void printDate();
	Date (int month, int day, int year);
	Date();
private:
	int month;
	int day;
	int year;
};

class Event
{
public:
	
	void setEventData(string eventName, int hour, int minute, int month, int day, int year);
	void printEventData() ;
	Event(string EventName = "Generic Event", int hour = 0, int minute = 0,
		int month = 1, int day = 1, int year = 2000);
private:
	string EventName;
	Time eventTime;
	Date eventDate;
};





Date::Date(int m, int d, int yr)
{
	int month = m;
	int day = d;
	int year = yr;
}

Date::Date()
{
	month = day = 1;
	year = 2000;
}

void Date::setDate(int m, int d, int yr)
{
	month = m;
	day = d;
	year = yr;
}

void Date::printDate()
{ 
	int m, d, y;
	getDate(m, d, y);
	if (m < 10) cout << "0";
	cout << m << "/";
	if (d < 10) cout << "0";
	cout << d << "/";
	if (y < 100) cout << "20";
	cout << y;
}

void Date::getDate(int &m, int &d, int &yr)
{
	m = month;
	d = day;
	yr = year;
}


Event::Event(string name, int hour, int minute, int month, int day, int year)
	: eventTime(hour,minute), eventDate(month,day,year)
{ 
	EventName = name;
}

void Event::setEventData(string name, int hr, int min, int mon, int day, int yr)
{
	EventName = name;
	eventTime.setTime(hr, min);
	eventDate.setDate(mon, day, yr);
}

void Event::printEventData() 
{
	cout << EventName << " occurs ";
	eventDate.printDate();
	cout << " at ";
	eventTime.printTime();
}



Time::Time()
{
	hour = minute = 0;
}

Time::Time(int hr, int min)
{
	hour = hr;
	minute = min;
}

void Time::getTime(int &hr, int &min)
{
	hr = hour;
	min = minute;
}

void Time::setTime(int hr, int min)
{
	hour = hr;
	minute = min;
}

void Time::printTime()
{
	int hr, min;
	getTime(hr, min);
	if (hr < 10) cout << "0";
	cout << hr << ":";
	if (min < 10) cout << "0";
	cout << min;
}

int main()
{
	Event event("New Year's Day", 1,1,1,1,2008);
	event.printEventData();
	cout << endl;
	event.setEventData("Valentine's Day", 12, 15,2, 14, 2010);
	event.printEventData();
	cout << endl;

	cin.get();
	cin.get();

	return 0;

	
}
closed account (DSLq5Di1)
1
2
3
4
5
6
Date::Date(int m, int d, int yr)
{
	int month = m;
	int day = d;
	int year = yr;
}

A prefix for member variables, such as "m_year" would help alleviate this headache in the future, and it would be preferable to have your constructor call setDate instead of replicating its functionality.
Topic archived. No new replies allowed.