Description
Problem A: Is it a leap year? (leapyear.py/leapyear.cpp)
Leap years are years with 366 days instead of the usual 365. The modern definition of leap years
has been in place since the year 1600, roughly. Look up this definition in order to write a
program to solve this problem.
Given a year, determine if it is/was/will be a leap year.
Input Specification
The single input value will be a positive integer in between 1600 and 10000, inclusive.
Output Specification
Output a single line stating if the year entered was a leap year, is a leap year, will be a leap year,
or was not a leap year, is not a leap year, or will not be a leap year. Thus, your output must use
valid verb tense based on the current year, 2018.
Here are four possible sample outputs:
1907 was not a leap year.
2018 is not a leap year.
2000 was a leap year.
2020 will be a leap year.
Sample Program Run #1
What year do you want to check?
2016
2016 was a leap year.
Sample Program Run #2
What year do you want to check?
2117
2117 will not be a leap year.
Sample Program Run #2
What year do you want to check?
1700
1700 was not a leap year.
Problem B (Challenge Problem): Sum of Leap Years (sumleap.c)
Given a starting year and an ending year, determine the sum of all of the leap years that fall
within those boundaries. Note: This is a challenge problem because I am ONLY accepting
solutions WITHOUT loops!!! You may look up information about arithmetic sequence sums
if you forgot how to do those.
Input Specification
Both the starting year, s, and the ending year, e, will be in between 1600 and 10,000, inclusive.
In addition, s ≤ e. (So, in full, the restrictions are: 1600 ≤ s ≤ e ≤ 10000.)
Output Specification
Output a single line of the format:
The sum of the leap years in between S and E is C.
where S and E are the starting and ending years inputted by the user and C is the result of the
query.
Sample Program Run #1
What is the starting year?
1600
What is the ending year?
1605
The sum of the leap years in between 1600 and 1605 is 3204.
Sample Program Run #2
What is the starting year?
1697
What is the ending year?
1703
The sum of the leap years in between 1697 and 1703 is 0.
Problem C: Taxes (tax.c)
Consider the following scheme for income taxes:
If you make less than $20,000 a year, you pay no income tax.
If you make in between $20,000 and $40,000 a year, you pay 10% on the amount of your income
above $20,000. For example, if you make $35,000, the amount of your income above $20,000 is
$15,000. 10% of this is $1500, so that is what you’d owe in income taxes.
If you make in between $40,000 and $80,000 a year, you pay 10% on your $20,000 of your
income and then 20% on the amount of income above $40,000. So for example, if you made
$50,000, you’d pay .1*($20,000) + .2*($10,000) = $4000.
Otherwise, if you may $80,000 or more a year, then you’ll pay 10% on $20,000 of your income
20% on $40,000 of your income and 30% on your income that exceeds $80,000. For example, if
you made $150,000 a year, you would pay .1*($20,000) + .2*($40,000) + .3*($70,000) =
$31,000 in income taxes.
Input Specification
The first and only input value will be a real number to two decimal places indicating your annual
income. It is guaranteed to be in between 0.00 and 1000000000.00.
Output Specification
Output a single line with the following format:
You owe $X.XX in income tax.
where X.XX is simply the dollar amount owed rounded to the nearest cent (must always print
two digits after the decimal.)
Sample Program Run #1
What is your annual income?
19056.78
You owe $0.00 in income tax.
Sample Program Run #2
What is your annual income?
150000.00
You owe $31000.00 in income tax.
Deliverables
Three source files:
1) leapyear.py or leapyear.cpp for your solution to problem A
2) sumleap.c for your solution to problem B
3) tax.c for your solution to problem C
All files are to be submitted over WebCourses.
Note: B is hard. Don’t feel bad if you don’t figure it out completely. I just want to see who can
figure it out!
Restrictions
Although you may use other compilers and coding environments, your programs must run in
IDLE for the Python programs and Code::Blocks for the C/C++ programs.
Grading Details
Your programs will be graded upon the following criteria:
1) Your correctness
2) Your programming style and use of white space. Even if you have a plan and your program
works perfectly, if your programming style is poor or your use of white space is poor, you could
get 10% or 15% deducted from your grade.
Note: As mentioned in class, the input specifications are there to help you. Those are the
requirements I guarantee I’ll stick to when testing your program. You don’t need to check if
the user enters values within those parameters.