Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ homework help: Assignment info: 1. In this chapter, the class dateType was designed to implement the date in a program, but the member function

C++ homework help:

Assignment info:

1. In this chapter, the class dateType was designed to implement the date in a program, but the member function setDate and the constructor do not check whether the date is valid before storing the date in the member variables. Rewrite the definitions of the function setDate and the constructor so that the values for the month, day, and year are checked before storing the date into the member variables.

2. Add a member function, isLeapYear, to check whether a year is a leap year. Moreover, write a test program to test your class.

3. The class dateType was designed and implemented to keep track of a date, but it has very limited operations. Redefine the class dateType so that it can perform the following operations on a date, in addition to the operations already defined:

a. Set the month.

b. Set the day.

c. Set the year.

d. Return the month.

e. Return the day.

f. Return the year.

g. Test whether the year is a leap year.

h. Return the number of days in the month. For example, if the date is 3-12-2017, the number of days to be returned is 31 because there are 31 days in March.

i. Return the number of days passed in the year. For example, if the date is 3-18-2017, the number of days passed in the year is 77. Note that the number of days returned also includes the current day.

j. Return the number of days remaining in the year. For example, if the date is 3-18-2017, the number of days remaining in the year is 288.

k. Calculate the new date by adding a fixed number of days to the date. For example, if the date is 3-18-2017 and the days to be added are 25, the new date is 4-12-2017.

4. Write the definitions of the functions to implement the operations defined for the latest version of the class dateType.

5. The class dateType prints the date in numerical form. Some applications might require the date to be printed in another form, such as March 24, 2017.

a. Derive the class extDateType so that the date can be printed in either form.

b. Add a member variable to the class extDateType so that the month can also be stored in string form.

c. Add a member function to output the month in the string format, followed by the yearfor example, in the form March 2017.

d. Write the definitions of the functions to implement the operations for the class extDateType.

e. Using the classes extDateType and dayType, design the class calendarType so that, given the month and the year, we can print the calendar for that month. To print a monthly calendar, you must know the first day of the month and the number of days in that month. Thus, you must store the first day of the month, which is the form dayType, and the month and the year of the calendar. Clearly, the month and the year can be stored in an object of the form extDateType by setting the day component of the date to 1 and the month and year as specified by the user. Thus, the class calendarType has two member variables: an object of the type dayType and an object of the type extDateType.

f. Design the class calendarType so that the program can print a calendar for any month starting January 1, 1500. Note that the day of January 1 of the year 1500 is a Monday. To calculate the first day of a month, you can add the appropriate days to Monday of January 1, 1500.

6. For the class calendarType, include the following operations:

a. Determine the first day of the month for which the calendar will be printed. Call this operation firstDayOfMonth.

b. Set the month.

c. Set the year.

d. Return the month.

e. Return the year.

f. Print the calendar for the particular month.

g. Add the appropriate constructors to initialize the member variables.

7. Write the definitions of the member functions of the class to implement the operations of the class calendarType.

8. Write a test program to print the calendar for either a particular month or a particular year. For example, the calendar for September 2017 is: September 2017

Sun Mon Tue Wed Thu Fri Sat 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

Here is the file I need to modify

class dateType { public: void setDate(int month, int day, int year); //Function to set the date. //The member variables dMonth, dDay, and dYear are set //according to the parameters. //Postcondition: dMonth = month; dDay = day; // dYear = year int getDay() const; //Function to return the day. //Postcondition: The value of dDay is returned. int getMonth() const; //Function to return the month. //Postcondition: The value of dMonth is returned. int getYear() const; //Function to return the year. //Postcondition: The value of dYear is returned. void printDate() const; //Function to output the date in the form mm-dd-yyyy. dateType(int month = 1, int day = 1, int year = 1900); //Constructor to set the date //The member variables dMonth, dDay, and dYear are set //according to the parameters. //Postcondition: dMonth = month; dDay = day; dYear = year; // If no values are specified, the default // values are used to initialize the member // variables. private: int dMonth; //variable to store the month int dDay; //variable to store the day int dYear; //variable to store the year }; #endif 

This is the implementation file

//Implementation file date #include  #include "dateType.h" using namespace std; void dateType::setDate(int month, int day, int year) { dMonth = month; dDay = day; dYear = year; } int dateType::getDay() const { return dDay; } int dateType::getMonth() const { return dMonth; } int dateType::getYear() const { return dYear; } void dateType::printDate() const { cout << dMonth << "-" << dDay << "-" << dYear; } //Constructor with parameters dateType::dateType(int month, int day, int year) { dMonth = month; dDay = day; dYear = year; } 
class dateType { public: void setDate(int month, int day, int year); //Function to set the date. //The member variables dMonth, dDay, and dYear are set //according to the parameters. //Postcondition: dMonth = month; dDay = day; // dYear = year int getDay() const; //Function to return the day. //Postcondition: The value of dDay is returned. int getMonth() const; //Function to return the month. //Postcondition: The value of dMonth is returned. int getYear() const; //Function to return the year. //Postcondition: The value of dYear is returned. void printDate() const; //Function to output the date in the form mm-dd-yyyy. dateType(int month = 1, int day = 1, int year = 1900); //Constructor to set the date //The member variables dMonth, dDay, and dYear are set //according to the parameters. //Postcondition: dMonth = month; dDay = day; dYear = year; // If no values are specified, the default // values are used to initialize the member // variables. private: int dMonth; //variable to store the month int dDay; //variable to store the day int dYear; //variable to store the year }; #endif 

This is the implementation file

//Implementation file date #include  #include "dateType.h" using namespace std; void dateType::setDate(int month, int day, int year) { dMonth = month; dDay = day; dYear = year; } int dateType::getDay() const { return dDay; } int dateType::getMonth() const { return dMonth; } int dateType::getYear() const { return dYear; } void dateType::printDate() const { cout << dMonth << "-" << dDay << "-" << dYear; } //Constructor with parameters dateType::dateType(int month, int day, int year) { dMonth = month; dDay = day; dYear = year; } 

I need the mainprogram.cpp and edit the header file and the implementation file

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 15th International Conference Dexa 2004 Zaragoza Spain August 30 September 3 2004 Proceedings Lncs 3180

Authors: Fernando Galindo ,Makoto Takizawa ,Roland Traunmuller

2004th Edition

3540229361, 978-3540229360

More Books

Students also viewed these Databases questions

Question

List five functional areas and their sub-functions.

Answered: 1 week ago