DOC PREVIEW
UE CS 215 - Programming Project 2

This preview shows page 1-2 out of 6 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS 215 - Fundamentals of Programming II Fall 2010 - Programming Project 2 20 pointsOut: September 15, 2010Due: September 22, 2010 (Wednesday)Reminder: Programming Projects (as opposed to Homework problems) are to be your own work. See syllabus for definitions of acceptable assistance from others.Consider the following specification for a Date class that models a calendar date in the Common Era. The analysis of each operation is given formally and the parameters must be declared in the order specified, but the design of each operation is given informally in English.Specification for Date ClassData Attributes:Objects Type Namemonth of the date int myMonthday of the date int myDayyear of the date int myYearThe class invariant (I.e., all valid objects must meet this condition):● month is 1 to 12 ● day is 1 to 31 for January, March, May, July, August, October, and December; 1 to 30 for April, June, September, and November; 1 to 28 for February in a non-leap year; and 1 to 29 for February in a leap year ● year is greater than 0 For those who do not recall the definition of a leap year, it is any year that is divisible by 4 but not by 100, or is divisible by 400. For example, 2008 is a leap year, 1900 is not a leap year, and 2000 is a leap year.Operations● Explicit-value constructor - initialize attributes from passed values Must have default argument values of 1, 1, 2010 for initialMonth, initialDay, and initialYear (i.e., January 1, 2010) - there is no default constructor for this class.Precondition: Initial values must meet class invariant above. The assert function (in <cassert>) should be used to ensure this.Analysis Revised: 09/19/2010 1 of 6 D. HwangObjects Type Movement Nameinitial month int received initialMonthinitial day int received initialDayinitial year int received initialYear● GetMonth - Returns month of date Analysis Objects Type Movement Namemonth of date int returned myMonth● GetDay - Returns day of date Analysis Objects Type Movement Nameday of date int returned myDay● GetYear - Returns year of date Analysis Objects Type Movement Nameyear of date int returned myYear● StringName - Returns the written out equivalent of the date as a string, e.g. "January 1, 2010" for 1/1/2010. Hint: you should use an ostringstream to do this. See design notes below.Analysis Objects Type Movement Namestring name of date string returned -----● DayOfWeek - Returns the string name of the day of the week the date represents according to the following formula.† Let a, b, c, and d be integers defined as follows: a = The number of the month of the year, with March = 1, April = 2, and so on, with January and February being counted as months 11 and 12 of the previous year. b = The day of the month † From Nyhoff, C++: An Introduction to Data Structures, Prentice-Hall, Inc. 1999, Problem 47 on page 167.Revised: 09/19/2010 2 of 6 D. Hwangc = The year of the century d = The century For example, July 31, 1929 gives a = 5, b = 31, c = 29, d = 19; January 3, 1988 gives a = 11, b = 3, c = 87, d = 19. Now calculate the following integer quantities: w = The integer quotient of (13a -1) / 5 x = The integer quotient of c / 4 y = The integer quotient of d / 4 z = w + x + y + b + c - 2d r = z reduced modulo 7, that is, r = z % 7 (except that the C++ % operator sometimes returns a negative number; if this happens, add 7 to the result), r = 0 represents Sunday, r = 1 represents Monday, and so on. Analysis Objects Type Movement Namestring name of day of the week string returned -----● operator== - friend overloaded operator, returns true if the two date objects represent the same date Analysis Objects Type Movement Namea date Date received lhsanother date Date received rhsresult of comparison bool returned -----● operator< - friend overloaded operator, returns true if the left-hand side date is earlier than the right-hand side date Analysis Objects Type Movement Namea date Date received lhsanother date Date received rhsresult of comparison bool returned -----● operator>> - friend overloaded operator function that reads date values from an input stream without prompting in format "MM/DD/YYYY'" (month and day may be a single digit) and store in the attributes. Must check that the input meets the class invariant above. If not met the date object is Revised: 09/19/2010 3 of 6 D. Hwangunchanged and the input stream should be put in the failed state and returned. Also, if the input stream fails for any reason, is should just be return. See design notes below.Analysis Objects Type Movement Nameinput stream istreamreceived, passed back, and returnedindate object Date passed back aDate● operator<< - friend overloaded operator function that prints date attributes to an output stream in format "MM/DD/YYYY", single digit month and day are allowed. Analysis Objects Type Movement Nameoutput stream ostreamreceived, passed back, and returnedoutdate object Date received aDateAssignmentWrite the implementation for this Date class. Note that all public names (the class operation names) must be as specified above including capitalization. The Date class definition and friend operator function prototypes should be put in header file date.h with suitable compilation guards. The implementations of the Date class and friend operator functions should be put in source file date.cpp. Both should be put into namespace Project2.Write a main program that adequately tests your Date class in file project2.cpp. This program should demonstrate that your Date class meets all of the specifications given above. Part of your grade will depend on how well you test your class. In addition, the submission system will run a specific driver program to test your Date class.You must submit a makefile named Makefile.project2 for your project that creates an executable file named project2. It should conform to the examples demonstrated in class.REMINDER: Your project must compile for it to be graded. Submissions that do not compile will be returned for resubmission and assessed a late penalty. Submissions that do not substantially work also will be returned for resubmission and assessed a late penalty.Follow the guidelines in the C++ Programming Style Guideline handout. As stated in the syllabus, part of the grade on a programming project depends on how well you adhere to the guidelines. The grader will look at your code listing and grade it according to the guidelines.Revised: 09/19/2010 4 of 6 D.


View Full Document

UE CS 215 - Programming Project 2

Documents in this Course
Lecture 4

Lecture 4

14 pages

Lecture 5

Lecture 5

18 pages

Lecture 6

Lecture 6

17 pages

Lecture 7

Lecture 7

28 pages

Lecture 1

Lecture 1

16 pages

Lecture 5

Lecture 5

15 pages

Lecture 7

Lecture 7

28 pages

Load more
Download Programming Project 2
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Programming Project 2 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Programming Project 2 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?