Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is what the code should look like in the outcome. 10. Using the classes ext

ID: 639974 • Letter: T

Question

This is what the code should look like in the outcome.

10. Using the classes extDateType and dayType, design the class calenderType so that, given the month and the year, we can print the calender for that month. To print a monthly calender, 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 calender. 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 calenderType has two member variables: an object of the type dayType and an object of the type extDateType.
Design the class calenderType sothat the program can print a calender for any month starting with 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 ass the appropriate days to Monday of January 1, 1500.
For the class calenderType, include the following operations:
a. Determine the first day of the month for which the calender 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 calender for the particular month.
g. Add the appropriate constructors to initialize the member variables.

11a. Write the definitions of the member functions of the class calenderType (designed in Programming Exercise 10) to implement the operations of the class calenderType.
b. Write a test program to print the calender for either a particular month or a particular year. For example the calender for September 2013 is:
Sunday Monday Tuesday Wednesday Thursday Friday Saturday
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 what I have so far

#include

#include "dayType.h"
#include "dateType.h"
#include "extDateType.h"
#include "calendarType.h"

using namespace std;

int main()
{
dateType d(1, 2, 1960);
extDateType ed(6, 10, 1981);
int num;

ed.printLongDate();
cout << endl;
  
ed.print();
cout << endl;

cout << "Days gone in the year: " << ed.numberOfDaysPassed();
cout << endl;

cout << "Days left in the Year: " << ed.numberOfDaysLeft() << endl;

cout << "Enter number of days to be added: ";
cin >> num;
cout << endl;
ed.incrementDate(num);

cout << "After increment date: ";
ed.print();
cout << endl;

//test day object
dayType newDay("Wednesday");

newDay.print();
cout << endl;

cout << "Next Day: " << newDay.nextDay() << endl;

newDay.setDay("Sunday");
cout << "Set Day: ";
newDay.print();
cout << endl;

newDay.prevDay();
cout << "Previous Day: " << newDay.prevDay() << endl;

newDay.addDay(12);
cout << "Add days: ";
newDay.print();
cout << endl;

//test calendar object
calendarType cal(9, 2015);

cal.printCalendar();
   system("pause");
return 0;
}

Explanation / Answer

#include <iostream>

#include <cstdlib>

#include <iomanip>

using namespace std;

bool isLeapYear (int); //good check for leap years

int firstDayofnewyearMonth (int );

int numOfDaysInMonth (int, bool); // takes the number of the month, a flag saying whether year is leap

void printHeader (int); // takes the number of the month, and the first day, prints, and updates

void printMonth (int, int&); // the first day of the next month

void skip (int);// prints the specified amount of spaces

void skipToDay (int);// prints leading spaces in monthly calendar

void disaster (); // terminates program in case of unrecoverable errors

int main ()

{

    system ("color f1 ");

    int year, firstDayInCurrentMonth;

    int currentMonth = 1;

    int numDays;

    bool leap;

    cout << "What year do you want a calendar for? ";

    cin >>year;

    cout<<endl;

    firstDayInCurrentMonth=firstDayofnewyearMonth(year);

    leap = isLeapYear(year);

    skip(9);

    cout << year << endl;

    while (currentMonth <= 12)

    {

    numDays = numOfDaysInMonth(currentMonth, leap);

    printHeader(currentMonth);

    printMonth(numDays, firstDayInCurrentMonth);

    cout << endl << endl << endl;

    currentMonth = currentMonth + 1;

    }

    cout << endl;

}

bool isLeapYear (int year)

{

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

}

int firstDayofnewyearMonth(int year)

{

    int day_start;

    int x1, x2, x3;

    x1 = (year - 1)/ 4;

    x2 = (year - 1)/ 100;

    x3 = (year - 1)/ 400;

    day_start = (year + x1 - x2 + x3) %7;

    return day_start;

}

int numOfDaysInMonth (int m, bool leap)

{

    if (m == 1) return(31);

    else if (m == 2) if (leap) return(29);else return(28);

    else if (m == 3) return(31);

    else if (m == 4) return(30);

    else if (m == 5) return(31);

    else if (m == 6) return(30);

    else if (m == 7) return(31);

    else if (m == 8) return(31);

    else if (m == 9) return(30);

    else if (m == 10) return(31);

    else if (m == 11) return(30);

    else if (m == 12) return(31);

    else disaster();

}

void printHeader (int m)

{

    if (m == 1)

    {

    skip(7);

    cout << "January" << endl;

    }

    else if (m == 2) { skip(7); cout << "February" << endl; }

    else if (m == 3) { skip(7); cout << "March" << endl; }

    else if (m == 4) { skip(7); cout << "April" << endl; }

    else if (m == 5) { skip(7); cout << "May" << endl; }

    else if (m == 6) { skip(7); cout << "June" << endl; }

    else if (m == 7) { skip(7); cout << "July" << endl; }

    else if (m == 8) { skip(7); cout << "August" << endl; }

    else if (m == 9) { skip(7); cout << "September" << endl; }

    else if (m == 10) { skip(7); cout << "October" << endl; }

    else if (m == 11) { skip(7); cout << "November" << endl; }

    else if (m == 12) { skip(7); cout << "December" << endl; }

    else disaster();

    cout << " S M T W T F S" <<endl;

    cout << "____________________" << endl;

}

void skip (int i)

{

    while (i > 0)

    {

    cout << " ";

    i = i - 1;

    }

}

void printMonth (int numDays, int &weekDay)

{

    int day = 1;

    skipToDay(weekDay);

    while (day <= numDays)

    {

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

    if (weekDay == 6)

    {

        cout << endl;

        weekDay = 0;

    }

    else weekDay = weekDay + 1;

    day = day + 1;

    }

}

void skipToDay (int d)

{

    return skip(3*d);

}

void disaster ()

{

    cout << "Disaster! Exiting ..." << endl;

    exit ( -1);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote