Write a program that, given a month and year, prints a calendar, such as June 2016 Su Mo Tu We Th Fr Sa XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX You should create at least two functions:...

1 answer below »

Write a program that, given a month and year, prints a calendar, such as



June 2016
Su Mo Tu We Th Fr Sa
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


You should create at least two functions:


1) int JulianDayDate(int month, int day, int year)

This function should return the day of the week, given a date. Here is one algorithm to do this given a Julian date:



JMD = (day + ((153 * (month + 12 * ((14 - month) / 12) - 3) + 2) / 5) +
(365 * (year + 4800 - ((14 - month) / 12))) +
((year + 4800 - ((14 - month) / 12)) / 4) -
((year + 4800 - ((14 - month) / 12)) / 100) +
((year + 4800 - ((14 - month) / 12)) / 400) - 32045) % 7;
This formula returns an index of the day of the week. // 0 = Monday, 1 = Tuesday, ..., 6 = Sunday

You can use the above to find out the weekday of the first day of the month for your calendar.


2) Next, you should create your own function to return the number of days in the month that you need to print. Your function should correctly handle leap years. Make sure your test output shows the various possible outputs, month lengths of 28,29,30,31.


int getDaysInMonth(int month, int year)

Hints:



  • Use helper methods to print the header and to print each row will make your code easier to understand and debug.

  • Each row except the header will have 20 characters.

  • You may want to also create a method that calculates the number of leading spaces before the first date of the month to make your code more modular.


Submission Instructions:




  • Submit C++ source code files that solve the defined problem.


  • Submit a screenshot of your test output including all test cases. You should validate your date inputs.

Answered Same DaySep 18, 2021

Answer To: Write a program that, given a month and year, prints a calendar, such as June 2016 Su Mo Tu We Th Fr...

Umakant answered on Sep 22 2021
147 Votes
Screenshots1/1.JPG
Screenshots1/2..JPG
Screenshots1/3..JPG
Screenshots2/1.JPG
Screenshots2/2..JPG
Screenshots2/3..JPG
Source code/CalenderEx/.vs/CalenderEx/v16/.suo
Source code/CalenderEx/.vs/CalenderEx/v16/Browse.VC.db
Source code/CalenderEx/.vs/CalenderEx/v16/ipch/AutoPCH/f72b33a5fc70f934/MONTHDAYS.ipch
Source code/CalenderEx/.vs/CalenderEx/v16/ipch/AutoPCH/f74716596bf8ecf/MONTHANDYEAR.ipch
Source code/CalenderEx/CalenderEx.aps
Source code/CalenderEx/CalenderEx.rc
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE 9, 1
#ifdef APSTUDIO_INVOKED
////////////////////////////////////////////////////////
/////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""winres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
Source code/CalenderEx/CalenderEx.sln
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30011.22
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CalenderEx", "CalenderEx.vcxproj", "{7E698B21-388B-4F6A-B13E-2B9D510F18D5}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|x64 = Debug|x64
        Debug|x86 = Debug|x86
        Release|x64 = Release|x64
        Release|x86 = Release|x86
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {7E698B21-388B-4F6A-B13E-2B9D510F18D5}.Debug|x64.ActiveCfg = Debug|x64
        {7E698B21-388B-4F6A-B13E-2B9D510F18D5}.Debug|x64.Build.0 = Debug|x64
        {7E698B21-388B-4F6A-B13E-2B9D510F18D5}.Debug|x86.ActiveCfg = Debug|Win32
        {7E698B21-388B-4F6A-B13E-2B9D510F18D5}.Debug|x86.Build.0 = Debug|Win32
        {7E698B21-388B-4F6A-B13E-2B9D510F18D5}.Release|x64.ActiveCfg = Release|x64
        {7E698B21-388B-4F6A-B13E-2B9D510F18D5}.Release|x64.Build.0 = Release|x64
        {7E698B21-388B-4F6A-B13E-2B9D510F18D5}.Release|x86.ActiveCfg = Release|Win32
        {7E698B21-388B-4F6A-B13E-2B9D510F18D5}.Release|x86.Build.0 = Release|Win32
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
    GlobalSection(ExtensibilityGlobals) = postSolution
        SolutionGuid = {C0E99D38-72BA-4F23-AC34-D2FB45F7B6B2}
    EndGlobalSection
EndGlobal
Source code/CalenderEx/CalenderEx.vcxproj



Debug
Win32


Release
Win32


Debug
x64


Release
x64



16.0
{7E698B21-388B-4F6A-B13E-2B9D510F18D5}
CalenderEx
10.0



Application
true
v142
Unicode


Application
false
v142
true
Unicode


Application
true
v142
Unicode


Application
false
v142
true
Unicode




















true


true


false


false



Level3
true
_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
true


Console
true




Level3
true
_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
true


Console
true




Level3
true
true
true
NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
true


Console
true
true
true




Level3
true
true
true
NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
true


Console
true
true
true















Source code/CalenderEx/CalenderEx.vcxproj.filters



{4FC737F1-C7A5-4376-A066-2A32D752A2FF}
cpp;c;cc;cxx;c++;def;odl;idl;hpj;bat;asm;asmx


