Homework Assignment 6

Total Page:16

File Type:pdf, Size:1020Kb

Homework Assignment 6

ENGR 221 Homework Assignment 6 Fall Semester 2007 Due Tuesday, October 23, 2007

Write a program, hwk6.cpp, in which you define a C++ class called Date with private integer members month, day, and year. Define 2 constructors for the class, one which does not require input arguments and initializes the date to 1/1/2000; the other which accepts input integer arguments m, d, and y. Also define the following public member functions of the class:

1. void Date::input_date(void) This function accepts input for month, day, and year.

2. void Date::print_date(void) This function converts the integer month to a character string and prints complete date, e. g., November 15, 1927. Implement with cout rather than printf command.

3. int Date::getMonth(void) This function returns the month.

4. int Date::getDay(void) This function returns the day.

5. int Date::getYear(void) This function returns the year.

Within main() instantiate objects date1 and date2. For date1 use the constructor that does not accept input arguments; for date2 use the one that does and initialize it to 10/23/2007. Using the cout object, print out each date using the integer month, day, and year values separated by slashes. Then for the object date1, invoke the input_date function to allow the user to change the date. Then invoke the print_date function to print its new date. The output should have the form: date1: 1/1/2000 date2: 10/23/2007 date1: Enter month, day, and year (e.g. 3 1 1999) separated by spaces: 12 6 1927 date1: December 6, 1927

Save your program as hwk6.cpp in your homework directory. Include your name and hwk6.cpp in comment lines at the top. Print out a copy of the program with sample output appended. Turn this in for grading. Remember to use g++ to compile your program. Email a completed copy of your program to both the instructor and the grader prior to the start of class on the due date. In the subject line of this email, type ENGR 221 hwk6.cpp. Send it as an attachment from your IPFW webmail account, which can be accessed through https://my.ipfw.edu/. If you are working from home or a campus lab other than the engineering labs, you can access the file by logging into http://students.etcs.ipfw.edu and transferring it from your homework directory to the local computer. Once the file is on the local computer, you can attach it to an email. In class, turn in a hardcopy of the program with your results appended at the bottom. Make sure the version you email does not have these appended results because it will not compile.

Grading:

Class date properly implemented 4 pts. Results accurate and according to instructions 2 pts. Proper use of cout 2 pts. Style, comments, and proper subject line in email 2 pts. 10 pts.

Recommended publications