final-spr08

final-spr08 - CMSC330 Spring 2008 Final Exam Do not start...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CMSC330 Spring 2008 Final Exam Do not start this exam until you are told to do so! Instructions You have 120 minutes to take this midterm. This exam has a total of 240 points, so allocate 30 seconds for each point. There is also a 16 point extra credit problem if you finish early. This is a closed book exam. No notes or other aids are allowed. If you have a question, please raise your hand and wait for the instructor. Answer essay questions concisely using 1 sentence, or at most 2 sentences. Longer answers are not necessary and a penalty may be applied . In order to be eligible for partial credit, show all of your work and clearly indicate your answers. Write neatly. Credit will not be given for illegible answers. Good luck!
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
1. (9 pts) Programming languages a. (3 pts) Give an example of a language feature (not including library functions) in Ruby & OCaml whose syntax is different but semantics are the same. b. (3 pts) Give an example of a language feature (not including library functions) in Ruby & Java whose syntax is the same but semantics are different. c. (3 pts) Describe a feature of an old programming language which proved vexing for programmers. 2. (12 pts) Ruby features What is the output (if any) of the following Ruby programs? Write FAIL if code does not execute. a. a = [2,3] a[3] = “c” a.push(“b”) puts a b. if “CMSC 330” =~ /([0-9]+)/ then puts $1 else puts “Error” end c. s = "CMSC 330 is too HARD!" s.scan(/[A-Z]+/) { |x| puts x } d. h = {2 => 3, 1 => 2, 0=>1} puts "#{h[1]} #{h[2]}" 3. (20 pts) Ruby programming Consider the following programming problem. We need to read from a text file a list of cars and the years they were produced. The file contains a number of lines of the form <car> <year>, where <car> is composed of letters, <year> is composed of digits, and the two are separated by a single space. Write a Ruby program to read in the list of cars and their model years, and output the list of cars and years in sorted order, with each car on a separate line. Any lines not in the correct format should be ignored. Skeleton Code Example Input Example Output file = File.new(ARGV[0], "r") until file.eof? do line = file.readline end // a = Array.new ; a.sort! // print 1 ; puts 2 yaris 2008 prius 2004 prius 2007 rav4 1998 yaris 2006 prius 2006 camry 1983 camry 1983 prius 2004 2006 2007 yaris 2006 2008
Background image of page 2
4. (30 pts) Regular expressions finite automata a. (6 pts) Reduce the regular expression (01)* | 1 to an NFA, using the algorithm shown in class. b.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 8

final-spr08 - CMSC330 Spring 2008 Final Exam Do not start...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online