Pledge: You may on this pledged assignment work in groups of two or three. Your partners must be from your same lab section. If you violate the section rule, your grade on the assignment will be cut in half. Your group may discuss the content of this assignment and your approach with anyone, but your group must do all if its own work. The group must create the logic of the solution, type the code, and compile, execute, and debug its own program. Your group may not use any code developed by anyone else. Your group's source code submitted electronically must match exactly the code you deliver in your lab section. Only one member of the group should submit the program electronically and only one printed copy should be handed in. The header comment section of your program should identify all members of the group. A person cannot be added to a group retroactively. So make sure your name is listed as part of your group's submission.
There have been several files created for you. The files are available individually or as a bundle.
class Date { public: // default constructor: creates day of form month/day/year Date(int month = 9, int day = 14, int year = 1752); // inspector getMonth(): returns the month associated with the date int getMonth() const; // inspector getDay(): returns the day associated with the date int getDay() const; // inspector getYear(): returns the year associated with the date int getYear() const; // mutator setMonth(): sets the month associated with the date, if // an invalid month is requested, an error message is generated and // 1 is used. void setMonth(int month); // mutator setDay(): sets the day associated with the date, if // an invalid day is requested, an error message is generated and // 1 is used void setDay(int day); // mutator setYear): sets the year associated with the date, if // an invalid year is requested, an error message is generated and // 2000 is used void setYear(int year); // mutator extract(): sets the date using the representation extracted // from input stream sin. The representation has form month/day/year. // If an invalid month, day, or year is supplied, an error message is // generated and a valid date is set. void extract(istream &sin); // operator ++: changes the representation of the invoking object to // the immediately successive date. The invoking object is returned. Date& operator ++ (void); // operator ==: returns true if the source represents the date as the // invoking object bool operator == (const Date& source) const; // facilitator insert(): displays a representation of the date to // stream sout. The representation has form month/day/year. void insert(ostream &sout) const; private: int thisMonth; // represents the month of our date int thisDay; // represents the day of our date int thisYear; // represents the year of our date };
In addition, you will find several auxiliary operator function prototypes in date.h
// operator >>: extracts a date of form month/day/year from sin and assigns // it to target. The operator is supplied as a client courtesy, The operator // makes use of date member function extract istream& operator >> (istream &sin, Date &target); // operator <<: inserts the date to sout with form month/day/year. The // operator is supplied as a client courtesy, The operator makes use of // date member function insert ostream& operator << (ostream &sout, const Date &source); // operator +: returns the date that is nbrDays days after dateOfInterest, // where nbrDays is at least 0 Date operator + (const Date &dateOfInterest, int nbrDays); // isLeapYear(): returns true if y is a leap year; otherwise, returns // false bool isLeapYear(int y);
Your assignment is implement the following Date member functions. Your implementation should be done in the file mydate.cpp
void setMonth(int month); void setDay(int day); void setYear(int year); void extract(istream &sin); Date& operator ++ (); bool operator == (const Date& source) const;You are to also implement the Date auxiliary function
bool isLeapYear(int y);For extra credit you can implement the Date auxiliary operator
Date operator + (const Date &dateOfInterest, int nbrDays);
#include "date.h" int main() { Date gregorianStart; Date finalExam(5, 9, 2001); Date leapYear(2, 29, 2000); Date piDay(3, 14, 1592); Date myBirthdate(4, 30, 1954); cout << "Start of the Gregorian calendar: " << gregorianStart << endl; cout << "The day of our final exam: " << finalExam << endl; cout << "Pi day: " << piDay << endl; cout << "My birthrate: " << myBirthdate << endl << endl; cout << "Please enter your birth date: "; Date birthdate; cin >> birthdate; cout << "Your birth date: " << birthdate << endl << endl; Date d(12, 30, 2000); ++d; // 12/31/200 ++d; // 1/1/2001 Date endDate(1, 1, 2001); cout << d << " and " << endDate; if (d == endDate) { cout << " are the same." << endl << endl; } else { cout << " are different" << endl << endl; } d = d + 31; // 2/1/2001 cout << d << endl << endl; d = d + 28; // 3/1/2001 cout << d << endl << endl; d = Date(2, 28, 2000); ++d; // 2/29/2000 cout << d << endl << endl; d = Date(2, 28, 1900); ++d; // 3/1/1900 cout << d << endl << endl; d = Date(2, 28, 1980); ++d; // 2/29/1980 cout << d << endl << endl; d = Date(2, 28, 2001); ++d; // 3/1/2001 cout << d << endl << endl; d = Date(11, 29, 1985); cout << "Enter a day: "; cin >> d; cout << d << endl << endl; return 0; }