Using the classes extDateType Programming Exercise 8 and day

Using the classes extDateType (Programming Exercise 8) and dayType (Chapter 10, Programming Exercise 5), 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 of 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. Design the class calendarType so that the program can print a calendar for any month starting January 1, 1500. Note that the day for 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.
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.

Solution

#include<iostream.h>

#include<string.h>

#include<conio.h>

#include<iomanip.h>

class Calendar

{

private:

                int month;

                int year;

                int firstday;

public:

                Calendar(int =11, int =2011);

                void setFirstDay();

                void print();

};

Calendar :: Calendar (int _month, int _year){

                month = _month;

                year = _year;

}

void Calendar :: setFirstDay(){

                int day=1;

                int y = year - (14-month)/12;

                int m = month +12 * ((14-month) / 12) -2;

                firstday= (day + y + y / 4 - y / 100 + y / 400 + (31 * m / 12)) % 7;

}

void Calendar :: print(){

                int NumberOfDaysInMonth;

                int FirstDayOfMonth = 0;

                int DayOfWeekCounter = 0;

                int DateCounter = 1;

                switch (month)

                {

                case 1:

                                cout<<setw(21)<<\"January \"<<year;

                                NumberOfDaysInMonth = 31;

                break;

                case 2:

                                cout<<setw(21)<<\"February \"<<year;

                                if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))

                                NumberOfDaysInMonth = 29;

                                else

                                NumberOfDaysInMonth = 28;

                break;

                case 3:

                                cout<<setw(21)<<\"March \"<<year;

                                NumberOfDaysInMonth = 31;

                break;

                case 4:

                                cout<<setw(21)<<\"April \"<<year;

                                NumberOfDaysInMonth = 30;

                break;

                case 5:

                                cout<<setw(21)<<\"May \"<<year;

                                NumberOfDaysInMonth = 31;

                break;

                case 6:

                                cout<<setw(21)<<\"June \"<<year;

                                NumberOfDaysInMonth = 30;

                break;

                case 7:

                                cout<<setw(21)<<\"July \"<<year;

                                NumberOfDaysInMonth = 31;

                break;

                case 8:

                                cout<<setw(21)<<\"August \"<<year;

                                NumberOfDaysInMonth = 31;

                break;

                case 9:

                                cout<<setw(21)<<\"September \"<<year;

                                NumberOfDaysInMonth = 30;

                break;

                case 10:

                                cout<<setw(21)<<\"October \"<<year;

                                NumberOfDaysInMonth = 31;

                break;

                case 11:

                                cout<<setw(21)<<\"November \"<<year;

                                NumberOfDaysInMonth = 30;

                break;

                case 12:

                                cout<<setw(21)<<\"December \"<<year;

                                NumberOfDaysInMonth = 31;

                break;

                }

                cout<<\"\ Sun   Mon   Tue   Wed   Thu   Fri   Sat\";

                cout<<\"\ \ \"<<setw(2);

                for (FirstDayOfMonth; FirstDayOfMonth < firstday; ++FirstDayOfMonth)

                {

                                cout<<setw(14);

                }

                int tempfirstday=firstday;

                DateCounter = 1;

                DayOfWeekCounter = tempfirstday;

                for (DateCounter; DateCounter <= NumberOfDaysInMonth; ++DateCounter)

                {

                                cout<<DateCounter<<setw(6);

                                ++DayOfWeekCounter;

                                if (DayOfWeekCounter > 6)

                                {

                                                cout<<\"\ \ \"<<setw(2);

                                                DayOfWeekCounter = 0;

                                }

                }

                cout << \" \ \" ;

                tempfirstday = DayOfWeekCounter + 1;

}

void main()   

{

                Calendar c;

                clrscr();

                c.setFirstDay();

                c.print();

                getch();

}

Using the classes extDateType (Programming Exercise 8) and dayType (Chapter 10, Programming Exercise 5), design the class calendarType so that, given the month
Using the classes extDateType (Programming Exercise 8) and dayType (Chapter 10, Programming Exercise 5), design the class calendarType so that, given the month
Using the classes extDateType (Programming Exercise 8) and dayType (Chapter 10, Programming Exercise 5), design the class calendarType so that, given the month
Using the classes extDateType (Programming Exercise 8) and dayType (Chapter 10, Programming Exercise 5), design the class calendarType so that, given the month

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site