Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 3.145.169.122
Web Server : Apache
System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.2.24
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0705) :  /home/kmmowery/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //home/kmmowery/monthex.cpp
//-------------------------------------------------------------
//	Name: Kieara Mowery
//	Due : Wednesday, October 12th, 2008
//	Date: Sunday, October 9th, 2008
//	Purpose: To display a monthly calendar starting on the 
//	         dates given, which includes the year and leap
//		 year.
//-------------------------------------------------------------

#include <iostream>
#include <iomanip>
using namespace std;

bool LeapYear(int year)
{
	int rem;	// the integer to establish the int year
	bool leapyr;
	rem = year % 4;
		
    if ( rem != 0 )
       leapyr = false;   
       if ( rem != 400 && rem != 100 )
          leapyr = false;
       else 
	  leapyr = true;

     return leapyr;
    
}


//-------------------------------------------------------------
// DaysInMonth determines the number of days of the month
// Note: This includes leap year
//-------------------------------------------------------------
// Accepts:  number (1 - 12) representing month
// Returns:  number of days in that month
//-------------------------------------------------------------


int DaysInMonth (int monthnum, int year)
{
    int numdays;  // temp variable for days in month

    switch (monthnum)
    {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:   numdays = 31;  break;
        case 2:   
        {
	   if(LeapYear(year) == true)
	     numdays = 29;
	   else 
	     numdays = 28;
	}
	break;
	case 4:
        case 6:
        case 9:
        case 11:   numdays = 30;  break;
    }

    return numdays;
}

//-------------------------------------------------------------
// DisplayMonthName displays the month name to standard output
//-------------------------------------------------------------
// Accepts:  number (1 - 12) representing month
// Returns:  nothing
//-------------------------------------------------------------

void DisplayMonthName (int monthnum)
{
    switch (monthnum)
    {
        case 1:  cout << " January";  break;
        case 2:  cout << "February";  break;
        case 3:  cout << "March";  break;
        case 4:  cout << "April";  break;
        case 5:  cout << "May";  break;
        case 6:  cout << "June";  break;
        case 7:  cout << "July";  break;
        case 8:  cout << "August";  break;
        case 9:  cout << "September";  break;
        case 10:  cout << "October";  break;
        case 11:  cout << "November";  break;
        case 12:  cout << "December";  break;
    }
}

    int CalculateDayofWeek ( int month, int day, int year)
    {
	int codes;	// code for the month
	int total;	// total overall
	int digits;	// digits of months
	int dayofweek;	// the day of the week starts
        int monthcode;	// code of the month
        int c;		// to eastablish the leap year
	switch (monthcode)
	{
	    case 1: monthcode = 6; break;
	    case 2: monthcode = 2; break;
	    case 3: monthcode = 2; break;
	    case 4: monthcode = 5; break;
	    case 5: monthcode = 0; break;
	    case 6: monthcode = 3; break;
	    case 7: monthcode = 5; break;
  	    case 8: monthcode = 1; break;
	    case 9: monthcode = 4; break;
	    case 10: monthcode = 6; break;
	    case 11: monthcode = 2; break;
	    case 12: monthcode = 4; break;
	}

    digits = year % 100;
    total = digits + digits / 4;
    codes = total + monthcode + day;

    if ( LeapYear(year) == true )
       if ( month == 1 || month == 2 )
	codes = codes - 1;
    
    c = year % 100;
    
    if ( c == 17 || c == 21 )
       codes = codes + 5;
    if ( c == 18 || c == 22 )
       codes = codes + 3;
    if ( c == 19 )
       codes = codes + 1;

    dayofweek = codes % 7;	    
	
    return dayofweek;    
}

    void DisplayTitleAndHeadings(int month)
    {
	DisplayMonthName (month);
        cout << " Sunday " << setw(8) << " Monday " << setw(8);
	cout << " Tuesday " << setw(8) << " Wednesday " << setw(8);
	cout << " Thursday " << setw(8) << " Friday " << setw(8);
	cout << " Saturday " << setw(8);
    }

    void DisplayFirstLine(int startdayofweek)
    {
	int i;	// to establish the start day of week
	cout << endl;

	for (i = 0; i < startdayofweek; i++)
	    cout << "    " ;
	for (i = 1; i <= ( 7 - startdayofweek); i++)
	    cout << setw(4) << i;
    }
    
    void DisplayFullWeek(int startdateofweek)
    {
	int i;	// to establish the start date of week
	cout << endl;
	for ( i = startdateofweek; i <= startdateofweek + 6; i++ )
	    cout << setw(8) << i; 
	    
    } 
    

    void DisplayLastWeek(int startdateofweek, int numdaysinmonth)
    {
	int i;
	cout << endl;
	for ( i = startdateofweek; i <= numdaysinmonth; i++ )
	    cout << setw(8) << i;
    }


//----------------------------------------------------------
//  Main Function
//-------------------------------------------------------------

int main ( )
{
    int	begdateofnextweek;	// the begin date of the following week

	
// --- Variables

    int monthnum,  	// month number (1 - 12) entered by user
	year,		// the year 
        numdays,  	// number of days in month
	begdayofmonth; 	// begin day of month

//--- Get Year from user

    cout << "\nEnter the year: ";
    cin >> year;

// --- Get month number from user

    cout << "\nEnter a month number (1-12): ";
    cin >> monthnum;

// --- Get Begin Day of Month
    
    begdayofmonth = CalculateDayofWeek ( monthnum, 1, year );
    numdays = DaysInMonth ( monthnum, year);

// --- Validate month number

    while (monthnum < 1 || monthnum > 12)
    {
       cout << "\n\n!!! Month number must be in range 1 - 12 !!!";
       cout << "\n\nPlease re-enter month number: ";
       cin >> monthnum;
    }
// --- Validate year number
    while ( year < 1000 || year > 36000 )
    {
       	cout << " \n\n!!! The year must be in range 1000 - 36000 !!!";
       	cout << " \n\nPlease re-enter month number: ";
	cin >> year;
     }
	
// --- Get number of days in month
 
    numdays = DaysInMonth(monthnum, year);

// --- Display output sentence 

    cout << "\n\n";
    DisplayMonthName (monthnum);
    cout << " has " << numdays << " days.\n\n";
    
    
    DisplayTitleAndHeadings(monthnum);
    DisplayFirstLine(begdayofmonth);    
    begdateofnextweek = 8 - begdayofmonth;
    DisplayFullWeek(begdateofnextweek);
    begdateofnextweek += 7;
    DisplayFullWeek(begdateofnextweek);
    begdateofnextweek += 7;
    DisplayFullWeek(begdateofnextweek);
    begdateofnextweek += 7;
    DisplayFullWeek(begdateofnextweek);
    begdateofnextweek += 7;    
    if ( numdays - begdateofnextweek >= 7)
    {
       DisplayFullWeek(begdateofnextweek);
       begdateofnextweek += 7;
    }
    DisplayLastWeek(begdateofnextweek, numdays);

    cout << endl;
    cout << endl;
    return 0;

}

Stv3n404 - 2023