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

C++ program , program should print 3 months on each row as indicated, comment it

ID: 3904217 • Letter: C

Question

C++ program , program should print 3 months on each row as indicated, comment it out as much as possible. Thank you

12. Write a program that prints a calendar for a year. Prompt the user for which day of the week January 1 is on and whether the year is a leap year. The day that January 1 is on is coded as follows: Sun 0 Mon 1 Tue 2 Wed 3 Thu 4 Fri 5 Sat 6 Hint: Use a switch statement inside a for or while loop for the months. Enter day of the week for January 1 4 Enter day leap year code (1 for leap year, 0 for non-leap year)0

Explanation / Answer

#include<iostream>
#include<iomanip>

using namespace std;

void printInfo (int m) {
    if (m == 1){
       cout << "     January" << endl;
    }
    else if (m == 2) {
         cout << "     February" << endl; }
    else if (m == 3) {    
         cout << "     March" << endl; }
    else if (m == 4) {
         cout << "     April" << endl; }
    else if (m == 5) {
         cout << "     May" << endl; }
    else if (m == 6) {
         cout << "     June" << endl; }
    else if (m == 7) {
         cout << "     July" << endl; }
    else if (m == 8) {
         cout << "     August" << endl; }
    else if (m == 9) {
         cout << "     September" << endl; }
    else if (m == 10) {
         cout << "     October" << endl; }
    else if (m == 11) {
         cout << "     November" << endl; }
    else if (m == 12) {
         cout << "     December" << endl; }
   

    cout << " Su Mo Tu We Th Fr Sa" <<endl;
}

int DaysInAMonth (int m, int l){
        if (m == 1)
           return(31);
        else if (m == 2 && l == 1)
             return(29);
        else if (m == 2 && l == 0)
             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);
}

void printMonthData (int nDays, int &DayOfWeek) {
        int day = 1;
        for (int i = 0; i<DayOfWeek; i++)
            cout << "   ";
        while (day <= nDays) {
            cout << setw(2) << day << " ";
            if (DayOfWeek == 6){
                cout << endl;
                DayOfWeek = 0;
            }
            else
               DayOfWeek = DayOfWeek + 1;
            day = day + 1;
        }
}

int main(){

    int year, firstDayOfMonth;
    int month;
    int numOfDays;
    int l;
  
   
    cout<<endl;
    cout << "What day of the week does January 1 fall on (0 for Sunday, 1 for Monday, etc.)?";
    cin >> firstDayOfMonth;
    cout << "Enter leap year code(1-leap year, 0 - non leap year):";
    cin >> l;

    cout << endl;

    month = 1;   
    cout << "     " << year << "       "<< endl;
    while ( month <= 12) {
        numOfDays = DaysInAMonth(month,1);
        printInfo(month);
        printMonthData(numOfDays, firstDayOfMonth);
        cout << endl << endl;
        month = month + 1;
    }
   
    cout << endl;
  
   return 0;
}

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