SlideShare a Scribd company logo
CSE240 – Introduction to
Programming Languages
Lecture 26:
Final Review
Javier Gonzalez-Sanchez
javiergs@asu.edu
javiergs.engineering.asu.edu
Office Hours: By appointment
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 2
Final Grades
• 25% Midterm exam
• 25% Final exam
• 25% Quizzes. 9 quizzes then 2.777 per quiz.
• 25% Homework. 6 homework then 4.166 per homework.
• 4% Extra points (3 + 1).
• 97 A+ |93 A- | 89 A| 85 B+ | 81 B| 77 B-| 73 C+|69 C| 65 D | E
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 3
Current Grades
0
2
4
6
8
10
12
A+ A A- B+ B B- C+ C D E
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 4
Topics
• Programming Languages Concepts
• C
• C++
• LISP
• Prolog
2 or 3 questions per topic. Most of them involve programming
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 5
Quiz
# Topic %
1 Prolog Fact 2
2a Prolog Recursive 0
2b Prolog Recursive 2
3 Lisp 0
4 Lisp 3
5 C/C++ pointers 5
6 Introduction *
7 Introduction *
8 C++ 2
9 C recursion 5
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 6
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);
}
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 7
C/C++ pointers
• What delete expression correspond to the expression
ptr=new int[100]
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 8
LISP
• What is the output of the following code?
(let ((x '(1 2)) (y '(9 10)))
(print (+ (first x) (first y)) )
)
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 9
Prolog
Facts
• mother_child(trude, sally).
• father_child(tom, sally).
• father_child(tom, erica).
• father_child(mike, tom).
Rules
• sibling(X, Y) :- parent_child(Z, X), parent_child(Z, Y).
• parent_child(X, Y) :- father_child(X, Y).
• parent_child(X, Y) :- mother_child(X, Y).
Query
• ?- sibling(sally, erica).
Yes
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 10
Prolog
fib(0, 0).
fib(1, 1).
fib(X, Y) :- X > 1,
X2 is X – 2, fib(X2, Y2),
X1 is X – 1, fib(X1, Y1),
Y is Y1 + Y2.
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 11
Fibonacci
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 12
Recursion
% this is fact
factorial(0, 1).
% this is a rule
% the factorial of F is N*F1
% if N>0 and
% N1 is N-1 and
% the factorial of N1 is F1
factorial(N, F) :-
N>0,
N1 is N - 1,
factorial(N1, F1),
F is N * F1.
?- factorial (3, W).
W=6
1. factorial(3, W)
apply rule 2
2. 3>0, N1 is 3-1, factorial (N1, F1), F is 3 *F1
solve the individual parts
true, 2 is 3-1, factorial (2, F1), F is 3*F1
apply rule 2 again
3. 2>0, N2 is 2-1, factorial (N2, F2), F1 is 2 * F2
solve the individual parts
true, 1 is 2-1, factorial (1, F1), F1 is 2*F2
apply rule 2 again
4. 1>0, N3 is 1-1, factorial (N3, F3), F2 is 2 * F3
solve the individual parts
true, 0 is 1-1, factorial (0, F3), F2 is 1*F3
apply rule 1
5. factorial (0, 1)
F3 is 1
6. Go back, replace F3 to get F2, then F2 to get F1,
then F1 to get F.
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 13
Recursion
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 14
Prolog
• doSomething(A,B,P) :- P is A + B.
?-doSomething(3,2,P).
?-doSomething(3,2,10).
CSE240 – Introduction to Programming Languages
Javier Gonzalez-Sanchez
javiergs@asu.edu
Fall 2017
Disclaimer. These slides can only be used as study material for the class CSE240 at ASU. They cannot be distributed or used for another purpose.

More Related Content

PDF
201801 CSE240 Lecture 24
PPT
9.4 part 4.ppt worked
PDF
201707 CSE110 Lecture 05
PDF
Module 2 lesson 7
PPT
Fun with calculations
PDF
Grade 8 lesson 9
PPTX
Nsc mathematics grade 12 2018 nov paper 1 1
PPT
St. James Data overview version 1
201801 CSE240 Lecture 24
9.4 part 4.ppt worked
201707 CSE110 Lecture 05
Module 2 lesson 7
Fun with calculations
Grade 8 lesson 9
Nsc mathematics grade 12 2018 nov paper 1 1
St. James Data overview version 1

What's hot (7)

