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

Write a C++ program to create and display a month calendar. The user provides th

ID: 3641041 • Letter: W

Question

Write a C++ program to create and display a month calendar. The user provides the month and the starting day of that month as integer values. The calendar contains the date values of working days only (Saturday, Monday,.., Wednesday), the weekend dates are not part of your calendar. Your code should use the starting day value, the date as integer to display the day values. Assume this program is not used for leap year. The calendar should be displayed in an output file month.txt.
Your program should use if, if-else, and switch control statements( only). The code should be interactive and the output should be labeled clearly and formatted neatly. Below is an example of the execution of the code and output file.

Explanation / Answer

Dude your question says to use if, if-else, and switch control statements( only) for "control statements".

It isn't saying anything about using looping ar array which means It isn't denying us the use of looping.

So its safe to use looping. Without looping the program will be very lengthy and impractical.

Please rate...

#include<iostream>
#include<fstream>
#include<cstdlib>
#include<iomanip>
using namespace std;
int main()
{
    int d,m,c,i;
    ofstream fout;
    fout.open("month.txt");
    if (!fout)
    {
       cout << "Error: cannot open data file. Program aborting. ";
       exit(1);
    }
    cout<<"Enter your starting day of the month";
    cout<<"(1 for saturday,2 for sunday, etc): ";
    cin>>d;
    cout<<" Enter your month";
    cout<<"(1 for january,2 for february,etc): ";
    cin>>m;
    char a[][10]={"Saturday","Sunday","Monday","Tuesday","Wednesday"};
    char b1[][15]={"January","February","March","April","May","June","July"};
    char b2[][15]={"August","September","October","November","December"};
    switch(m)
    {
        case 1:case 3:case 5:case 7:case 8:case 10:case 12:
        {
            if(m<=7)fout<<"            "<<b1[m-1]<<" ";
            if(m>7)fout<<"             "<<b2[12-m+2]<<" ";
            for(i=0;i<5;i++)
            {
                fout<<setw(10)<<a[i];
            }
            fout<<" ";
            if(d<=5){
            for(i=1;i<d;i++)
            {
                fout<<setw(10)<<"";
            }
            }
            for(i=1;i<=7-d-1;i++)
            {
                fout<<setw(10)<<i;
            }
            fout<<" ";
            c=0;
            for(i=7-d+2;i<=31;i++)
            {
                c++;
                fout<<setw(10)<<i;
                if(c>=5){i=i+2;c=0;
                fout<<" ";
                }
            }
            break;
        }
        case 4:case 6:case 9:case 11:
        {
            if(m<=7)fout<<"            "<<b1[m-1]<<" ";
            if(m>7)fout<<"             "<<b2[12-m+2]<<" ";
            for(i=0;i<5;i++)
            {
                fout<<setw(10)<<a[i];
            }
            fout<<" ";
            if(d<=5){
            for(i=1;i<d;i++)
            {
                fout<<setw(10)<<"";
            }
            }
            for(i=1;i<=7-d-1;i++)
            {
                fout<<setw(10)<<i;
            }
            fout<<" ";
            c=0;
            for(i=7-d+2;i<31;i++)
            {
                c++;
                fout<<setw(10)<<i;
                if(c>=5){i=i+2;c=0;
                fout<<" ";
                }
            }
            break;
        }
        case 2:
        {
            if(m<=7)fout<<"            "<<b1[m-1]<<" ";
            if(m>7)fout<<"             "<<b2[12-m+2]<<" ";
            for(i=0;i<5;i++)
            {
                fout<<setw(10)<<a[i];
            }
            fout<<" ";
            if(d<=5){
            for(i=1;i<d;i++)
            {
                fout<<setw(10)<<"";
            }
            }
            for(i=1;i<=7-d-1;i++)
            {
                fout<<setw(10)<<i;
            }
            fout<<" ";
            c=0;
            for(i=7-d+2;i<28;i++)
            {
                c++;
                fout<<setw(10)<<i;
                if(c>=5){i=i+2;c=0;
                fout<<" ";
                }
            }
            break;
        }
    }
}

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