CSCI 310 Exam #1

Spring 2008

 

Directions: This exam is closed book, closed notes, closed neighbor, open mind.  Show all your work in the space provided.  If you need more space, use the back of one of the other exam sheets.  Read through the entire exam before starting to answer any of the questions in order to answer the easiest questions first and maximize your score.  There are 100 points on this exam (assuming I added correctly) not counting any bonus questions.  You have 50 minutes to complete this exam.  Good luck and have fun!

 

1.     (30 points) History…match the descriptions with the appropriate language.  Write the number corresponding to the correct answer in the provided blank.  You may use an answer more than once.

 

___A.  Logic programming language, popular in Europe and Japan

___B.  Designed by Bjarne Stroustrup, originally known as C with Classes

___C.  Designed by Niklaus Wirth to be a teaching language that was easy to compile

___D.  Sponsored by the DoD; designed to be English-like so that managers could read the code

___E.  First functional programming language; designed to be used for AI

___F.  First language to use BNF to describe its syntax

___G.  Originally designed for systems programming at Bell Labs in the early 1970’s

___H.  Scientific language designed for the IBM 704; proved high level programming languages could be efficient

___I.   Language that tried to combine Algol 60, COBOL, and FORTRAN IV into a universal language

___J.  Sponsored by the DoD as a single language to be used for all their software (instead of the 450 they currently used)

___K.  Designed at Dartmouth to allow non-science students easy computer access

___L.  Language that emphasized orthogonality; was described using van Wijngaarden grammars

___N.  Originally designed by Sun to develop software for consumer electronics

___O.  First introduced classes to support coroutines to ease writing simulation programs

1.     Ada

2.     Algol 60

3.     Algol 68

4.     Algol W

5.     Alice

6.     APL

7.     B

8.     BASIC

9.     BCPL

10.  C

11.  C++

12.  C#

13.  COBOL

14.  CPL

15.  Eiffel

16.  F#

17.  Forth

18.  FORTRAN

19.  Haskell

20.  Icon

21.  J++

22.  J#

23.  Java

24.  Lisp

25.  Logo

26.  ML

27.  Modula 2

28.  Occam

29.  Pascal

30.  PL/I

31.  Prolog

32.  Python

33.  RPG

34.  Ruby

35.  Scheme

36.  Simula 67

37.  Smalltalk 80

38.  Snobol

39.  None of the above


2.     (20 points) Short answer:

a.     One type of programming language is the procedural, or imperative type.  Name three other different programming language types.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

b.    How do you implement iteration in a pure functional language, since you have no loop variables?

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

c.     We briefly talked about several different application domains for programming languages.  One was MIS or business oriented programming.  Name two others.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

d.    What Lisp function takes the list (a b) and the list (c d) and returns the list (a b c d)?

 

 

 

 

 

 

 

 

 

 

 

 

 

 

e.     What does the Lisp function (defun foo (x) (cons (car x) (cdr x))) do?

 

 

 

 

 

 

 

 

 

 

 

 

 

3.      (30 points) Lisp programming

a.     Write a Lisp function mathstuff that takes a number as a parameter and returns

·         Twice the number if the number is positive

·         Zero if the number is zero

·         Half the number if the number is negative.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

b.    Write a Lisp function named duplicate that takes a list of atoms and duplicates each atom in the list.  For example, given the list (a b c d) the function would return (a a b b c c d d).

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

c.     Write a Lisp function named triangle that takes a positive integer as input, and returns the sum of all integers from 1 up through that integer.  For example, if passed the value 5, the function would return 1+2+3+4+5, or 15.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

d.    Write a Lisp function named myreverse that takes a list and reverses it.  It should not reverse any sublists.  For instance if passed the list (a (b c) d), your function should return the list (d (b c) a).

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

e.     Write a Lisp function named moremath that takes a list of numbers and alternately subtracts and adds them.  For instance, if given the list (10 9 8 7 6 5), your function should return 10–9+8–7+6–5, or 3 as its value.

 

 


 

4.     (20 points) Prolog programming

Write Prolog statements to capture the following information:

·         John, Fred, Dan and Steve are men.

·         John is the father of Fred and Dan.

·         Dan is the father of Steve.

·         The definition of a son predicate in terms of the father predicate.

·         The definition of a brother predicate in terms of the father and son predicates.

·         The definition of an uncle predicate in terms of the father, son, and brother predicates.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


Bonus: (5 points) The ubiquitous sudoku…using the numbers 1 through 9, fill in the squares so that each row, each column, and each indicated 3x3 square contains each of the digits 1 through 9 exactly once.

 

 

 

6

4

 

 

3

 

 

 

7

 

3

 

2

 

1

 

5

 

 

 

 

 

 

 

7

 

9

 

5

6

3

 

4

 

 

 

 

 

 

 

 

 

 

 

6

 

2

9

4

 

8

 

6

 

 

 

 

 

 

 

2

 

2

 

1

 

9

 

6

 

 

 

1

 

 

7

5

 

 

 

Bonus: (5 points)  A 25 ft ladder (NOT an extension ladder) is placed with its foot 7 ft away from a building. If the top of the ladder slips down 4 ft, how many feet will the bottom slide out?