Leap Year

  1. In last semester we learned the rules of leap years.
  2. A year is a leap year if it is divisible by 4, unless it is a century year that is not divisible by 400. (1800 and 1900 are not leap years while 1600 and 2000 are.)
  3. Write a C++ Boolean function isLeap(year) which determines whether a year is a leap year. (A Boolean function implies that its return value will be either true or false.)
  4. Test your function with the following main program:
    
    int main()
    {
        int year;
        cout << "Please input a year -- ";
        cin >> year;
        if ( isLeap(year) )
            cout << endl << "It is a leap year." << endl;
        else
            cout << endl << "It is not a leap year." << endl;
        return 0;
    }
    
  5. Combine your function and the above main() in a single .cpp file and submit it.
    The program may run as follows:
    
    Please input a year - 2013
    
    It is not a leap year.
    
    
    
    Please input a year - 2016
    
    It is a leap year.