Midterm Exam 2 with Answers - Object Oriented Program II | CMSC 132, Exams of Computer Science

Material Type: Exam; Professor: Padua-Perez; Class: OBJECT-ORIENTED PROG II; Subject: Computer Science; University: University of Maryland; Term: Summer I 2008;

Typology: Exams

Pre 2010

Uploaded on 02/13/2009

koofers-user-9zb
koofers-user-9zb 🇺🇸

10 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
University of Maryland College Park
Dept of Computer Science
CMSC132, Midterm #2 Key
Summer 2008
First Name (PRINT): ___________________________________________________
Last Name (PRINT): ___________________________________________________
University ID: _________________________________________________________
I pledge on my honor that I have not given or received any unauthorized assistance on this examination.
Your signature: _____________________________________________________________
Instructions
This exam is a closed-book and closed-notes exam.
Total point value is 100 points, 50 minutes exam.
Please use a pencil to complete the exam.
PUNT RULE: For any question, you may write PUNT, and you will get ¼ of the points for the question
(rounded down). If you feel totally lost on a question, you are encouraged to punt rather than write
down an incorrect answer in hopes of getting some partial credit.
WRITE NEATLY. If we cannot understand your answer, we will not grade it (i.e., 0 credit).
Grader Use Only
#1
Software Engineering
(30)
#2
OO Design (UML)
(20)
#3
GUI/Inner Classes
(12)
#4
Heaps
(14)
#5
Binary Trees
(24)
Total
(100)
pf3
pf4
pf5

Partial preview of the text

Download Midterm Exam 2 with Answers - Object Oriented Program II | CMSC 132 and more Exams Computer Science in PDF only on Docsity!

University of Maryland College Park

Dept of Computer Science

CMSC132, Midterm #2 Key

Summer 2008

First Name (PRINT): ___________________________________________________

Last Name (PRINT): ___________________________________________________

University ID: _________________________________________________________

I pledge on my honor that I have not given or received any unauthorized assistance on this examination.

_Your signature: ______________________________________________________________

Instructions

This exam is a closed-book and closed-notes exam.Total point value is 100 points, 50 minutes exam.Please use a pencil to complete the exam.PUNT RULE: For any question, you may write PUNT, and you will get ¼ of the points for the question (rounded down). If you feel totally lost on a question, you are encouraged to punt rather than write down an incorrect answer in hopes of getting some partial credit.WRITE NEATLY. If we cannot understand your answer, we will not grade it (i.e., 0 credit).

Grader Use Only

#1 Software Engineering ( 30 )

#2 OO Design (UML) (20)

#3 GUI/Inner Classes (12)

#4 Heaps ( 14 )

#5 Binary Trees ( 24 )

Total (100)

Problem 1 (30 pts) Software Engineering

  1. T The Waterfall model begins a new step only when the previous step is complete.
  2. T Maintenance is considered a component of the software life cycle.
  3. T Software process models are codified sets of practices for software development.
  4. T The Waterfall model is more appropriate for small software projects.
  5. F Pair programming is a practice associated with the Waterfall model.
  6. F Abstraction and encapsulation help make programs run faster.
  7. T In OO systems invoking an object’s method is equivalent to sending the object a message.
  8. F Coding is the largest component of software development.
  9. F We prefer inheritance over composition when designing a system.
  10. F Encapsulation makes code modification harder and reduces code reuse.
  11. T Formal methods are mathematically-based techniques for specification, development, and verification of software systems.
  12. T Some people believe recent software development techniques have reduced the cost of change.
  13. F Regression testing ensures functionality is not lost when software is bought & sold.
  14. T In the Blackboard architecture components communicate through a shared updatable blackboard.
  15. T A mock object is similar to a stub but it can record calls made to the object.
  16. T Test coverage measures whether code is executed by some test case.
  17. The waterfall model of software development emphasizes predictability
  18. The iterative model of software development emphasizes adaptability
  19. In OO design, objects in a system correspond to nouns in the problem description.
  20. Similarly, interactions between objects correspond to verbs in the problem description.
  21. (4 pts) The software life cycle is a sequence of essential operations necessary for producing quality software. Mention four of those essential operations.

Answer: Any four of: Problem Specification, Program Design, Algorithms and Data Structures, Coding and Debugging, Testing and Verification, Documentation and Support, Maintenance

  1. (2 pts) What is clear box testing? Briefly explain.

Answer: Testing where we are allowed to examine the code.

  1. (2 pts) What is black box testing? Briefly explain.

Answer: Testing where we are not allowed to examine the code. Tests behavior in response to inputs.

  1. (2 pts) What is regression testing? Briefly explain.

Answer: Testing to see if some functionality has been lost.

package innerClass;

class Tetris { public void playGame() { System.out.println("Playing Tetris"); } }

public class Driver { public static void main(String[] args) { Tetris megaTetris = /* COMPLETE THIS ASSIGNMENT */ } }

Answer:

Tetris megaTetris = new Tetris() { public void playGame() { System. out .println("Playing MegaTetris"); } };

Problem 4 (14 pts) Heaps

Use the following heap to answer the questions that follow.

  1. (2 pts) Draw the heap as an array.

Answer: 7 10 8 13 20

7

10

13 20

8

  1. (3 pts) Draw the heap that would result from inserting 3 in the above heap.

Answer:

  1. (3 pts) Draw the heap that would result by deleting 7 from the original heap.

Answer:

  1. (6 pts) For a heap (designed to find the MAXIMUM value of a collection):

a. F Every heap is a binary search tree. b. F A post-order traversal of a heap will list its values in increasing order. c. T The heap will always be a balanced-tree (elements can be inserted in any order) d. T The time required to find the maximum element is O(1). e. T A sorted array represents a heap. f. T Priority queues can be implemented using heaps.

8

10

13

20

3

10

13 20

7

8

  1. (12 pts) Implement the method removeLeaves that removes all the leaf nodes of the tree.

Answer:

public void removeLeaves() { if (root == null) return; else if (root.left == null && root.right == null) root = null; else { removeLeavesAux(root.left, root); removeLeavesAux(root.right, root); } }

private void removeLeavesAux(Node rootAux, Node parent) { if (rootAux.left == null && rootAux.right == null) if (rootAux == parent.left) parent.left = null; else parent.right = null; else if (rootAux.left == null && rootAux.right != null) removeLeavesAux(rootAux.right, rootAux); else if (rootAux.left != null && rootAux.right == null) removeLeavesAux(rootAux.left, rootAux); else { removeLeavesAux(rootAux.left, rootAux); removeLeavesAux(rootAux.right, rootAux); } }