Page 1 of 1

## 1 Replies - 386 Views - Last Post: 04 December 2012 - 04:29 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=302753&amp;s=3b54dc0934c9367276e2893e8cb9c71f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Jbf1001

Reputation: 1
• Posts: 31
• Joined: 24-October 12

Posted 04 December 2012 - 04:20 PM

My proffessors instructions are often quite confusing. So I think I have this written correctly, but the output only gives me this:

Month = 1, Day = 1
Month = 1, Day = 1
The dates are the same!

Could someone point me in the direction of the problem. Please don't just give me the fixed code. I want to understand the problem and the solution.
```#include <iostream>
using namespace std;

class DayOfYear
{
public:
DayOfYear(int theMonth, int theDay);
DayOfYear();
void setMonth(int newMonth);
void setDay(int newDay);
int getMonth();
int getDay();
friend istream& operator >>(istream& ins, DayOfYear date);
friend ostream& operator <<(ostream& outs, const DayOfYear date);
friend bool operator ==(DayOfYear date1, DayOfYear date2);
private:
int month;
int day;
};

int main()
{
DayOfYear date_1, date_2;

cout << "Enter the Day and Month separated by a space." << endl;
cin >> date_1;

cout << "Enter the Day and Month separated by a space." << endl;
cin >> date_2;

cout << "Date 1:" << endl;
cout << date_1;

cout << "Date 2:" << endl;
cout << date_2;

if(date_1 == date_2){
cout << "The dates are the same!" << endl;
}else{
cout << "The dates are different!" << endl;
}
return 0;
}

bool operator ==(DayOfYear date1, DayOfYear date2)
{
return ((date1.month == date2.month) &&
(date1.day == date2.day));
}

DayOfYear::DayOfYear(int theMonth, int theDay)
{
if ((theMonth >= 1) && (theMonth <= 12) && (theDay >= 1) && (theDay <= 31))
{
month = theMonth;
day = theDay;
}
else
{
cout << "Error!  Invalid initial value for month and / or day." << endl;
cout << "Setting both values to 1." << endl;
day = 1;
month = 1;
}
}

DayOfYear::DayOfYear()
{
month = 1;
day = 1;
}

void DayOfYear::setMonth(int newMonth)
{
if ((newMonth >= 1) && (newMonth <= 12))
month = newMonth;
else
cout << "Error!  The month must be between 1 and 12." << endl;
}

void DayOfYear::setDay(int newDay)
{
if ((newDay >= 1) && (newDay <= 31))
day = newDay;
else
cout << "Error!  The month must be between 1 and 31." << endl;
}

int DayOfYear::getMonth()
{
return month;
}

int DayOfYear::getDay()
{
return day;
}

istream& operator >>(istream& ins, DayOfYear date)
{
int tempMonth, tempDay;

ins >> tempMonth;
date.setMonth(tempMonth);

ins >> tempDay;
date.setDay(tempDay);

return ins;
}

ostream& operator <<(ostream& outs, const DayOfYear date)
{
outs << "month = " << date.month << ", day = " << date.day << endl;
return outs;
}

```

Is This A Good Question/Topic? 0

### #2 Jbf1001

Reputation: 1
• Posts: 31
• Joined: 24-October 12

Posted 04 December 2012 - 04:29 PM

O.K. so I jumped the gun early on this one. HAHA. I had to change some of my 'DayOfYear' to 'DayOfYear&'. Pass by reference really makes a difference hahaha

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }