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

this is C++ CHAPTER 5, Exercs*5.29 (Display leap years) 5.29) (Display leap year

ID: 3751732 • Letter: T

Question

this is C++

CHAPTER 5, Exercs*5.29 (Display leap years) 5.29) (Display leap years) Write a program that displays all the leap years, 10 per line, in the period between two positive integer year periods entered by the user separated by exactly one space SAMPLE RUN #4: ./DisplayLeapYears Interactive Session Hide Invisibles Highlight: None Show Highlighted OnlyU Enter.a positive start year:1666-4 Enter.a positive end.year.greater.then start.year 1999. 1668-1672 1676-1688-1684-1688-1692 1696-1784-1708 1712 1716.1720 1724 1728-1732.1736-1740-1744.1748. 1752-1756-1760-1764-1768: 1772-1776-1780. 174.1788- 1792.1796. 1804.1808.1812.1816-1820-1824.1828 1832 1836-1840 1844 1848 1852 1856.1860-1864 1868.1872. 1876 1880 1884 1888 1892 1896 1904 1908 1912 1916. 1920 1924 1928 1932.1936 1940 1944 1948-1952 1956. 1960 1964 1968 84 -1988 1992 1996 972.1976.1980 19

Explanation / Answer

If you post more than 1 question, as per chegg guidelines I have to solve only first question.

Ques 1.

#include<iostream>

using namespace std;

// return true if n is leap year

bool isLeapYear( int n )

{

    // if n is divisible by 400

    // it is leap year

    if ( n % 400 == 0)

        return true;

    // if n is divisible by 100

    // it is not leap year

    else if ( n % 100 == 0)

        return false;

    // if n is divisible by 4

    // it is leap year

    else if ( n % 4 == 0)

        return true;

    // it is not leap year

    else

        return false;

}

int main()

{

    int p, r;

   

    cout<<"Enter a positive start year : ";

    cin>>p;

   

    cout<<"Enter a positive end year greater than start year : ";

    cin>>r;

   

    int i, count = 0, pre = 0;

   

    // traverse throught the years

    for( i = p ; i < r ; i++ )

    {

        // if i is leap year

        if( isLeapYear(i) )

        {

            cout<<i<<" ";

           

            count++;

        }

           

        // if 10 elements have been printed in the current line

        if( count % 10 == 0 && count != pre )

        {

            pre = count;

            cout<<endl;

        }

  }

   

    return 0;

}

Sample Output