Question

SCHEME :-) [5 marks] Write a procedure called convert that takes as arguments: a temperature value...

SCHEME :-)

  1. [5 marks] Write a procedure called convert that takes as arguments: a temperature value (number), and two strings representing the input and output units respectively. The procedure should support conversions to or from any combination of Celcius ("C"), Fahrenheit ("F"), and Kelvin ("K"). Any other unit argument should result in the return of an error string.
    A table of temperature conversion equations and a calculator for verification can be found here.
    (Note: to compare strings in Scheme you can use the predicate (equal? str1 str2). To concatenate strings you can use the function (string-append str1 str2 ...).)
    E.g. (convert 32 "C" "F") → 89.6
    E.g. (convert 32 "apples" "oranges") → "Could not convert from apples to oranges"
0 0
Add a comment Improve this question Transcribed image text
Answer #1

(define (convert temp x y)
   (cond ((and (real? temp)
               (or (equal? "C" x) (equal? "F" x) (equal? "K" x))
               (or (equal? "C" y) (equal? "F" y) (equal? "K" y)))
           (cond
               ((and (equal? "C" x) (equal? "F" y)) (+ (* temp 1.8) 32))
               ((and (equal? "C" x) (equal? "K" y)) (+ temp 273.15))
               ((and (equal? "F" x) (equal? "C" y)) (/ (- temp 32) 1.8))
               ((and (equal? "F" x) (equal? "K" y)) (+ (/ (- temp 32) 1.8) 273.15))
               ((and (equal? "K" x) (equal? "C" y)) (- temp 273.15))
               ((and (equal? "K" x) (equal? "F" y)) (+ (* (- temp 273.15) 1.8) 32))
           ))
       (else "Could not convert from apples to oranges")
   )
)

Add a comment
Know the answer?
Add Answer to:
SCHEME :-) [5 marks] Write a procedure called convert that takes as arguments: a temperature value...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • SCHEME [3 marks] Define a procedure called days_in_month that takes as arguments two numbers representing a...

    SCHEME [3 marks] Define a procedure called days_in_month that takes as arguments two numbers representing a month and a year. The procedure should return the number of days in the given month. Note: the procedure should account for leap years. You may assume valid month and year values are passed in as arguments. E.g. (days_in_month 9 2019) → 30 E.g. (days_in_month 2 2019) → 28 E.g. (days_in_month 2 2020) → 29

  • FOR PYTHON Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice...

    FOR PYTHON Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The program should use two custom functions, f_to_c and c_to_f, to perform the conversions. Both of these functions should be defined in a custom module named temps. Custom functionc_to_f should be a void function defined to take a Celsius temperature as a parameter. It should calculate and print the equivalent Fahrenheit temperature accurate to three decimal places. Custom function f_to_c should be a...

  • Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The...

    Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The program should use two custom functions, f_to_c and c_to_f, to perform the conversions. Both of these functions should be defined in a custom module named temps. Custom function c_to_f should be a void function defined to take a Celsius temperature as a parameter. It should calculate and print the equivalent Fahrenheit temperature accurate to three decimal places. Custom function f_to_c should be a value-returning...

  • i need a python code For an exact conversion between "Fahrenheit temperature scale" and "Celsius temperature...

    i need a python code For an exact conversion between "Fahrenheit temperature scale" and "Celsius temperature scale", the following formulas can be applied. Here, F is the value in Fahrenheit and the value in Celsius: Temperature Conversions C = 5 9 (F - 32) F = (š xc) + 3 Write a Python program that uses the above formula to convert Celsius to Fahrenheit and vice versa. We ask user to input "Enter a degree: ", and then we get...

  • In java Se8 i am trying to write a program convert temperature between celsius, fahrenheit and...

    In java Se8 i am trying to write a program convert temperature between celsius, fahrenheit and kelvin, but i am stuck at how to return the proper result without chage the frame, and I cnould not figure out how to use those three settemp method. import java. uti1. Arrays public class Temperature different scale names/ public static Stringll scales -Celsius", "Fahrenheit", "Kelvin private double temperature private char scale; public Temperature (double temp temp 273. 15; this. scale-C if (temp <-273....

  • Question 1 An array is NOT: A - Made up of different data types. B - Subscripted by integers. C -...

    Question 1 An array is NOT: A - Made up of different data types. B - Subscripted by integers. C - A consecutive group of memory chunks. D - None of the choices. Question 2 How many times is the body of the loop executed? int i=1; while(true) { cout << i; if(++i==5) break; } A - Forever B - 4 C - 5 D - 6 E - 0 Question 3 What is wrong with the following piece of...

  • In Problem Set 7 you designed and implemented a Message class. This time, let's design and...

    In Problem Set 7 you designed and implemented a Message class. This time, let's design and implement a Mailbox class in a file named Mailbox java. Do the following with this class • You may use the Message class from PS 7. You will have to add new features to the Message class from PS 7 as you work through this problem. You are welcome to start with my sample solution if you wish • Suppose there are multiple mail...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT