See attachment.
Microsoft Word - BCS230_182_homework4.docx BCS 230: Foundations of Computer Programming II CRN 90110, 90111 JL Fall 2018 ----------------------------------------------------------------------------------------------------------------------------------- Homework 4 − Wednesday, October 24 Due Saturday, November 10, 11:59PM on Blackboard ---------------------------------------------------------------------------------------------------------------------------------------------------------- Assignment Goals: To learn to use class inheritance and class composition to create new classes. Assignment: A. (20 points) In Lab 6, you defined and implemented a class called Time. You will make some modifications to the lab 6 program so that it meets the following specifications: The class Time consists of three private member variables of type int: hour, minute, and second. The class Time also includes the following public member functions: 1. print to print the hour, minute, and second in the format of HH-MM-SS. (Hint: consider using output manipulators setw and setfill). 2. setTime to accept three int arguments and use them to set the hour, minute and second member variables. A valid value for hour is between 0 and 23, inclusively. A valid value for minute and second is between 0 and 59. For any invalid values, use 0 instead. 3. getHour to return the value of hour. 4. getMinute to return the value of minute. 5. getSecond to return the value of minute. 6. An equals function that compares two Time objects. Return true if they are equal in hour, minute, and second, otherwise return false. The equals function has a formal parameter which is a Time object. 7. A constructor that accepts three int arguments and use them to initialize hour, minute and second. The three parameters have default value 0. Data validation should be considered. (Hints: Call the setTime member function with 3 arguments.) 8. A copy constructor that creates a Time object by initializing it with an existing Time object. B. (20 points) In Lab 7, you defined and implemented a class called Date. You will make some modification to the lab 7 program so that it meets the following specifications: The class Date consists of three private member variables: year of type int, month of type int, and day of type int. The class Date also includes the following public member functions: 1. print to output the year, month, and day in the format of YYYY-MM-DD. 2. setDate to set the year, month and day according to the parameters. Data validation should be provided. 1) A valid year should be between 1900 and 2020 inclusively, otherwise using 2001 for the year. 2) A valid month should be between 1 and 12 inclusively, otherwise using 1 for the month. 3) A valid day should be between 1 and 28 when the month is 2, i.e., simply assume there are 28 days in February. 1 and 31 when the month is 1, 3, 5, 7, 8, 10, or 12, which means there are 31 days in January, March, May, July, August, October, and December . 1 and 30 when the month is 4, 6, 9, or 11 for April, June, September, and November. Use 1 for any invalid value. 3. getYear to return the year. 4. getMonth to return the month. 5. getDay to return the day. 6. equals to compare two Date objects’ values. Return true if they are the same, otherwise return false. 7. A constructor with default parameters to initialize year, month, and day. The default values for the year, month, and day are 2001, 1, and 1, respectively. 8. A copy constructor to initialize year, month, and day with an existing Date object. C. (40 points) Define a new class called Event using class composition. The class Event consists of four private member variables: string name string location Date date Time time The class Event should also include the following public member functions: 1. print to print the even name, location, date, and time information. 2. setEvent to set the event name, location, date, and time using two string parameters, one Date parameter, and one Time parameter. 3. setEventName to set the event name according to the parameter. 4. getEventName to return the event name. 5. setLocation to set the event location according to the parameter. 6. getLocation to return the event location. 7. setDate to set the event date using a Date object. 8. getDate to return the date, a Date object. 9. setTime to set the event time using a Time object. 10. getTime to return the time, a Time object. 11. equalEventDate to compare two events’ dates. Return true if they are the same, otherwise, return false. 12. A default constructor to initialize name and location to “None”. (The default constructor of Date and Time will be automatically invoked.) 13. An overloaded constructor that initializes name, location, date, and time according to the parameters (two string parameters, one Date parameter, and one Time parameter). D. (20 points) In the client program, you should write statements to test your class implementation including the following functions in the Event class: default constructor, overloaded constructor, mutator functions, accessor functions, and print and equalEventDate function. You can use the following sample data for the events, as well as other data at your preference. Event Name Location Date Time BCS230 Exam 2 Whitman 215 2018/10/31 10:50 Make-up Day N/A 2018/12/14 12:15 Graduation Commencement Nold Athletic Complex 2019/01/16 9:30 Submission: You should submit a ZIP file that contains seven files on the following names: Time.h Time.cpp Date.h Date.cpp Event.h Event.cpp hw4main.cpp. Do NOT use any other file names. Be sure to include the integrity statement “I certify that this submission is my own original work” with your name and RAM ID in each source file. Extra credits (20 points): Save the following data in a text file hw4data.txt. In the client program, use loops to read data from this file, create Event objects accordingly, and output the event information in a well-aligned format. BCS230 Final Exam:Whitman 209:2018:5:14:10:30:00 Make-up Day:N/A:2017:05:12:12:15:00 Graduation Commencement:Nold Athletic Complex:2016:5:20:9:30:00 Doctor Appointment:Doctor’s Office:2015:06:01:11:00:00 Note, the character‘:’ is a delimiter.