Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The passage of time is measures in days, months, and years. In this assignment we are going to define a class Date to represent a

The passage of time is measures in days, months, and years. In this assignment we are going to define a class Date to represent a calendar date.All Date objects have the following data members:
month (an integer value between 1 and 12)
day (an integer value between 1 and 31)
year (a four-digit, non-negative integer)
For this class provide:
a constructor:
parameters for the constructor must be provided in the following order: month, day, and year.
use the default values technique so that if no data is provided for month, day, year the date is set to January 1,1900.
inspectors/getters/accessors for all the data members. Use the get convention to name your getters.
a mutator/setter changeDate:
this setter modifies the Date object by adding a given amount of days.
this setter takes one parameter which is an integer that represents the number of days to add to a Date object.
You must be careful and make sure the resulting Date remains in the valid range. For example if you add 2 days to 01/31/2024 the resulting date should be 02/02/2024; and if you add 15 to 12/31/2024 the resulting date should be 01/15/2025
Note: Remember that January, March, May, July, August, October and December have 31 days. Assume February has always 28 days. April, June, September, and November have 30 days.
Hint: You will need to use loops and if statements for this method. You are not allowed to use the datetime module or any other materials not specifically covered in cS 171/ CS 172.
Then proceed to overload the following operators:
The __str__ special method, so the print function can be used with this class.
This method should return a Date object as a string in the format mm/dd/yyyy (for example 01/31/2024)
The comparison operators: ==,!=,<,<=,> and >=
These operators will allow us to compare two Date objects.
Note: a Date object is greater than another Date object if it's a later date. For example: 07/01/2024 is greater than 01/23/2024. Likewise 07/01/2024 is greater than 07/01/2020
The subscript operator ([]), as an accessor.
Accessing position 0 returns the value of the month data member.
Accessing position 1 returns the value of the day data member.
Accessing position 2 returns the value of the year data member.
For any other index value, raise an exception ("Index out of Bounds").
The code for the Date class should be saved in the date.py file.
In the main.py file you will have the main script for this assignment.
You must write a main script to make sure that your class and associated methods and operators work correctly.
At the very minimum you are expected to
create a few Date objects with the user providing data for the data members.
your main script should not accept invalid date for Date objects. For example 02/31/2009 is an invalid date because February only has 28 days.
for your convenience the module inputroutines.py is being provided to help with input validation.
demonstrate that all the getter and setter methods work correctly/
demonstrate that each one of the overloaded operators work:
You should explicitly compare two Date objects using the ==!=<<=>>=operators.
You should explicitly use the print() function to display a Date object.
You should explicitly use the subscript operator [] with a Date object to access each of the object data members.
Notes:
The purpose of this problem is to practice creating classes and operator overloading.
Please make sure to submit a well-written program. Good identifier names, useful comments, and spacing will be some of the criteria that will be used when grading this assignment.
You must use attribute mangling.
This assignment can be and must be solved using only the materials that have been discussed in class. Do not look for alternative methods that have not been covered as part of this course.
!!!!!You are not allowed to use the datetime module or any other materials not specifically covered in cS 171/ CS 172.!!!!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

3319234609, 978-3319234601

More Books

Students also viewed these Databases questions

Question

million households).

Answered: 1 week ago