#### Description of this paper

##### CSE 240 Homework 13, Spring 2016 (50 points) Due Saturday, April-(Answered)

Description

Question

I need help doing my assignment using different languages.

CSE 240 Homework 13, Spring 2016 (50

points)

Due Saturday, April 30, 2016 at 11:59PM, plus one day grace period.

Note: No late submission for the last homework.

The submission link will be disable at 11:59pm on Sunday, May 1, 2016

Introduction

The aim of this assignment is to make sure that you understand and are familiar with the

concepts covered in the lectures. By the end of the assignment, you should have exercised

Prolog list operations and manipulations

Prolog recursive rules with multiple nested calls

Recursion in C++, Scheme and Prolog

Reading: Chapter 5 and lecture slides.

You are expected to do the majority of the assignment outside the class meetings. Should you

TA during their office hours.

You are encouraged to ask and answer questions on the course discussion board. (However, do

CSE240 ? Introduction to Programming Languages

Homework 13

1|Page

Programming Assignment (50 points)

1

Complete the code for the following problem in C++, Scheme, and Prolog.

foo ( x )=

{

x

x?1

[30 points]

0

if x=0

+ foo ( x?1) if x &gt;0

For example: foo(5) = 54 + 43 + 32 + 21 + 10 = 701

You must use recursion. Follow the Fantastic Four-Step Abstract approach. You must

indicate the steps in the comments for all parts. (Note, a Prolog rule does not return a

value. You need to use a parameter to hold the return value.)

2

1.1 C++

[10 points]

1.2 Scheme

[10 points]

1.3 Prolog

[10 points]

Joey has 40 dollars to spend. He decides to go to the store and spend all 40 dollars. The

available items are listed below with their corresponding values. He can buy multiples of

each item, as long as his total cost is equal to 40.

[20 points]

Item

Candy

Hat

Game

Music CD

Toy

Cost (dollars)

2

6

12

8

5

For example, Joey can purchase 2 Games, and 2 Music CDs: 2*12 + 2*8 = 40

Joey cannot purchase 4 Games: 4*12 = 48 &gt; 40

Joey cannot purchase only 3 Games: 3*12 = 36 &lt; 40

2.1

Define a rule purchase(C, H, G, M, T) to find out how many of each item can be purchased

with 40 dollars, where C, H, G, M, and T are the costs (in dollars) of the Candy, Hat,

Game, Music CD, and Toy respectively. (Assume there is no sales tax).

[15]

2.2

Use your purchase rule to find all possible outputs to the following question (goal).

[2]

| ?- purchase(3, 1, G, M, 2). Put all answers of the question in comment.

2.3

Use your purchase rule to find all possible outputs to the following question (goal).

CSE240 ? Introduction to Programming Languages

Homework 13

[3]

2|Page

| ?- purchase(C, 1, 1, 1, T). Put all answers of the question in comment.

Special note for prolog execution: after you have successfully compiled the code and

entered prolog environment, you will start to execute the program. But [Question1]. will not

work as the file name includes an upper case letter. Hence, you will need to include a single

quotation to resolve this issue (e.g., [?Question1?].). The same for Question2 file.

(1) The TA will read your program and give points based on the points allocated to each

inclusion of the required functions, and correctness of the implementations of each function.

(2) Compile the code. If it does not compile, 20% of the points given in (1) will be deducted. For

example, if you are given 20 points in step (1), your points will become 16 if the program fails to

compile.

(3) If the code passes the compilation, the TA will execute and test the code. If, for any reason,

the program gives an incorrect output or crashes for any input, 10% of the points given in (1)

will be deducted.

What to Submit?

You are required to submit your solutions in a compressed format (.zip). Make sure your

compressed file is label correctly - lastname_firstname13.zip.

The compressed file MUST contain the following:

Question1.cpp

Question1.rkt

Question1.pl

Question2.pl

The files must contain the rules and the outputs of the goals. No other files should be in the

compressed folder.

If multiple submissions are made, the most recent submission will be graded. (Even if the

assignment is submitted late.)

Where to Submit?

All submissions must be electronically submitted to the respected homework link in the course

CSE240 ? Introduction to Programming Languages

Homework 13

3|Page

Late submission deduction policy

No penalty for late submissions that are received within 24 hours after the deadline;

No late submission after Sunday at 11:59PM.

CSE240 ? Introduction to Programming Languages

Homework 13

4|Page

Paper#9210117 | Written in 27-Jul-2016

Price : \$22