Homework 5 Solution

$30.00 $24.00

Introduction In this assignment, you will implement a calculator using Scheme. For the assignment you can use The MIT Scheme interpreter which is installed on our UNIX systems (e.g. ow.sabanciuniv.edu) or you can install and use a MIT Scheme interpreter for Windows. The Task The assignment is divided into several parts. Each part is connected…

5/5 – (1 vote)

You’ll get a: zip file solution

 

Categorys:
Tags:

Description

5/5 – (1 vote)
  • Introduction

In this assignment, you will implement a calculator using Scheme. For the assignment you can use The MIT Scheme interpreter which is installed on our UNIX systems (e.g. ow.sabanciuniv.edu) or you can install and use a MIT Scheme interpreter for Windows.

  • The Task

The assignment is divided into several parts. Each part is connected to another and by combining them, you will obtain a left-associative calculator in Scheme:

  1. Write a procedure named twoOperatorCalculator which will calculate left-associative in x addition and subtraction operations. Operations are given as a list and the output should be the result of these operations. Below is a sample output for this procedure:

1 ]=> (twoOperatorCalculator 0(1 + 15 32=5 + 2))0 V alue : 38=5

  1. Write a procedure named fourOperatorCalculator which will calculate left-associative in x multiplication and division operations. Operations are given as a list and the out-put should be a list which contains in x addition, in x subtraction operations and the results of multiplication and division operations. Below is a sample output for this procedure:

1 ]=> (fourOperatorCalculator 0(1 + 3

5

4=5

8 + 2

1))0

V alue : 15 : (1 + 15 32=5 + 2)0

3. Write a procedure named calculatorNested which will calculate operations in nested

1

lists. Some operations may have precedence over other operations and these operations are represented using nested lists. This procedure should calculate the operations inside nested lists and return a list which contains in x addition, subtraction, multiplication, division operations and the results of nested lists. Below is a sample output for this procedure:

1 ]=> (calculatorNested

0(1 +

(1+1 2) 5 4=5 8+(5 3) 1))0

V alue : 13

:(1+3

5

4=5 8

+ 2

1)

1 ]=> (calculatorNested

0(1 +

2

(2

(3 + 5)=2)))0

V alue : 24

:(1+2

2)

Note that there can be nested lists inside other nested lists. In this case calcula-torNested should calculate all nested lists.

  1. Write a procedure named checkOperators which will make an input check for the calculator. Allowed operations on the calculator are in x addition, in x subtraction, in x multiplication and in x division. These operations are given as elements of a list. The list can also contain nested lists which can have their own calculations. Below is a sample output for this procedure:

1 ]=> (checkOperators 0(1 + (1 + 1

2)

5

4=5

8+(5 3)

1))

V alue : # t

  1. Write a procedure named calculator which will calculate in x addition, subtraction, multiplication and division operations. Operators should be left-associative. Multipli-cation and division should have precedence over addition and subtraction. Operations surrounded by parenthesizes should have precedence over other operations. Operations are given as a list. The procedure should rst check whether the given list is syntacti-cally correct. If the list is not syntactically correct, then the procedure should return false, otherwise it should calculate the operations and give the output as a result. Be-low is a sample output for this procedure:

1 ]=> (calculator0(1 + (1 + 1

2)

5

4=5

8+(5 3)

1))

V alue : 38=5

Please use recursion and use let and let in your code only for debugging purposes.

2

  • How to Submit

    • On SUCourse, submit your .scm le using the following format: id-hw5.scm. DO NOT compress/bundle/archive.

    • Important: SUCourses clock may be o a couple of minutes. Take this into account to decide when to submit.

    • No homework will be accepted if it is not submitted using SUCourse.

    • You must write your les by yourself.

    • Start working on the homework immediately.

    • Good luck 🙂

3

Homework 5 Solution
$30.00 $24.00