CS/CE 4337 Homework 04 Spring 2021 Homework 04 Answer the questions below, and submit electronically via elearning. Make sure you submit a couple hours early at the latest and double check your...

1 answer below »
This is an Organization programming languages assignment. the question need to be programmed in Prolog, I need screenshots of compiling and running code along with solution. The Assignment that need to be done is HW 5. Chapter 16: 9,10,11,12. 4 questions in total. Also I will attach the HW 3 solution here, so that the expert can refer to them incase require because the questions refer to hw 3.


CS/CE 4337 Homework 04 Spring 2021 Homework 04 Answer the questions below, and submit electronically via elearning. Make sure you submit a couple hours early at the latest and double check your submission to ensure everything is in order before the submission time. Your answers should be submitted as a “.doc”, “.docx”, or “.pdf” file. Your answers should be typed, but scans or pictures of hand drawn figures and diagrams may be included in the file when needed. Code should be turned in as plain text source code. REMINDER: In prolog, a predicate can be referred to by its functor and arity(number of arguments) by writing its functor, followed by a slash, and then the arity. Due: Saturday, May 8 11:59pm Chapter 11: 1. (4pt) Why are destructors not as frequently needed in Java as they are in C++? 2. (4pt) Explain the three reasons accessors to private types are better than making the types public. 3. (4pt) What are the differences between a C++ struct and a C# struct? 4. (4pt) What is a C# assembly? 5. (4pt) Describe the two problems that appear in the construction of large programs that led to the development of encapsulation constructs. 6. (4pt) What is the advantage of using a C++ namespace? 7. (4pt) What is a Java package, and what is its purpose? Chapter 16: Implementing Subprograms 1. (4pt) Briefly describe the two parts of a compound term? 2. (4pt) Briefly describe “antecedents” and “consequences”. 3. (4pt) Give general (not rigorous) definitions of resolution and unification. 4. (4pt) What are the forms of Horn clauses? 5. (4pt) What are the three forms of a Prolog term? How are they handled during unification? 6. (4pt) Explain how backtracking works in Prolog. 7. (4pt) Explain the negation problem with Prolog. Why is this a limitation? 8. (4pt) What is the basic concept of declarative semantics? Organization of Programming Languages Page 1 CS/CE 4337 Homework 04 Spring 2021 9. (10pt) For this question you will implement a predicate that computes the area of a shape (Just like in Homework 3) in prolog. Each shape will be represented by a structure in the following formats: • Circle: circle(Radius) • Rectangle: rectangle(Width Height) • Triangle: triangle(base height) 10. (10pt) This question is based on the one from homework 3. Consider a list where every element is a nested list of length 2. The first element of each nested list is either a 0 or a 1. The second element of each nested list is some integer. As an example: [[0 1] [1 2] [1 3] [0 4] [0 3]] For the purposes of this question, let’s call the first element of each nested list the key and the second element of the nested lists the value. In prolog, implement a predicate, count by cat/2, that takes such a list as input and yields a two element list where • the first element is the sum of the values of all nested lists with 0 as the key, and • the second element is the sum of the values of all nested lists with 1 as the key It may be helpful to create helper functions. 11. (10pt) Encode the following knowledge as prolog rules and facts. • Alice has an A in class • Brian has an B in class • Carrie has an C in class • David has an A in class • Erica has an B in class • Frank has an C in class • Gina has an B in class • With an A or a B, a student has a good grade • With an A, a student has a great grade Write a query that asks “Who is a good student?”. (More on next page) Organization of Programming Languages Page 2 CS/CE 4337 Homework 04 Spring 2021 12. (10pt) Add the best students/1, and best students/2 predicates to your code for question 11. • If there is at least one student with a great grade, then best student/1 will be true for students that have a great grade. Otherwise, if there is no student with a great grade then best students/1 will be true for students with a good grade. • The two arguments to best students/2 should be different students. If there are at least two students with a great grade, then best students/2 is true for any pair of such students. Otherwise, it is true if the first argument will make best students/1 true, and the second is a student with a good grade. Organization of Programming Languages Page 3
Answered 8 days AfterMay 04, 2021

