UE CS 215 - CS 215 ­ Fundamentals of Programming II

Unformatted text preview:

CS 215 - Fundamentals of Programming II Fall 2008 - Programming Project 1 20 pointsOut: September 10, 2008 Due: September 17, 2008Reminder: Programming Projects (as opposed to Homework problems) are to be your own work. See syllabus for definitions of acceptable assistance from others.The instructor’s format for class specifications is defined in the last section of the on-line handouts An Analysis and Design Style Guideline and An Analysis and Design Style Guideline for Classes (It is used by the instructor in CS 210.) A link to this handout also is provided on the CS 215 home page.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, 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 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, 2008 for initialMonth, initialDay, and initialYear (i.e., January 1, 2008) Precondition: Initial values must meet class invariant above. Throws RangeError exception with a suitable error message if not met.09/08/08 1 of 5Analysis Objects Type Kind Movement Nameinitial month int variable received initialMonthinitial day int variable received initialDayinitial year int variable received initialYear● GetMonth - Returns month of date Analysis Objects Type Kind Movement Namemonth of date int variable returned myMonth● GetDay - Returns day of date Analysis Objects Type Kind Movement Nameday of date int variable returned myDay● GetYear - Returns year of date Analysis Objects Type Kind Movement Nameyear of date int variable returned myYear● StringName - Returns the written out equivalent of the date as a string, e.g. "January 1, 2008" for 1/1/2008. Hint: you should use an ostringstream to do this. Analysis Objects Type Kind Movement Namestring name of date string variable 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 † From Nyhoff, C++: An Introduction to Data Structures, Prentice-Hall, Inc. 1999, Problem 47 on page 167.09/08/08 2 of 5February being counted as months 11 and 12 of the previous year. b = The day of the month c = 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 Kind Movement Namestring name of day of the week string variable returned -----● operator== - friend overloaded operator, returns true if the two date objects represent the same date Analysis Objects Type Kind Movement Namea date Date variable received lhsanother date Date variable received rhsresult of comparison bool variable returned -----● operator< - friend overloaded operator, returns true if the left-hand side date is earlier than the right-hand side date Analysis Objects Type Kind Movement Namea date Date variable received lhsanother date Date variable received rhsresult of comparison bool variable 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 09/08/08 3 of 5attributes. Must check that the input meets the class invariant above. If not met the date object is unchanged and a RangeError exception is thrown with a suitable error message.Analysis Objects Type Kind Movement Nameinput stream istream variable received, passed back, and returned indate object Date variable 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 Kind Movement Nameoutput stream ostream variable received, passed back, and returned outdate object Date variable received aDateAssignmentWrite the implementation for this Date class. Note that the function names for this class must be as specified above. 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.Write a main program that adequately tests your Date class in file datedriver.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.The file except.h with the RangeError exception class definition is available from csserver in directory /home/hwang/cs215/lecture06 and on the course website under September 8. You can copy the file by changing directories to where you want to put it and typing: cp /home/hwang/cs215/lecture06/except.h .(The last ‘.’ indicates the current directory.) You should not modify this file.You must submit a makefile named Makefile.project1 for your project that creates an executable file named datedriver. Submissions without working makefiles will be assessed up to a 3-point penalty as indicated


View Full Document

UE CS 215 - CS 215 ­ Fundamentals of Programming II

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 CS 215 ­ Fundamentals of Programming II
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 CS 215 ­ Fundamentals of Programming II 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 CS 215 ­ Fundamentals of Programming II 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?