Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Nearly every 4 years is a leap year in the Gregorian calendar.In a leap year, there are 366 days (adding February 29th) insteadof the usual

Nearly every 4 years is a leap year in the Gregorian calendar.In a leap year, there are 366 days (adding February 29th) insteadof the usual 365. Specifically a year y is a leap year if it isdivisible by 4. However, every year that is divisible by 100 is nota leap year unless it is divisible by 400. Thus, 2000, 2004, 2008were leaps years but 2001, 2002, 2003 were not. 1900 was not a leapyear; though it was divisible by 4 it was divisible by 100 but not400. We’ve provided a partially completed program, leapYear.c thattests whether or not various years are leap years. 1. Implement aconditional statement inside the isLeapYear() function to determineif the given year is a leap year or not. Return true ( 1 ) if itis, false ( 0 ) if it is not. 2. Compile and run your program:we’ve provided 3 hard-coded test cases. Fix any errors in yourprogram until they all pass. 3. Using the provided code as anexample, add at least 3 more test cases to your program. Repeatyour compile/run/test until they all pass.

int year;
int numPassed = 0;
int numFailed = 0;

//Hard-coded ad-hoc test cases
//Do not change these, add your own test cases
//below. All test cases should pass.

year = 2000;
printf("Test Case 1: year = %d: ", year);
if(!isLeapYear(year)) {
printf("FAILED!");
numFailed = numFailed + 1;
} else {
printf("PASSED!");
numPassed = numPassed + 1;
}

year = 2001;
printf("Test Case 2: year = %d: ", year);
if(isLeapYear(year)) {
printf("FAILED!");
numFailed = numFailed + 1;
} else {
printf("PASSED!");
numPassed = numPassed + 1;
}

year = 2100;
printf("Test Case 3: year = %d: ", year);
if(isLeapYear(year)) {
printf("FAILED!");
numFailed = numFailed + 1;
} else {
printf("PASSED!");
numPassed = numPassed + 1;
}

//TODO: write at least 3 more of your own test cases

printf("");
printf("Summary:");
printf("Number of test cases passed: %d",numPassed);
printf("Number of test cases failed: %d",numFailed);
printf("Percentage Passed: %.2f%%", (double) numPassed /(numPassed + numFailed) * 100.0);

return 0;
}

int isLeapYear(int year) {
//TODO: Write your logic here
// The year is stored in the variableyear
// Your function should return true (1)if it represents a leap year
// and false (0) if it does not.
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Computer Performance Engineering 10th European Workshop Epew 2013 Venice Italy September 17 2013 Proceedings

Authors: Maria Simonetta Balsamo ,William Knottenbelt ,Andrea Marin

2013 Edition

3642407242, 978-3642407246

More Books

Students also viewed these Programming questions