2015-09-29 LAB + HW07

posted Sep 29, 2015, 5:57 AM by Samuel Konstantinovich   [ updated Sep 29, 2015, 5:13 PM ]
HW07: 
Submit a file on the homework server by Thursday October 1st at 6am.
;-You are still responsible for completing your labs even if there is homework assigned.
;-Include your header on the file
;-Your entire file must be run-able scheme code. Any problem numbers or English text should be commented out with;
;-You should include test cases to demonstrate that you tested your code.
;-You MUST re-use functions instead of re-typing parts of the solution in later problems. This only applies if there is something to re-use.

Define the following 3 functions in scheme. They should work as instructed, and you may need more thorough tests to verify that they work. 
1.
 (SumOfSquares a b) takes numeric inputs a, b and returns the sum of their squares.
e.g.,
(SumOfSquares 0 0) → 0
(SumOfSquares 1 2) → 5
(SumOfSquares 4 5) → 41 

2.
(ArithMean3 a b c) takes numeric inputs a, b, c and returns their arithmetic mean.
e.g.,
(ArithMean3 0 0 0) → 0
(ArithMean3 1 2 3) → 2
(ArithMean3 5 -10 20) → 5

3.
(HarMean3 a b c) takes numeric inputs a, b, c and returns their harmonic mean. (Harmonic mean is the reciprocal of the arithmetic mean of the reciprocals.)
e.g.,
(HarMean3 5 5 5) → 5
(HarMean3 3 6 18) → 5.4
(HarMean3 5 -10 20) → 20


Do Now:


Translate to scheme:
3 - 2 ( 4 - 1 ) + 6 / (8 + 4)

Reminder:
Scheme has operations like
(abs x) ;absolute value
(sqrt x) ;sqrt

Lab:
How can you calculate the maximum of two values using only:
 + - * / abs

so   using those operations on X and Y
if X = 5 and Y = 12, the result of the expression should be 12.
if X = 12 and Y = 5, the result of the expression should be 12.


Hint:  You need abs, and if you need abs, there is another operator you will most likely need. 


After you figure out a formula:
Write the following scheme functions:  Log in and use drracket
(myMax a b)  evaluates to the larger of the two numbers
(max3 a b c)  evaluates to the largest of the three numbers
(max4 a b c d)  evaluates to the largest of the four numbers

Before the end of the period email yourself the lab.
Press the ubuntu start menu circle (top left)
Type: network    and click on the network icon.
click on Network Proxy, switch it to manual then fill in:
HTTP:   149.89.1.30      port 3128
HTTPS:   149.89.1.30      port 3128
Comments