Problem: Write a C++ program to take two inputs from the user, the year N, and d, the day of the week that January 1st falls on. Assume that the days are encoded as follows: (Mon: 1, Tues: 2, Wed: 3,   Sun: 7). Based on this, print all the dates on which Sunday falls on in that year.You must also take into account if the year is a leap year or not. The year is said to be a leap year if the year is divisible by four, except for end-of-century years where the year should be divisible by 400.

Example:Let s say you were interested in finding out all the dates when Sunday is going to be this year i.e. 2024, then the input to your code should be:2024 1Explanation for the above input: 2024 is the year and 1st Jan happened to be on Monday this year, hence was number-encoded as 1The output should list the dates of all Sundays in the year N, month-wise on a new line.

Constraints (Assume)1000 <= N (Year) <= 35001 <= d <= 12

Student submission:
#include <simplecpp>

main_program {
    int N, d;
    cin >> N >> d;
    bool leap;
    
    //leap year calculation
    if(N % 100 == 0) {
        if(N % 400 == 0) {
            leap = True;
        }
    }
    else if(N % 4 == 0) {
        leap = True;
    }

    int sun;

    //Jan
    cout << "Month 1: ";
    for(sun = 8 - d; sun <= 31; sun += 7) {
        cout << sun << " ";
    }
    cout << endl;

    //Feb
    if(leap == False) {
        cout << "Month 2: ";
        if(d <= 4) {
            for(sun = 5 - d; sun <= 28; sun += 7) {
                cout << sun << " ";
            }
        }
        else {
           for(sun = 11 - d; sun <= 28; sun += 7) {
                cout << sun << " ";
            } 
        }
        cout << endl;
    }
    else {
        cout << "Month 2: ";
        if(d <= 4) {
            for(sun = 5 - d; sun <= 29; sun += 7) {
                cout << sun << " ";
            }
        }
        else {
           for(sun = 11; sun <= 29; sun += 7) {
                cout << sun << " ";
            } 
        }
        
    cout << endl;
    }

    //March
    if(leap == False) {
        cout << "Month 3: ";
        if(d <= 4) {
            for(sun = 5 - d; sun <= 31; sun += 7) {
                cout << sun << " ";
            }
        }
        else {
           for(sun = 11 - d; sun <= 31; sun += 7) {
                cout << sun << " ";
            } 
        }
        cout << endl;
    }
    else {
        cout << "Month 3: ";
        if(d <= 5) {
            for(sun = 6 - d; sun <= 31; sun += 7) {
                cout << sun << " ";
            }
        }
        else {
           for(sun = 12 - d; sun <= 31; sun += 7) {
                cout << sun << " ";
            } 
        }
        
    cout << endl;
    }

    //April
    if(leap == False) {
        cout << "Month 4: ";
        if(d > 1) {
            for(sun = 9 - d; sun <= 30; sun += 7) {
            cout << sun << " ";
        }
        }
        else {
           for(sun = 1; sun <= 30; sun += 7) {
                cout << sun << " ";
            } 
        }
        cout << endl;
    }
    else {
        cout << "Month 4: ";
        if(d <= 5) {
            for(sun = 6 - d; sun <= 30; sun += 7) {
                cout << sun << " ";
            }
        }
        else {
           for(sun = 12 - d; sun <= 30; sun += 7) {
                cout << sun << " ";
            } 
        }
        
    cout << endl;
    }

    //May
    if(leap == False) {
        cout << "Month 5: ";
        if(d < 7) {
            for(sun = 7 - d; sun <= 31; sun += 7) {
            cout << sun << " ";
        }
        }
        else {
           for(sun = 7; sun <= 31; sun += 7) {
                cout << sun << " ";
            } 
        }
        cout << endl;
    }
    else {
        cout << "Month 5: ";
        if(d <= 5) {
            for(sun = 6 - d; sun <= 30; sun += 7) {
                cout << sun << " ";
            }
        }
        else {
           for(sun = 12 - d; sun <= 30; sun += 7) {
                cout << sun << " ";
            } 
        }
        
    cout << endl;
    }
    //June
    if(leap == False) {
        cout << "Month 6: ";
        if(d < 4) {
            for(sun = 4 - d; sun <= 30; sun += 7) {
            cout << sun << " ";
        }
        }
        else {
           for(sun = d + 3; sun <= 30; sun += 7) {
                cout << sun << " ";
            } 
        }
        cout << endl;
    }
    else {
        cout << "Month 6: ";
        if(d <= 5) {
            for(sun = 6 - d; sun <= 30; sun += 7) {
                cout << sun << " ";
            }
        }
        else {
           for(sun = 12 - d; sun <= 30; sun += 7) {
                cout << sun << " ";
            } 
        }
        
    cout << endl;
    }

    //July
    if(leap == False) {
        cout << "Month 7: ";
        if(d > 2) {
            for(sun = 9 - d; sun <= 31; sun += 7) {
            cout << sun << " ";
        }
        }
        else {
           for(sun = 2 - d; sun <= 31; sun += 7) {
                cout << sun << " ";
            } 
        }
        cout << endl;
    }
    else {
        cout << "Month 7: ";
        if(d <= 5) {
            for(sun = 6 - d; sun <= 30; sun += 7) {
                cout << sun << " ";
            }
        }
        else {
           for(sun = 12 - d; sun <= 30; sun += 7) {
                cout << sun << " ";
            } 
        }
        
    cout << endl;
    }

    //August
    if(leap == False) { 
        cout << "Month 8: ";
        if(d < 6) {
            for(sun = 6 - d; sun <= 30; sun += 7) {
            cout << sun << " ";
        }
        }
        else {
           for(sun = 1; sun <= 30; sun += 7) {
                cout << sun << " ";
            } 
        }
        cout << endl;
    }
    else {
        cout << "Month 8: ";
        if(d < 6) {
            for(sun = 6 - d; sun <= 30; sun += 7) {
                cout << sun << " ";
            }
        }
        else {
           for(sun = 12 - d; sun <= 30; sun += 7) {
                cout << sun << " ";
            } 
        }
        
    cout << endl;
    }

    //September
    if(leap == False) {
        cout << "Month 9: ";
        if(d < 3) {
            for(sun = 3 - d; sun <= 30; sun += 7) {
            cout << sun << " ";
        }
        }
        else {
           for(sun = d + 2; sun <= 30; sun += 7) {
                cout << sun << " ";
            } 
        }
        cout << endl;
    }
    else {
        cout << "Month 9: ";
        if(d <= 5) {
            for(sun = 6 - d; sun <= 30; sun += 7) {
                cout << sun << " ";
            }
        }
        else {
           for(sun = 12 - d; sun <= 30; sun += 7) {
                cout << sun << " ";
            } 
        }
        
    cout << endl;
    }

    //October
    if(leap == False) {
        cout << "Month 10: ";
        for(sun = 8 - d; sun <= 31; sun += 7) {
            cout << sun << " ";
        }
        cout << endl;
    }
    else {
        cout << "Month 10: ";
        if(d <= 5) {
            for(sun = 6 - d; sun <= 31; sun += 7) {
                cout << sun << " ";
            }
        }
        else {
           for(sun = 12 - d; sun <= 31; sun += 7) {
                cout << sun << " ";
            } 
        }
        
    cout << endl;
    }

    //November
    if(leap == False) {
        cout << "Month 11: ";
        if(d <= 4) {
            for(sun = 5 - d; sun <= 30; sun += 7) {
                cout << sun << " ";
            }
        }
        else {
           for(sun = 11 - d; sun <= 30; sun += 7) {
                cout << sun << " ";
            } 
        }
        cout << endl;
    }
    else {
        cout << "Month 11: ";
        if(d <= 5) {
            for(sun = 6 - d; sun <= 31; sun += 7) {
                cout << sun << " ";
            }
        }
        else {
           for(sun = 12 - d; sun <= 31; sun += 7) {
                cout << sun << " ";
            } 
        }
        
    cout << endl;
    }

    //December
    if(leap == False) {
        cout << "Month 12: ";
        if(d < 3) {
            for(sun = 3 - d; sun <= 30; sun += 7) {
            cout << sun << " ";
        }
        }
        else {
           for(sun = d + 2; sun <= 30; sun += 7) {
                cout << sun << " ";
            } 
        }
        cout << endl;
    }
    else {
        cout << "Month 12: ";
        if(d <= 5) {
            for(sun = 6 - d; sun <= 30; sun += 7) {
                cout << sun << " ";
            }
        }
        else {
           for(sun = 12 - d; sun <= 30; sun += 7) {
                cout << sun << " ";
            } 
        }
        
    cout << endl;
    }
}

Grading criterion: Correct I/O incl. Format
Rating A: I/O Handled correctly
Rating B: Error in I/O
Rating C: 0
Rating D: 0
Assigned grade: A