2017-09-20 HW07 EXAM

posted Sep 20, 2017, 6:22 AM by Samuel Konstantinovich   [ updated Sep 20, 2017, 11:14 PM ]
Goal: Multiple choices!


NOTE: Exam next Friday!

Do Now:

1. Write a function that accepts three side lengths of a triangle a b and c, that assumes c is the longest side. It returns true if that triangle is a right triangle, false otherwise. (Does not require if statements)
(pythCheck 3 4 5)  is #true
(pythCheck 5 4 3)  is #false
(pythCheck 3 4 6)  is #false
After writing it out , run drRacket and test at least one other Pythagorean triples!

Note: You probably cannot check triangles with irrational side measures because of rounding errors.(like a  1 1  sqrt(2) triangle)
 
2. Discuss how can you make (isRight a b c) that uses pythCheck such that it does not assume anything about the longest side?
Write this function! (returns true if the 3 values given are valid lengths of a right triangle. Assume a,b,c are all integers)


Classwork:

Rubber ducky!

We can return words too!
(if (> x 3)
    "Big" 
    "Small")

would show you a value either: (Quotes show up when typing text as a value in computer languages, and when you print it in Scheme)
"Big"
OR
"Small"
but never both.

Branching an if statement:

An if statement is an expression so you can put an if inside of an if:
(if  you_have_cake_ingredients ;outer if
     (if  you_can_bake
          (go_bake_a_cake)
          (go_learn_to_bake) ) ;close the inner if
    (go_buy_cake_stuff)  ) ;close the outer if

Try to make a function: 
(gee x)
- negative numbers turn positive
- zero becomes -1
- positive numbers become double their value.
(gee -3)  is 3
(gee -4) is 4
(gee 0) is -1
(gee 3) is 6
(gee 1.5) is 3.0


Try to make a function:
(calcGrade n) Where n is your grade, you get different results:
>= 90 : "Pass"
From 70 up to but not including 90: "Fail"
<70 : "Disown"



LAB/HW07: Monday 8am on the HW server: (As a comment)
This is a normal-sized assignment, but due to the holiday, if you have any plans that would make you unable to complete it by Monday, please provide a reason when you submit it. 

Directions: Write the following functions in Scheme, including the test cases you used to verify they work:
1.
(isBetween a b n)  where a b and n are all numbers.
    -Return #true when n is strictly between (not equal) a and b.
    -Return  #false otherwise
    -Note: a can be smaller larger or equal to b.
    -Restriction: Scheme allows you to say (< a b n)  to represent  a < b < n, but you should avoid this construct and use your knowledge of compound inequalities!

2.
(xor a b) where a and b are boolean values. This is similar to the or function, but is the exclusive or.

Since it is a boolean function  you can use #true and #false as arguments, and you can only use and/or/not, to operate on the parameters.

Returns: 
    #true when a and b have different truth values.
    #false when they are both the same.
e.g.
(xor #true #true) -> #false
(xor #true #false) -> #true

Restriction: Do this using the three operations:
      and, or, not 
     (There is another easy way to do it but that avoids the heart of the problem.)



3. 
Write a function (alarmTime day isVacation)
Given a day encoded as:
0=Sun, 1=Mon, 2=Tue, ...6=Sat, 
and a boolean isVacation indicating if we are on vacation, return an integer indicating when the alarm clock should ring. 
-Weekdays, the alarm should be 7
-Weekend it should be 10 
-Unless we are on vacation (isVacation is #true) 
Vacation mode changes the times to be:
   -Weekdays should be 10
   -weekends should be 12.

4. Write a function (gradeFix n) such that:
n >=90  return the same number back
n > 86 and n< 90 return an 88
n >82 and n<=86 return an 85
All other cases return a 50.
Comments