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