Question: Must include 5 screenshot of a working code Must include 5 screenshot of a working code Homework #1 DayOfYear Class For this assignment, we will

Must include 5 screenshot of a working code

Must include 5 screenshot of a working code

Homework #1

DayOfYear Class

For this assignment, we will be modifying the DayOfYear class found in Display 7.1 of the textbook. Specifically, operators will be overloaded. And we will test them out.

Class Requirements:

You may assume that there are 12 months in a year, and every month has 30 days. (360 days in a year). See Extra Credit section below Use member initialization and constructor delegation when possible Your program should be const-consistent Use references for return types and parameters where appropriate Overload the following operators (Shown using types):

DayOfYear + DayOfYear: Add the months and days, return an object by value DayOfYear + int: Add an integer amount of days to a DayOfYear object DayOfYear - DayOfYear: Return the number of days between the two dates. You should only perform the subtraction if the left operand is greater than the right operand. -DayOfYear: Return the end of the year minus the DayOfYear object. So, instead of a date so many days into the year, it is a date so many days from the end of the year DayOfYear == DayOfYear: Returns boolean DayOfYear < DayOfYear: Returns boolean DayOfYear > DayOfYear: Returns boolean ++DayOfYear: Increments by one day. Returns modified DayOfYear by reference DayOfYear++: Increments by one day. Returns old value of DayOfYear object --DayOfYear and DayOfYear--: Similar implementations to ++DayOfYear and DayOfYear++ <<: Replaces the output() function >>: Replaces the input() function, acceptable inputs should be only of the formats: mm/dd, m/dd, mm/d, m/d DayOfYear[int]: Returns a read-only data member according to the table below In order to ensure all implementations of overloading are attempted, the subtraction operator must be implemented as a non-member, non-friend function

Overloaded [ ] Indices

Index

Returns

1

month

2

day

3

day of year (e.g., February 2 would return 33)

anything else

-1

main.cpp Requirements:

Declare four (4) DayOfYear objects. Be sure to utilize each constructor at least once Perform each arithmetic and comparitive operation as many times as necessary to demonstrate that they work. For example, == should be tested twice, to ensure it can return TRUE when two dates are the same, and false otherwise While performing these operations, test that you roll over into a different month or year the way you should. Rolling over into a different year simply means the day after Dec. 30 is Jan. 1 and vice versa Print dates using << and change the date of all four (4) objects with >>, once for each acceptable date format. Then print the changed dates

Reminders:

Some operators must be implemented as member functions, and some others must be implemented as friend functions Be mindful of your date moving into the next or previous months, and also the rollover for the year as well Place comments only where necessary

Your code should speak for itself Choose good names Comments should be succinct, and placed only where you think an extra explanation is needed (i.e., Dont tell me youre declaring variables. I can see that you are declaring variables; I also know how to code)

* Short comments pointing out where you are fulfilling requirements in your main function are encouraged

Use proper style for your code. If in doubt, refer to the handouts on Blackboard. There is no one right way, but there are lots of wrong ways

Preparing and Submitting:

Your code must be able to compile and run on the EECS Linux Lab servers You are submitting C++ code. Any headers should have the file extension .hpp Your submission must include a makefile Submit ONLY source files and a makefile Design your makefile so that the final executable is called hw01 Program compilation and execution for grading will be conducted in the following manner:

$ make

$ hw01 < infile > outfile

Homework submission will be handled exclusively through the handin tool in the Linux Lab. You may submit your homework using the following command:

~cs411/bin/handin 1 FILE1 FILE2 ...

Extra Credit:

To earn up to 110% on this assignment:

Create the program as described, except use a true 365 day calendar. February should only have 28 days; there is no need to account for a leap year.

Here is what I have from the book.

#include

#include

#include

class DayOfYear {

private:

int month;

int day;

void testDate();

public:

DayOfYear(int month, int day);

DayOfYear(int month);

DayOfYear();

void input();

void output();

int getMonthNumber();

int getDay();

};

const DayOfYear operator +(const DayOfYear& date1, const DayOfYear& date2); //addition

/*

const DayOfYear operator -(const DayOfYear& date1, const DayOfYear& date2); //subtraction

bool operator ==(const DayOfYear& date1, const DayOfYear& date2); //compare

const DayOfYear operator -(const DayOfYear& date1, const DayOfYear date2); //negation

const DayOfYear operator >(const DayOfYear& date1, const DayOfYear date2); //greater

const DayOfYear operator <(const DayOfYear& date1, const DayOfYear date2); //lesser

*/

int main()

{

DayOfYear date_add;

DayOfYear date_subtract;

DayOfYear date_comparison;

DayOfYear date_equality;

date_add.input(); //test

std::cout << date_add.getDay() << std::endl;

system("pause"); //windows pause (comment out for linux)

return 0;

}

DayOfYear::DayOfYear(int month, int day)

{ }

DayOfYear::DayOfYear(int month)

{ }

DayOfYear::DayOfYear()

{ }

void DayOfYear::input()

{

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

std::cin >> month;

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

std::cin >> day;

testDate();

}

void DayOfYear::output()

{

switch (month) {

case 1:

std::cout << "January ";

break;

case 2:

std::cout << "February ";

break;

case 3:

std::cout << "March ";

break;

case 4:

std::cout << "April ";

break;

case 5:

std::cout << "May ";

break;

case 6:

std::cout << "June ";

break;

case 7:

std::cout << "July ";

break;

case 8:

std::cout << "August ";

break;

case 9:

std::cout << "September ";

break;

case 10:

std::cout << "October ";

break;

case 11:

std::cout << "November ";

break;

case 12:

std::cout << "December ";

break;

default:

std::cout << "Error in DayOfYear::output.";

}

std::cout << day;

}

int DayOfYear::getMonthNumber()

{

return month;

}

int DayOfYear::getDay()

{

return day;

}

void DayOfYear::testDate()

{

if (month < 1 || month > 12)

{

std::cout << "Illegal month value! ";

system("pause"); //windows pause for testing (comment out for linux)

exit(1);

}

if (day < 1 || day > 30)

{

std::cout << "Illegal day value! ";

system("pause"); //windows pause for testing (comment out for linux)

exit(1);

}

}

const DayOfYear operator +(const DayOfYear& date1, const DayOfYear& date2) //WIP

{

int total_days = (date1.getMonthNumber()*30) + date2.getDay(); //testing

int var_month = total_days / 30;

int var_day = total_days % 30;

return DayOfYear(var_month, var_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!