Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSE240 Lecture 27

CSE240 Lecture 27

Introduction to Programming Languages
Final Review
(202204)

Javier Gonzalez-Sanchez

January 27, 2017
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. jgs CSE 240 Introduction to Programming Languages Lecture 27: Final

    Review Dr. Javier Gonzalez-Sanchez [email protected] javiergs.engineering.asu.edu | javiergs.com PERALTA 230U Office Hours: By appointment
  2. jgs The following slides shows some examples related to some

    topics This is NOT a comprehensive list of topics Topics in the exam can be found Weeks 1 to 8
  3. Javier Gonzalez-Sanchez | CSE240 | Spring 2020 | 3 jgs

    Topics § Programming Languages Concepts § C § C++ § LISP § Prolog 2 or 5 questions per topic. Most of them involve programming
  4. Javier Gonzalez-Sanchez | CSE240 | Spring 2020 | 5 jgs

    C recursion #include <stdio.h> void fun(int x) { if (x>0) { printf("%d", x); fun(x-1); printf("%d", x); } } int main() { fun(5); }
  5. Javier Gonzalez-Sanchez | CSE240 | Spring 2020 | 6 jgs

    C/C++ pointers § What delete expression correspond to the expression ptr=new int[100]
  6. Javier Gonzalez-Sanchez | CSE240 | Spring 2020 | 8 jgs

    LISP § What is the output of the following code? (let ((x '(1 2)) (y '(9 10))) (print (+ (first x) (first y)) ) )
  7. Javier Gonzalez-Sanchez | CSE240 | Spring 2020 | 9 jgs

    LISP 1. Create a function that receives a list and return the lowerst value 2. Create a function that receives a list and an integer and return “true” if the number exist in the list 3. Create a function that receives a list and return “true” if the list contains a palindrome. such as (a b c d e d c b a) 4. Create a variable in Lisp to store a tic-tac-toe, such as x E x 0 X 0 E x E
  8. Javier Gonzalez-Sanchez | CSE240 | Spring 2020 | 10 jgs

    LISP 5. Create a function that receives the variable with the tic-tac-toe and return “true” if there is an empty space (an “E” letter). 6. The following list represent a tree '(a (b () ()) (c (d () () ) (e () ()) ) ) Create a function (recursive) that traverse the tree and print all the elements as A B C D E. 7. What is printed by the following code? (setf route '(boston cambridge lincoln concord)) (print (first (rest route)))
  9. Javier Gonzalez-Sanchez | CSE240 | Spring 2020 | 11 jgs

    LISP 8. What is the output of the following code? (let ((x '(1 2)) (y '(9 10))) (print (+ (first x) (first y)) ) ) 9. What is printed by the following code? (defun fun(n) (if (= n 0) () (fun (- n 1)) ) n ) (print (fun 5)) 10. What is equivalent code in C++ for the following LISP statement (if (< 1 2) (+ 3 4) (- 5 6) )
  10. Javier Gonzalez-Sanchez | CSE240 | Spring 2020 | 12 jgs

    LISP 1. A function test-min that returns the lower value in a List of numbers (test-min L) 2. A function test-average that returns the average of all values in a List of numbers (test-average L) 3. A function test-fibonacci that prints the first n elements of the fibonacci series (test-fibonacci n) 4. A recursive function that returns the leftmost even element in a list of numbers (test-even L) 5. A functions that traverse a list and returns how many of its elements are 0 (test-count-zeros L) 6. A recursive function that return the N member of a list L (assuming that the elements are numbered from zero onwards): (test-get n L) 7. A recursive function that returns non-NIL if x is a member of the list L. (test-is-in-list x L)
  11. Javier Gonzalez-Sanchez | CSE240 | Spring 2020 | 14 jgs

    Q1 What is the predicate logic expression equivalent to "Charlie owns a computer" owns(charlie, computer).
  12. Javier Gonzalez-Sanchez | CSE240 | Spring 2020 | 15 jgs

    Q2 instructor(john,cs365). instructor(mary,cs311). enrolled(danielle,cs365). enrolled(danielle,cs446). § Which query provides a list of all the students enrolled in cs365? enrolled(Who, cs365).
  13. Javier Gonzalez-Sanchez | CSE240 | Spring 2020 | 16 jgs

    Q3 If weather is cold, everyone likes it. Write this statement as a Prolog clause. likes(X, weather) :- cold(weather). %notice “weather” in lowercase
  14. Javier Gonzalez-Sanchez | CSE240 | Spring 2020 | 17 jgs

    Q5 § Given the following facts § cat(tom). § black_spots(tom). § dog(pluto). § white_spots(pluto) § Which rule defines in Prolog the following sentence: § "mary owns a Pet if it is a cat and it has black spots" owns(mary, Pet):- cat(Pet), black_spots(Pet).
  15. Javier Gonzalez-Sanchez | CSE240 | Spring 2020 | 18 jgs

    Q6 Which rule defines in Prolog the following sentence: "If someone owns something, he loves it" loves(Who, What):-owns(Who, What).
  16. Javier Gonzalez-Sanchez | CSE240 | Spring 2020 | 21 jgs

    Test Yourselves § A recursive function rec is defined as follows Write a set of rules in Prolog to define the solution to this function. ï î ï í ì ³ - - + - = £ = 3 ) 3 ( * ) 2 ( ) 1 ( 2 1 1 0 ) ( n n rec n rec n rec n n n rec
  17. jgs CSE 240 Introduction to Programming Languages Javier Gonzalez-Sanchez, Ph.D.

    [email protected] Fall 2021 Copyright. These slides can only be used as study material for the class CSE240 at Arizona State University. They cannot be distributed or used for another purpose.