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

In this program, you will store a calendar month of dates (numbers starting at 1

ID: 3694108 • Letter: I

Question

In this program, you will store a calendar month of dates (numbers starting at 1) in a two-dimensional array. Some months have 31 days, others 30, and February has 28 (29 if it’s a leap year, which is a year divisible by 4). Here is a list of Months, the number of Days in each month, and the Day on which each Month Starts, in 2016, 2017, 2018, and 2019: Day on which Month Starts Months Days 2016 2017 2018 2019 January 31 Friday Sunday Monday Tuesday February 28* Monday Wednesday Thursday Friday March 31 Tuesday Wednesday Thursday Friday April 30 Friday Saturday Sunday Monday May 31 Sunday Monday Tuesday Wednesday June 30 Wednesday Thursday Friday Saturday July 31 Friday Saturday Sunday Monday August 31 Monday Tuesday Wednesday Thursday September 30 Thursday Friday Saturday Sunday October 31 Saturday Sunday Monday Tuesday November 30 Tuesday Wednesday Thursday Friday December 31 Thursday Friday Saturday Sunday *except leap year Given a month name, the name of the starting day of the week, and the year, write a program to store the date (number) of each day in the corresponding array location. Use a two-dimensional array called month of type int to store the generated month dates. 1. Declare month to be an array of type int of the proper size and dimensions (weeks and days), and initialize all elements to 0. 2. Handle user input as follows: a. Ask the user for the month name, and match it to the appropriate number of days (hint: use parallel arrays) b. If the month is February, you need to know the year, and test if it is a leap year to adjust February’s number of days, if needed. c. Ask the user which day of the week the month starts on, and match it to the proper day number (Sunday being day 1), to determine which position in the two-dimensional array to start storing dates (hint: use parallel arrays) 3. Use formatted output to display the month left-aligned, omitting “0” dates (see the output example below) 4. Use functions if desired. Allow your main program to loop, allowing the user to ask for an unlimited number of months. In C++. HELP

Explanation / Answer

Program:

#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace std;
bool isLeapYear (int);
int firstDayofnewyearMonth (int );
int numOfDaysInMonth (int, bool);
void printHeader (int);
void printMonth (int, int&);
void skip (int);
void skipToDay (int);
void disaster ();
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