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 year, day;
	cin >> year >> day;
	int sun1 = 8 - day;
	if (year%4 == 0) {
		if (year%100 != 0) {
		// leap year
			if (sun1 <= 3) {
			cout << "Month 1: " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
			sun1 += 28;
			sun1 += 7;
			sun1 -= 31;
			}
			else {
				cout << "Month 1: " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
				sun1 += 21;
				sun1 += 7;
				sun1 -= 31;
			}
		
			if (sun1 == 1) {
				cout << "Month 2: " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
				sun1 += 28;
				sun1 += 7;
				sun1 -= 29;
			}
			else {
				cout << "Month 2: " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
				sun1 += 21;
				sun1 += 7;
				sun1 -= 29;
			}
	
			if (sun1 <= 3) {
				cout << "Month 3: " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
				sun1 += 28;
				sun1 += 7;
				sun1 -= 31;
			}
			else {
				cout << "Month 3: " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
				sun1 += 21;
				sun1 += 7;
				sun1 -= 31;
			}
			
			if (sun1 <= 2) {
					cout << "Month" << 4 <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
					sun1 += 28;
					sun1 += 7;
					sun1 -= 30;	
				}
				else {
					cout << "Month" << 4 <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
					sun1 += 21;
					sun1 += 7;
					sun1 -= 30;
				}
				
				if (sun1 <= 3) {
					cout << "Month" << 5 <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
					sun1 += 28;
					sun1 += 7;
					sun1 -= 31;	
				}
				else {
					cout << "Month" << 5 <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
					sun1 += 21;
					sun1 += 7;
					sun1 -= 31;
				}	

			for (int i = 3; i < 7; i++) {
				if (sun1 <= 3) {
					cout << "Month" << 2*i <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
					sun1 += 28;
					sun1 += 7;
					sun1 -= 31;	
				}
				else {
					cout << "Month" << 2*i <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
					sun1 += 21;
					sun1 += 7;
					sun1 -= 31;
				}	
				if (2*i + 1 == 13) break;
				if (sun1 <= 2) {
					cout << "Month" << 2*i+1 <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
					sun1 += 28;
					sun1 += 7;
					sun1 -= 30;	
				}
				else {
					cout << "Month" << 2*i+1 <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
					sun1 += 21;
					sun1 += 7;
					sun1 -= 30;
				}
				
				
			}
		}
			else if (year%400 == 0) {
				// leap year
				if (sun1 <= 3) {
					cout << "Month 1: " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
					sun1 += 28;
					sun1 += 7;
					sun1 -= 31;
				}
				else {
					cout << "Month 1: " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
					sun1 += 21;
					sun1 += 7;
					sun1 -= 31;
				}

				if (sun1 == 1) {
					cout << "Month 2: " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
					sun1 += 28;
					sun1 += 7;
					sun1 -= 29;
				}
				else {
					cout << "Month 2: " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
					sun1 += 21;
					sun1 += 7;
					sun1 -= 29;
				}

				if (sun1 <= 3) {
				cout << "Month 3: " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
				sun1 += 28;
				sun1 += 7;
				sun1 -= 31;
				}
				else {
				cout << "Month 3: " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
				sun1 += 21;
				sun1 += 7;
				sun1 -= 31;
			}
	
			if (sun1 <= 2) {
					cout << "Month" << 4 <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
					sun1 += 28;
					sun1 += 7;
					sun1 -= 30;	
				}
				else {
					cout << "Month" << 4 <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
					sun1 += 21;
					sun1 += 7;
					sun1 -= 30;
				}
				
				if (sun1 <= 3) {
					cout << "Month" << 5 <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
					sun1 += 28;
					sun1 += 7;
					sun1 -= 31;	
				}
				else {
					cout << "Month" << 5 <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
					sun1 += 21;
					sun1 += 7;
					sun1 -= 31;
				}	

			for (int i = 3; i < 7; i++) {
				if (sun1 <= 3) {
					cout << "Month" << 2*i <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
					sun1 += 28;
					sun1 += 7;
					sun1 -= 31;	
				}
				else {
					cout << "Month" << 2*i <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
					sun1 += 21;
					sun1 += 7;
					sun1 -= 31;
				}	
				if (2*i + 1 == 13) break;
				if (sun1 <= 2) {
					cout << "Month" << 2*i+1 <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
					sun1 += 28;
					sun1 += 7;
					sun1 -= 30;	
				}
				else {
					cout << "Month" << 2*i+1 <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
					sun1 += 21;
					sun1 += 7;
					sun1 -= 30;
				}
				
				
			}
		}
		else if (year%400 != 0) {
			// normal year
			if (sun1 <= 3) {
				cout << "Month 1: " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
				sun1 += 28;
				sun1 += 7;
				sun1 -= 31;
			}
			else {
			cout << "Month 1: "  << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
			sun1 += 21;
			sun1 += 7;
			sun1 -= 31;
			}

		cout << "Month 2: " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
		sun1 += 21;
		sun1 += 7;
		sun1 -= 28;
	
		if (sun1 <= 3) {
			cout << "Month 3: " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
			sun1 += 28;
			sun1 += 7;
			sun1 -= 31;
		}
		else {
		cout << "Month 3: " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
		sun1 += 21;
		sun1 += 7;
		sun1 -= 31;
		}
	

		if (sun1 <= 2) {
					cout << "Month" << 4 <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
					sun1 += 28;
					sun1 += 7;
					sun1 -= 30;	
				}
				else {
					cout << "Month" << 4 <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
					sun1 += 21;
					sun1 += 7;
					sun1 -= 30;
				}
				
				if (sun1 <= 3) {
					cout << "Month" << 5 <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
					sun1 += 28;
					sun1 += 7;
					sun1 -= 31;	
				}
				else {
					cout << "Month" << 5 <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
					sun1 += 21;
					sun1 += 7;
					sun1 -= 31;
				}	

			for (int i = 3; i < 7; i++) {
				if (sun1 <= 3) {
					cout << "Month" << 2*i <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
					sun1 += 28;
					sun1 += 7;
					sun1 -= 31;	
				}
				else {
					cout << "Month" << 2*i <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
					sun1 += 21;
					sun1 += 7;
					sun1 -= 31;
				}	
				if (2*i + 1 == 13) break;
				if (sun1 <= 2) {
					cout << "Month" << 2*i+1 <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
					sun1 += 28;
					sun1 += 7;
					sun1 -= 30;	
				}
				else {
					cout << "Month" << 2*i+1 <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
					sun1 += 21;
					sun1 += 7;
					sun1 -= 30;
				}
				
				
			}
	}
	} else {
	// normal year
		if (sun1 <= 3) {
		cout << "Month 1: " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
		sun1 += 28;
		sun1 += 7;
		sun1 -= 31;
	}
	else {
		cout << "Month 1: " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
		sun1 += 21;
		sun1 += 7;
		sun1 -= 31;
	}
	
	cout << "Month 2: " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
	sun1 += 21;
	sun1 += 7;
	sun1 -= 28;
	
	if (sun1 <= 3) {
		cout << "Month 3: " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
		sun1 += 28;
		sun1 += 7;
		sun1 -= 31;
	}
	else {
		cout << "Month 3: " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
		sun1 += 21;
		sun1 += 7;
		sun1 -= 31;
	}	

	if (sun1 <= 2) {
					cout << "Month" << 4 <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
					sun1 += 28;
					sun1 += 7;
					sun1 -= 30;	
				}
				else {
					cout << "Month" << 4 <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
					sun1 += 21;
					sun1 += 7;
					sun1 -= 30;
				}
				
				if (sun1 <= 3) {
					cout << "Month" << 5 <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
					sun1 += 28;
					sun1 += 7;
					sun1 -= 31;	
				}
				else {
					cout << "Month" << 5 <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
					sun1 += 21;
					sun1 += 7;
					sun1 -= 31;
				}	

			for (int i = 3; i < 7; i++) {
				if (sun1 <= 3) {
					cout << "Month" << 2*i <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
					sun1 += 28;
					sun1 += 7;
					sun1 -= 31;	
				}
				else {
					cout << "Month" << 2*i <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
					sun1 += 21;
					sun1 += 7;
					sun1 -= 31;
				}	
				if (2*i + 1 == 13) break;
				if (sun1 <= 2) {
					cout << "Month" << 2*i+1 <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << " " << sun1 + 28 << endl;
					sun1 += 28;
					sun1 += 7;
					sun1 -= 30;	
				}
				else {
					cout << "Month" << 2*i+1 <<": " << sun1 << " " << sun1 + 7 << " " << sun1 + 14 << " " << sun1 + 21 << endl;
					sun1 += 21;
					sun1 += 7;
					sun1 -= 30;
				}
				
				
			}
}
}

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