Answer To: CS/CE 4337 Homework 04 Spring 2021 Homework 04 Answer the questions below, and submit electronically...

Swapnil answered on May 06 2021
138 Votes
83035/explanation.docx
Chapter 16: Implementing Subprograms
        9
        For this question we need to find out the implementation of the area of shapes. So that each shape can give the different formats of following.
Circle:
We need to find the area of circle shapes using the program so the program gives us the detailed information about circle. Here we are using the 4 statement that can gives the domain, predicates, goal and clause statement.
· We have selected these 4 statement because
these statement will help us to find the area of circle.
· We next pass the arguments that can predict the name for this (predicate_name (arg1, arg2, arg3,..., argn)
· The predicates function will give us the detailed statement about how to add two integers (here we can add upto 2 integers that is mentioned in the add_upto function.
· Next we are using the clauses function.
· Here we can add the upto 1,1 integers so that can give the circle prediction of it.
· Again we can add_upto N integers where it will help us to finding the result if and only if condition satisfy.
· If the condition gives N>=2 here we are checking the N integers can give the condition should be greater than or equal to 2.
· So when finding the prediction, it will help us to N_1 so the result can be stored in the N-1 integer.
· Next we will check fir N_1 integer that can be added into the result.
· So the Result will give us the Res+N where it will stored into it.(Res+N).
· Next we will check for the goal function
· The goal function will give us the sub goal and it will help us to finding the prediction of shapes of circle.
· We can add the 3 sub goals into the result. So while radius will give the goals to finding the result.
· So the result will give us the 6 as the sub goals and that will give by the radius.
· So next we will get the final text for the radius of the circle. For this we need to find the radius of the circle and it can use the formula A = π r².
· So here pi values can be used to calculating the result.
· And double will give us the 2 as the radius for it.
· Next we will use the predicates function to get the output for the integer and the real values.
· So the output function can give us the integer and the real function.
· Next we will use the clauses for printing the output.
· We will use the output (0, _) integers to get the output values.
· Here 0, can give the initial values and the _ will give us the resulting condition.
· The output can be uses the (N, R) if N > 0 this condition will give us the output for the N and the Result in case the condition satisfies for the N > 0.
· So now will use the formula for getting the circular area and that can give the diameter of it. (C=2*pi*R,)
· Now we will get the area for pi into the radius.
· So now we will print circumference and the area to get the result.
· So now the R1 will give the double*R for the reading the input from it.
· Next the output (N1, R1) will give us the output for the N1, R1 for it.
· Next we will check for the predicate statement.
· For this we will use the factorial function using the integer and the real parameters.
· Now we will use the write function to print the positive integer number.
· It will read the N values for it.
· Now the factorial formula we can use for the calculating the factorial numbers for getting the final result that can give us the area of circle and its shapes.
· Now we can use the factorial number that can basically give the condition N>0.
· So after that we can calculate the n1 values for the factorial function.
· And finally we can store the result into the Result function that has been calculated using N*Res function.
Rectangle:
Now we will check for the rectangle function.
· We will define the rectangle area using the a, b parameters.
· Next we will check for the return condition using (a*b)
· Next we will define the rectangle perimeter using the a, b parameters.
· Again we will return the perimeter for the rectangle 2 * (a + b).
· Now we will set the values for a and b respectively.
· Now we will print the area and the perimeter for it.
Triangle:
Now we will check fir the triangle function.
· For triangle we will be using the areaRectangle and perimeterRectangle functions.
· We will define the rectangle area function using a, b parameter.
· We will return the a * b values for the triangle
· Next we will define the rectangle perimeter function using a, b parameters.
· Next we will set the values for a and b respectively.
· And finally we will print he area and the perimeter values using the defined functions and we will get the triangle for it.
        10
        In this problem we are considering the list for every element that is nested list of length 2. Here we need to find the first element to the nested list that can be 0 or 1. And the second element of each nested list in some integer.
The program explanation:
·...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here