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

C++ This is part 2 of a two part assignment. Your score on this assignment will

ID: 3857908 • Letter: C

Question

C++

This is part 2 of a two part assignment. Your score on this assignment will take into consideration your work on both the previous assignment and this assignment.

This assignment is a continuation of the last assignment. I'll repeat the introductory information here.

Write a program that prints a calendar for one year, given the day of the week that January 1 falls on. Each successive month starts on the day of the week that follows the last day of the preceding month. Days of the week will be numbered 0 through 6 for Sunday through Saturday.

Do not use classes, arrays, or structs in this project!! (If you don't know what they are, don't worry, you aren't using them.)

Your output should look exactly like the one in this sample screen output:

Additional Requirements and Hints:

All of the requirements from your last assignment (part 1 of this assignment) still apply.

If your part 1 of this assignment was written well, this part, part 2, should be completed by making just two changes: (1) One or more parameters may need to be modified. You shouldn't need to add or delete any parameters. (2) Inside the for loop that prints the dates, add an if or if/else statement. Among other things, this statement should contain a cout << endl; to force a new line when the day is saturday.

The basic idea here is that you will use the "startDay" variable to always represent the current day of the month. That way, when you go to print the first day of the following month, you can always check the value of startDay to see what day of the week the month should start on. Other than the increment operator (++), do not use any arithmetic operators to figure out what the first day of the month should be, especially not the % operator.

Don't forget that 20 percent of your score on this assignment will be based on comments.

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 << " S M T W T F S" <<endl;
}

int DaysInAMonth (int m){
        if (m == 1)
           return(31);
        else if (m == 2)
             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;
  
    cout << "What year do you want a calendar for? ";
    cin >>year;
   
    cout<<endl;
    cout << "What day of the week does January 1 fall on (0 for Sunday, 1 for Monday, etc.)?";
   
    cin >> firstDayOfMonth;

    cout << endl;

    month = 1;   
    cout << "     " << year << "       "<< endl;
    while ( month <= 12) {
        numOfDays = DaysInAMonth(month);
        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