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

Problem Description You are asked to design, implement, debug and test an intera

ID: 3780287 • Letter: P

Question

Problem Description

You are asked to design, implement, debug and test an interactive C++ program that will produce a calendar for any month specified by the user.

Input

The input to this program will be entered at the keyboard. The user will be prompted to enter the month and year. Both will be stored as integers. The month must be a number between 1 and 12. The year will be a four-digit integer representing a year in the Gregorian calendar system (our normal system) which started in 1582.

The input must be tested for validity.

Output

This program should display the calendar for the month requested by the user. It should be organized in grid format, with the month and year centered over the grid. Under that there should be seven columns appropriately labeled. The first of the month must appear under the correct day and the rest of the days in the month lined up accordingly. (See example below.)

                      February 2012

Sun    Mon   Tue    Wed   Thu    Fri      Sat

============================

                               1   2       3      4            

   5         6       7      8 9 10      11         

12       13   14 15      16      17      18      

19        20 21 22      23      24      25        

26       27   28 29   

Should have 5 user defined functions

1) int daysofweek(int day, int month, int year)

2) bool leapyear (int year)

3) void getInput (int &month, int %year)

4)int daysInMonth(int month, int year)

5) void displayTitle (int month, int year)

Explanation / Answer

public class Calendar {

  
public static int dayofWeek(int month, int day, int year) {
int y = year - (14 - month) / 12;
int x = y + y/4 - y/100 + y/400;
int m = month + 12 * ((14 - month) / 12) - 2;
int d = (day + x + (31*m)/12) % 7;
return d;
}

  
public static boolean isLeapYear(int year) {       //used to find leapyear
if ((year % 4 == 0) && (year % 100 != 0)) return true;
if (year % 400 == 0) return true;
return false;
}

public static void main(String[] args) {
  
int month = Integer.parseInt(args[0]); // month (Jan = 1, Dec = 12),taking input from command line
int year = Integer.parseInt(args[1]); // year ,taking year from command line

  
String[] months = {                       //string array to store months
"", // leave empty so that months[1] = "January"
"January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December"
};

// taking number of days in a month in to array
int[] days = {
0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};


if (month == 2 && isLeapYear(year)) days[month] = 29; // checking for leap year


// printing the calander calendar header
System.out.println(" " + months[month] + " " + year);
System.out.println(" S M Tu W Th F S");

  
int d = dayofWeek(month, 1, year);   // for starting day

// print the calendar
for (int i = 0; i < d; i++)
System.out.print(" ");
for (int i = 1; i <= days[month]; i++) {
System.out.printf("%2d ", i);
if (((i + d) % 7 == 0) || (i == days[month])) System.out.println();
}

}
}

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