Question: Consider the following DayOfYear class and implement a function to compare 2 objects of type DayOfYear. The name of the function can be isequal or

Consider the following DayOfYear class and implement a function to compare 2 objects of type DayOfYear. The name of the function can be isequal or something similar. Implement the functions as:

Non-member function

Member function

Friend function

Overloaded == operator

#include

using namespace std;

class DayOfYear

{

public:

void input( );

void output( );

void set(int new_month, int new_day);

int get_month( );

int get_day( );

private:

void check_date( );

int month;

int day;

};

void DayOfYear::input( ){

cout << "Enter the month as a number: ";

cin >> month;

cout << "Enter the day of the month: ";

cin >> day;

check_date( );

}

void DayOfYear::output( ){

cout << "month = " << month << ", day = " << day << endl;

}

void DayOfYear::set(int new_month, int new_day)

{

month = new_month;

day = new_day;

check_date();

}

void DayOfYear::check_date( ){

if ((month < 1) || (month > 12) || (day < 1) || (day > 31))

{

cout << "Illegal date. Aborting program. ";

exit(1);

}

}

int DayOfYear::get_month( ){

return month;

}

int DayOfYear::get_day( ){

return day;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!