The second part of the Calendar Program project (the first part being the struct
ID: 3791816 • Letter: T
Question
The second part of the Calendar Program project (the first part being the structure part due earlier) is to write the pseudocode for two functions: computeOffset() and displayTable().
Compute Offset
Write the pseudocode for the function computeOffset(). This function will determine the day of the week of the first day of the month by counting how many days have passed since the 1st of January, 1753 (which is a Monday and offset == 0). That number (numDays) divided by 7 will tell us how many weeks have passed. The remainder will tell us the offset from Monday. For example, if the month begins on a Thursday, then offset == 3. The prototype for the function is:
int computeOffset(int month, int year);
Please do not plagiarize this from the internet; you must use a loop to solve the problem.
The output for this function is the following:
You might want to test your algorithm (and get ahead on the next installment of the project) by also writing the code in C++ and testing it with a driver program. For example, we know that the January 1st 1753 is a Monday. Therefore, your driver program should output:
The second is the 1st of August, 2001 which is a Wednesday.
Display Table
Write the pseudocode for the function displayTable(). This function will take the number of days in a month (numDays) and the offset (offset) as parameters and will display the calendar table. For example, consider numDays == 30 and offset == 3. The output would be:
There are two problems you must solve: how to put the spaces before the first day of the month, and how to put the newline character at the end of the week. The prototype of the function is:
void displayTable(int offset, int numDays);
Day offset Sunday 6 Monday 0 Tuesday 1 Wednesday 2 Thursday 3 Friday 4 Saturday 5Explanation / Answer
As the year 1753 is our marked year where offset was 0 we will do all the calculation based on this.
and for a displayTable function, we need offset.
oid displayTable(int offset, int numDays)
{
// Variable
int days;
if (offset == 0) // Mon
cout << setw(4) << " ";
else if (offset == 1) // Tues
cout << setw(8) << " ";
else if (offset == 2) // Wed
cout << setw(12) << " ";
else if (offset == 3) // Thurs
cout << setw(16) << " ";
else if (offset == 4) // Fri
cout << setw(20) << " ";
else if (offset == 5) // Sat
cout << setw(24) << " ";
else (offset == 6) // Sun
{}
for (days = 1; days <= numDays; days++)
{
cout << " " << setw(2) << days;
if ((days + offset) % 7 == 0)
cout << " ";
}
cout << endl;
return;
}
int computeOffset(int month, int year)