PDF
Module 2 lesson 2
PDF
Lesson 5 day 2
PDF
Module 2 lesson 1
PPTX
Adding Integers
PDF
Module 1 lesson 20 day 2
DOCX
Story filmstrip
DOCX
G6 m4-h-lesson 30-t
Module 2 lesson 2
Lesson 5 day 2
Module 2 lesson 1
Adding Integers
Module 1 lesson 20 day 2
Story filmstrip
G6 m4-h-lesson 30-t
Ad

Similar to 201801 CSE240 Lecture 26 (20)

PDF
201801 CSE240 Lecture 25
PDF
201801 CSE240 Lecture 17
DOCX
CSC8503 Principles of Programming Languages Semester 1, 2015.docx
PDF
201505 CSE340 Lecture 02
PDF
201801 CSE240 Lecture 19
PDF
HSC ICT: Chapter 5 Board MCQ Solution
PDF
201801 CSE240 Lecture 23
PDF
062636636366363773737373733+73737733+7.pdf
PDF
201801 CSE240 Lecture 21
PPTX
Prolog 7-Languages
PDF
04. haskell handling
PDF
Clqr a4-consec
PPTX
Introduction to Prolog
DOCX
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
DOCX
Important C program of Balagurusamy Book
PDF
201707 CSE110 Lecture 33
DOCX
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
DOCX
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
PDF
201801 CSE240 Lecture 01
PDF
Solution Manual for Python for Everyone 2nd Edition Horstmann
201801 CSE240 Lecture 25
201801 CSE240 Lecture 17
CSC8503 Principles of Programming Languages Semester 1, 2015.docx
201505 CSE340 Lecture 02
201801 CSE240 Lecture 19
HSC ICT: Chapter 5 Board MCQ Solution
201801 CSE240 Lecture 23
062636636366363773737373733+73737733+7.pdf
201801 CSE240 Lecture 21
Prolog 7-Languages
04. haskell handling
Clqr a4-consec
Introduction to Prolog
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
Important C program of Balagurusamy Book
201707 CSE110 Lecture 33
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
201801 CSE240 Lecture 01
Solution Manual for Python for Everyone 2nd Edition Horstmann
Ad

More from Javier Gonzalez-Sanchez (20)

PDF
201804 SER332 Lecture 01
PDF
201801 SER332 Lecture 03
PDF
201801 SER332 Lecture 04
PDF
201801 SER332 Lecture 02
PDF
201801 CSE240 Lecture 22
PDF
201801 CSE240 Lecture 20
PDF
201801 CSE240 Lecture 18
PDF
201801 CSE240 Lecture 16
PDF
201801 CSE240 Lecture 15
PDF
201801 CSE240 Lecture 14
PDF
201801 CSE240 Lecture 13
PDF
201801 CSE240 Lecture 12
PDF
201801 CSE240 Lecture 11
PDF
201801 CSE240 Lecture 10
PDF
201801 CSE240 Lecture 09
PDF
201801 CSE240 Lecture 08
PDF
201801 CSE240 Lecture 07
PDF
201801 CSE240 Lecture 06
PDF
201801 CSE240 Lecture 05
PDF
201801 CSE240 Lecture 04
201804 SER332 Lecture 01
201801 SER332 Lecture 03
201801 SER332 Lecture 04
201801 SER332 Lecture 02
201801 CSE240 Lecture 22
201801 CSE240 Lecture 20
201801 CSE240 Lecture 18
201801 CSE240 Lecture 16
201801 CSE240 Lecture 15
201801 CSE240 Lecture 14
201801 CSE240 Lecture 13
201801 CSE240 Lecture 12
201801 CSE240 Lecture 11
201801 CSE240 Lecture 10
201801 CSE240 Lecture 09
201801 CSE240 Lecture 08
201801 CSE240 Lecture 07
201801 CSE240 Lecture 06
201801 CSE240 Lecture 05
201801 CSE240 Lecture 04

Recently uploaded (20)

