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

Programming Questions and Exercises - Prof. Randy R. Appleton, Exams of Programming Languages

Various programming questions and exercises covering topics in perl, python, java, c++, lisp, prolog, and regular expressions. The questions cover array size comparison, integer length definition, federal debt calculation, variable naming, regular expression matching, associative array lookup time, lisp function call, infinite loop in prolog, recursion relation calculation, input validation, file manipulation, and microsoft word compatible word processor creation.

Typology: Exams

2009/2010

Uploaded on 02/25/2010

koofers-user-cb0
koofers-user-cb0 🇺🇸

5

(1)

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Questions
1) Suppose I have an array of 100 ints in Perl and/or Python. It will take more space than storing the
100 ints would in C++ or Java. Why?
2) In Java, an integer is defined to be exactly four bytes. In C++, there is no such length definition.
What advantage does C++ gain by not defining the length of an int?
3) The federal government has debt. How much is your share? In other words, what is total federal
debt per person in the U.S.?
4) Some languages require the programmer to name the type of a variable. For example, in C++ and
Java, every variable is either an int or a float or a boolean or so on. Other languages make no such
requirement. Why might you want the language to require this of you?
5) Write me a regular expression that matches non-negative whole numbers as written in American as
shown below.
Good Good Bad Bad
1 123 0.1 0,12
1,234 0123 1a234 1234,5678
1,234,567,890 1234576 1234,567 123,4567
6) Suppose I have an associative array (dictionary) in Perl. It has 'n' elements. How long will it take to
look up an element given the key value? (Circle just one)
O(1) O(n) O(n * log(n)) O(n**2)
7) What does the code below mean in Lisp?
(fred)
a) The literal string "fred". b) The variable 'fred'
c) Call the function 'fred'. d) Run the program 'fred'.
pf2

Partial preview of the text

Download Programming Questions and Exercises - Prof. Randy R. Appleton and more Exams Programming Languages in PDF only on Docsity!

Questions

  1. Suppose I have an array of 100 ints in Perl and/or Python. It will take more space than storing the 100 ints would in C++ or Java. Why?
  2. In Java, an integer is defined to be exactly four bytes. In C++, there is no such length definition. What advantage does C++ gain by not defining the length of an int?
  3. The federal government has debt. How much is your share? In other words, what is total federal debt per person in the U.S.?
  4. Some languages require the programmer to name the type of a variable. For example, in C++ and Java, every variable is either an int or a float or a boolean or so on. Other languages make no such requirement. Why might you want the language to require this of you?
  5. Write me a regular expression that matches non-negative whole numbers as written in American as shown below. Good Good Bad Bad 1 123 0.1 0, 1,234 0123 1a234 1234, 1,234,567,890 1234576 1234,567 123,
  6. Suppose I have an associative array (dictionary) in Perl. It has 'n' elements. How long will it take to look up an element given the key value? (Circle just one) O(1) O(n) O(n * log(n)) O(n**2)
  7. What does the code below mean in Lisp? (fred) a) The literal string "fred". b) The variable 'fred' c) Call the function 'fred'. d) Run the program 'fred'.
  1. What does this program print? (define (loop x) (if (> x 2) x (loop (+ 1 x)) ) ) (loop 3)
  2. Write an infinite loop in Prolog. It should run either forever, or until memory is exhausted. Programs You may only do four of these programs. You may not use the same language twice. Feel free to plan ahead. Each program is worth 3 points.
  3. Write a program that prints the f(10) for of the following recursion relation. Note, the correct answer is 11,496. f(x) = 1 if x < 1 f(x) = 1f(x-1)+2f(x-2)+3*f(x-3) if x >= 1
  4. Ask for an input number. If it is a positive power of 2, then stop, else repeat.
  5. Read /etc/passwd on euclid. Fields in that file are divided by colons. Tell me the first field for every line that has a 7th field which is not "/bin/bash". I believe there are 33 such lines.
  6. Pop up a window. It should have a text field or a text box. When the user enters 'die' the window should close.
  7. Your drunk person starts at position zero. Flip a fair coin. If it's heads, he walks one time to the left, otherwise he walks right. When he reaches position 10, he falls off a cliff. Print each coin flip, the resulting position, and the number of moves made.
  8. Print the name of the file with the longest filename. Also print the name of the longest file (file with the most data).
  9. Write me a Microsoft Word compatible word processor. All features of Microsoft Word must be present. No partial credit allowed.