Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Midterm Exam: SIMPLESEM Code and Prolog Predicate for Problem Solving, Exams of Computer Science

A midterm exam from a computer science course, consisting of two parts. The first part requires writing a simplesem code for a given program using the c3 language paradigm and entering data in the provided data segment. The second part involves writing a prolog predicate to sort a list into a nondecreasing order using the lesseq ordering. The document also includes sample code for bubblesort and merge sort algorithms.

Typology: Exams

2009/2010

Uploaded on 03/28/2010

koofers-user-hal
koofers-user-hal ๐Ÿ‡บ๐Ÿ‡ธ

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
๎˜๎˜‚๎˜ƒ๎˜„๎˜‚๎˜…๎˜†๎˜†๎˜‡๎˜ˆ๎˜„๎˜‰๎˜Š๎˜…๎˜ˆ๎˜„๎˜‹๎˜…๎˜„๎˜Œ๎˜
๎˜๎˜‚๎˜ƒ๎˜„๎˜‚๎˜…๎˜†๎˜†๎˜‡๎˜ˆ๎˜„๎˜‰๎˜Š๎˜…๎˜ˆ๎˜„๎˜‹๎˜…๎˜„๎˜Œ๎˜๎˜๎˜‚๎˜ƒ๎˜„๎˜‚๎˜…๎˜†๎˜†๎˜‡๎˜ˆ๎˜„๎˜‰๎˜Š๎˜…๎˜ˆ๎˜„๎˜‹๎˜…๎˜„๎˜Œ๎˜
๎˜๎˜‚๎˜ƒ๎˜„๎˜‚๎˜…๎˜†๎˜†๎˜‡๎˜ˆ๎˜„๎˜‰๎˜Š๎˜…๎˜ˆ๎˜„๎˜‹๎˜…๎˜„๎˜Œ๎˜๎˜‰
๎˜‰๎˜‰
๎˜‰
Midterm Exam
February 25, 2005
(100 pts.)
1. (80pts) (a) (50 pts.) Write a complete SIMPLESEM code for the following program using the
C3 language paradigm. (b) (30pts.) Manually run the resulting code and enter all the data in
the data segment. Enter your code and data in the table provided below. Use pencil so that
you can easily make necessary corrections. Use back sides of pages for scratch notes.
int m = 4; int n = 16;
main()
{
int m = 100
if (n > 10 & m > 83) m = f()
else m = 0
}
int f()
{
int k = 3, int n = 4
if (m == 1) return 4
else
{ n = m-- + k
return ( n * f())
}
}
๎˜Ž๎˜ƒ๎˜†๎˜๎˜‹๎˜๎˜Œ๎˜‚๎˜‰๎˜‘๎˜’๎˜‡๎˜Œ๎˜ˆ๎˜’๎˜Œ๎˜‰๎˜“๎˜Œ๎˜๎˜…๎˜‚๎˜๎˜†๎˜Œ๎˜ˆ๎˜๎˜‰
๎˜”๎˜Œ๎˜ƒ๎˜•๎˜ƒ๎˜‚๎˜‰๎˜Ž๎˜–๎˜‰๎˜๎˜‚๎˜—๎˜˜๎˜†๎˜‹๎˜๎˜‡๎˜ˆ๎˜๎˜™๎˜‡๎˜‰
Last name: First name: Social Security:
pf3
pf4

Partial preview of the text

Download Midterm Exam: SIMPLESEM Code and Prolog Predicate for Problem Solving and more Exams Computer Science in PDF only on Docsity!

^     

Midterm Exam

February 25, 2005

(100 pts.)

1. (80pts) (a) (50 pts.) Write a complete SIMPLESEM code for the following program using the

C3 language paradigm. (b) (30pts.) Manually run the resulting code and enter all the data in

the data segment. Enter your code and data in the table provided below. Use pencil so that

you can easily make necessary corrections. Use back sides of pages for scratch notes.

int m = 4; int n = 16; main() { int m = 100 if (n > 10 & m > 83) m = f() else m = 0 } int f() { int k = 3, int n = 4 if (m == 1) return 4 else { n = m-- + k return ( n * f()) } }              Last name: First name: Social Security:

SIMPLESEM CODE SEGMENT FOR PROBLEM # Nr Code Comments

  1. set 0, 4 set current
  2. set 1, 7 set free
  3. set 2, 4 m = 4
  4. set 3, 16 n = 16
  5. set 6, 100 m = 100
  6. jumpt 14, D[3]<=10 or D[6]<=
  7. set 1, D[1] + 1 calling sequence
  8. set D[1], 8 + 4
  9. set D[1]+1, D[0]
  10. set 0, D[1]
  11. set 1, D[1] + 4
  12. jump 16
  13. set 6, D[D[1]] m = f()
  14. jump 15
  15. set 6, 0 m = 6
  16. halt
  17. set D[0]+2, 3 k = 3
  18. set D[0]+3, 4 n = 4
  19. jumpt 23, D[2] <> 1
  20. set D[0]-1, 4 return 4
  21. set 1, D[0]-
  22. set 0, D[D[0]+1]
  23. jump D[D[1]+1]
  24. set D[0]+3, D[2] + D[D[0]+2] n = m + k
  25. set 2, D[2]-1 m--
  26. set 1, D[1] + 1 calling sequence
  27. set D[1], 27 + 4
  28. set D[1]+1, D[0]
  29. set 0, D[1]
  30. set 1, D[1] + 4
  31. jump 16
  32. set D[0]-1, D[D[0]+2]D[D[1]] return nf()
  33. jump 20

SIMPLESEM DATA SEGMENT FOR PROBLEM # Nr. Contents Comments

  1. 4/8/13/18/23/18/13/8/4 CURRENT
  2. 7/8/12/13/17/18/22/23/27/22/17/12/7 FREE
  3. 4/3/2/1 m (global)
  4. 16 n
  5. R.P. Main
  6. D.L. Main
  7. 100/108 m (main)
  8. 108 3*36=
  9. 12
  10. 4
  11. 3
  12. 4/
  13. 36 3*12=
  14. 31
  15. 8
  16. 3
  17. 4/
  18. 12 3*4=
  19. 31
  20. 13
  21. 3
  22. 4/
  23. 4
  24. 31
  25. 18
  26. 3
  27. 4