-
Notifications
You must be signed in to change notification settings - Fork 53
/
leapYear.c
83 lines (71 loc) · 1.86 KB
/
leapYear.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* This program determines if various years are leap
* years or not.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
/**
* Returns true (1) if the given year is a leap year,
* false (0) if it is not a leap year.
*/
int isLeapYear(int year);
int main(int argc, char **argv) {
bool reportPass = false;
if(argc > 1 && strcmp(argv[1], "-reportPass") == 0) {
reportPass = true;
}
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!\n");
numFailed = numFailed + 1;
} else {
printf("PASSED!\n");
numPassed = numPassed + 1;
}
year = 2001;
printf("Test Case 2: year = %d: ", year);
if(isLeapYear(year)) {
printf("FAILED!\n");
numFailed = numFailed + 1;
} else {
printf("PASSED!\n");
numPassed = numPassed + 1;
}
year = 2100;
printf("Test Case 3: year = %d: ", year);
if(isLeapYear(year)) {
printf("FAILED!\n");
numFailed = numFailed + 1;
} else {
printf("PASSED!\n");
numPassed = numPassed + 1;
}
//TODO: write *at least* 3 more of your own
// test cases here, they should all pass!
printf("\n\n");
printf("Summary:\n");
printf("Number of test cases passed: %d\n", numPassed);
printf("Number of test cases failed: %d\n", numFailed);
printf("Percentage Passed: %.2f%%\n", (double) numPassed / (numPassed + numFailed) * 100.0);
if(reportPass) {
return numPassed;
} else {
return numFailed;
}
}
int isLeapYear(int year) {
//TODO: Write your logic here
// The year is stored in the variable year
// Your function should return true (1) if it represents a leap year
// and false (0) if it does not.
}