PDF
top salesforce developer skills in 2025.pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
CHAPTER 2 - PM Management and IT Context
PPTX
Introduction to Artificial Intelligence
PDF
System and Network Administraation Chapter 3
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
AI in Product Development-omnex systems
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Transform Your Business with a Software ERP System
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
top salesforce developer skills in 2025.pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
CHAPTER 2 - PM Management and IT Context
Introduction to Artificial Intelligence
System and Network Administraation Chapter 3
wealthsignaloriginal-com-DS-text-... (1).pdf
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Design an Analysis of Algorithms II-SECS-1021-03
Odoo Companies in India – Driving Business Transformation.pdf
AI in Product Development-omnex systems
Softaken Excel to vCard Converter Software.pdf
Operating system designcfffgfgggggggvggggggggg
Transform Your Business with a Software ERP System
How to Choose the Right IT Partner for Your Business in Malaysia
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PTS Company Brochure 2025 (1).pdf.......
Design an Analysis of Algorithms I-SECS-1021-03
VVF-Customer-Presentation2025-Ver1.9.pptx

201801 CSE240 Lecture 26

  • 1. CSE240 – Introduction to Programming Languages Lecture 26: Final Review Javier Gonzalez-Sanchez javiergs@asu.edu javiergs.engineering.asu.edu Office Hours: By appointment
  • 2. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 2 Final Grades • 25% Midterm exam • 25% Final exam • 25% Quizzes. 9 quizzes then 2.777 per quiz. • 25% Homework. 6 homework then 4.166 per homework. • 4% Extra points (3 + 1). • 97 A+ |93 A- | 89 A| 85 B+ | 81 B| 77 B-| 73 C+|69 C| 65 D | E
  • 3. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 3 Current Grades 0 2 4 6 8 10 12 A+ A A- B+ B B- C+ C D E
  • 4. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 4 Topics • Programming Languages Concepts • C • C++ • LISP • Prolog 2 or 3 questions per topic. Most of them involve programming
  • 5. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 5 Quiz # Topic % 1 Prolog Fact 2 2a Prolog Recursive 0 2b Prolog Recursive 2 3 Lisp 0 4 Lisp 3 5 C/C++ pointers 5 6 Introduction * 7 Introduction * 8 C++ 2 9 C recursion 5
  • 6. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 6 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); }
  • 7. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 7 C/C++ pointers • What delete expression correspond to the expression ptr=new int[100]
  • 8. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 8 LISP • What is the output of the following code? (let ((x '(1 2)) (y '(9 10))) (print (+ (first x) (first y)) ) )
  • 9. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 9 Prolog Facts • mother_child(trude, sally). • father_child(tom, sally). • father_child(tom, erica). • father_child(mike, tom). Rules • sibling(X, Y) :- parent_child(Z, X), parent_child(Z, Y). • parent_child(X, Y) :- father_child(X, Y). • parent_child(X, Y) :- mother_child(X, Y). Query • ?- sibling(sally, erica). Yes
  • 10. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 10 Prolog fib(0, 0). fib(1, 1). fib(X, Y) :- X > 1, X2 is X – 2, fib(X2, Y2), X1 is X – 1, fib(X1, Y1), Y is Y1 + Y2.
  • 11. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 11 Fibonacci
  • 12. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 12 Recursion % this is fact factorial(0, 1). % this is a rule % the factorial of F is N*F1 % if N>0 and % N1 is N-1 and % the factorial of N1 is F1 factorial(N, F) :- N>0, N1 is N - 1, factorial(N1, F1), F is N * F1. ?- factorial (3, W). W=6 1. factorial(3, W) apply rule 2 2. 3>0, N1 is 3-1, factorial (N1, F1), F is 3 *F1 solve the individual parts true, 2 is 3-1, factorial (2, F1), F is 3*F1 apply rule 2 again 3. 2>0, N2 is 2-1, factorial (N2, F2), F1 is 2 * F2 solve the individual parts true, 1 is 2-1, factorial (1, F1), F1 is 2*F2 apply rule 2 again 4. 1>0, N3 is 1-1, factorial (N3, F3), F2 is 2 * F3 solve the individual parts true, 0 is 1-1, factorial (0, F3), F2 is 1*F3 apply rule 1 5. factorial (0, 1) F3 is 1 6. Go back, replace F3 to get F2, then F2 to get F1, then F1 to get F.
  • 13. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 13 Recursion
  • 14. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 14 Prolog • doSomething(A,B,P) :- P is A + B. ?-doSomething(3,2,P). ?-doSomething(3,2,10).
  • 15. CSE240 – Introduction to Programming Languages Javier Gonzalez-Sanchez javiergs@asu.edu Fall 2017 Disclaimer. These slides can only be used as study material for the class CSE240 at ASU. They cannot be distributed or used for another purpose.