2014-09-29 HW12 due Thurs

posted Sep 29, 2014, 8:21 PM by Samuel Konstantinovich   [ updated Oct 3, 2014, 4:56 AM ]
You have a Quiz this Friday Oct 3rd, because of a fire drill. 
    The quiz will only be on scheme only, up to if statements. 
The EXAM will be next friday Oct 10th. 
    The test will cover everything up to what we learn next Tuesday unless otherwise stated.

HW12 : Deadline: Thursday Oct 2nd 11:59pm 
(submit a rkt or txt file, include your header)

1. Write a function (makeEven x) , assume x is an integer.
When x is even it evaluates to x
When x is odd, it evaluates to x+1

2. Write a function (checkSign x) , assume x is a real number.
When x is positive return 1 
When x is negative return 2
When x is neutral return 3

(checkSign 4) -> 1
(checkSign -3) -> 2
(checkSign 0) -> 3
3. Write a function (howManyRoots a b c) that tells us how many roots a quadratic in the form ax^2 + bx + c = 0. The possible values are 0 1 or 2.

The discriminant can help us determine the nature of the roots of a quadratic as follows:
discriminant is negative : there are no real solutions
discriminant is zero : there is exactly one real solution
discriminant is positive : there are two real solutions

edit: fixed name of function
(howManyRoots 2 6 3) returns 2
(howManyRoots 1 -8 16) returns 1
(howManyRoots 4 5 3) returns 0

4. Write a function (leapyear year) that returns #t when a year is a leap year, #f when it is not. 
NOTE: This problem does not require an if statement. Try to figure it out with just boolean expressions

You may google leap years for clarification.
The rules of leap years are:   
-Multiples of 400 are leap years.
-Multiples of 100 that are not multiples of 400 are not leap years
-Multiples of 4 that are not multiples of 100 are leap years
-All other years are are not.
OR: (rephrase)
Years that are multiples of 4 are leap years, except that every year that is a multiple of 100 is not a leap year , unless it is also a multiple of 400 then it is.
(leapyear 2000) #t
(leapyear 1900) #f
(leapyear 1904) #t 
(leapyear 2103) #f
(leapyear 2104) #t