{93995380-89BD-4b04-88EB-625FBE52EBFB}
h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd


{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms




Source Files


Source Files




Header Files




Resource Files


Source code/CalenderEx/CalenderEx.vcxproj.user


Source code/CalenderEx/Debug/CalenderEx.exe
Source code/CalenderEx/Debug/CalenderEx.ilk
Source code/CalenderEx/Debug/CalenderEx.log
MonthAndYear.cpp
C:\Users\smang\OneDrive\Desktop\65738-Cpp-Calendar\Source code\CalenderEx\MonthAndYear.cpp(32): warning C4715: 'numberOfDaysInMonth': not all control paths return a value
C:\Users\smang\OneDrive\Desktop\65738-Cpp-Calendar\Source code\CalenderEx\MonthAndYear.cpp(71): warning C4715: 'MonthSequenceNumber': not all control paths return a value
CalenderEx.vcxproj -> C:\Users\smang\OneDrive\Desktop\65738-Cpp-Calendar\Source code\CalenderEx\Debug\CalenderEx.exe
Source code/CalenderEx/Debug/CalenderEx.pdb
Source code/CalenderEx/Debug/CalenderEx.res
Source code/CalenderEx/Debug/CalenderEx.tlog/CalenderEx.lastbuildstate
PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.25.28610:TargetPlatformVersion=10.0.18362.0:
Debug|Win32|C:\Users\smang\OneDrive\Desktop\65738-Cpp-Calendar\Source code\CalenderEx\|
Source code/CalenderEx/Debug/CalenderEx.tlog/CL.command.1.tlog
^C:\USERS\SMANG\ONEDRIVE\DESKTOP\65738-CPP-CALENDAR\SOURCE CODE\CALENDEREX\MONTHDAYS.CPP
/c /ZI /JMC /nologo /W3 /WX- /diagnostics:column /sdl /Od /Oy- /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /permissive- /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"DEBUG\\" /Fd"DEBUG\VC142.PDB" /Gd /TP /analyze- /FC C:\USERS\SMANG\ONEDRIVE\DESKTOP\65738-CPP-CALENDAR\SOURCE CODE\CALENDEREX\MONTHDAYS.CPP
^C:\USERS\SMANG\ONEDRIVE\DESKTOP\65738-CPP-CALENDAR\SOURCE CODE\CALENDEREX\MONTHANDYEAR.CPP
/c /ZI /JMC /nologo /W3 /WX- /diagnostics:column /sdl /Od /Oy- /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /permissive- /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"DEBUG\\" /Fd"DEBUG\VC142.PDB" /Gd /TP /analyze- /FC C:\USERS\SMANG\ONEDRIVE\DESKTOP\65738-CPP-CALENDAR\SOURCE CODE\CALENDEREX\MONTHANDYEAR.CPP
Source code/CalenderEx/Debug/CalenderEx.tlog/CL.read.1.tlog
^C:\USERS\SMANG\ONEDRIVE\DESKTOP\65738-CPP-CALENDAR\SOURCE CODE\CALENDEREX\MONTHDAYS.CPP
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.25.28610\INCLUDE\IOSTREAM
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.25.28610\INCLUDE\YVALS_CORE.H
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.25.28610\INCLUDE\VCRUNTIME.H
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.25.28610\INCLUDE\SAL.H
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.25.28610\INCLUDE\CONCURRENCYSAL.H
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.25.28610\INCLUDE\VADEFS.H
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.25.28610\INCLUDE\XKEYCHECK.H
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.25.28610\INCLUDE\ISTREAM
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.25.28610\INCLUDE\OSTREAM
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.25.28610\INCLUDE\IOS
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.25.28610\INCLUDE\XLOCNUM
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.25.28610\INCLUDE\CLIMITS
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.25.28610\INCLUDE\LIMITS.H
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.25.28610\INCLUDE\CMATH
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.25.28610\INCLUDE\YVALS.H
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\UCRT\CRTDBG.H
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\UCRT\CORECRT.H
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.25.28610\INCLUDE\VCRUNTIME_NEW_DEBUG.H
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.25.28610\INCLUDE\VCRUNTIME_NEW.H
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.25.28610\INCLUDE\CRTDEFS.H
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.25.28610\INCLUDE\USE_ANSI.H
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.25.28610\INCLUDE\CSTDLIB
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\UCRT\MATH.H
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\UCRT\CORECRT_MATH.H
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\UCRT\STDLIB.H
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\UCRT\CORECRT_MALLOC.H
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\UCRT\CORECRT_SEARCH.H
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\UCRT\STDDEF.H
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\UCRT\CORECRT_WSTDLIB.H
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.25.28610\INCLUDE\XTR1COMMON
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.25.28610\INCLUDE\CSTDIO
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\UCRT\STDIO.H
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\UCRT\CORECRT_WSTDIO.H
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\UCRT\CORECRT_STDIO_CONFIG.H
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.25.28610\INCLUDE\STREAMBUF
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.25.28610\INCLUDE\XIOSBASE
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\UCRT\SHARE.H
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.18362.0\UCRT\CORECRT_SHARE.H
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.25.28610\INCLUDE\SYSTEM_ERROR
C:\PROGRAM FILES...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here