This is a closed book examination. Do not consult any sources. Use additional sheets if needed, and be sure your name is on every page. When you finish, turn in these pages. If you like, you may then take a short break before beginning part B, which must be finished by the time written on the board in front.
Throughout this part of the examination I gave partial credit for an answer that was not directly responsive to the question, but true and even slightly relevant to the topic.
1. Comparing C++ and Java, describe the major ways in which one is better (easier to use, easier to learn, more powerful, more flexible, or more suitable) than the other: (a). Major C++ advantages over Java (or Java disadvantages):
(10 points)
More consistency between built-in types and user-defined classes. In particular operator overloading supports cleaner syntax in application programs. Usually more efficient execution. Supports multiple inheritance (but only one path for polymorphic function invocation and possible problems with duplicate member names).
(Full credit for any two)
(b). Major Java advantages over C++ (or C++ disadvantages):
(10 points)
Garbage collection relieves programmer of having to manage memory. Interfaces support polymorphism along multiple inheritance paths. Byte-code allows compiled programs to run on any platform that has a java interpreter. Standard library support for GUI objects at several levels. Supports safe applets to run under a user’s browser. New enum feature provides excellent support for discrete types having small no. of values.
(Full credit for any two. Also see question #2.)
2.
Explain why programmers should avoid using the built-in (language-provided) arrays in C (8 points) programs, but should feel free to use them in Java programs.
The main issue (full credit for this one): Java generates code to verify that all references to array elements are within the allocated bounds. C++ doesn’t, so code can refer to any cell in memory, a source of catastrophic bugs as well as possible entry for malicious virus programs. Also Java supplies the LENGTH attribute, so a function can reliably determine the size of an array passed as an argument. In C++ you have to pass a second size argument, which could be erroneous. Several students asserted that Java arrays are dynamic (can grow and shrink) while C++’s are not. Wrong! Both are fixed at allocation time. But Vector or other container (collection) classes in either language can be dynamic.
3. For any type of data item explain the criteria a programmer (or database designer) should apply: (a). For choosing its internal representation (11 points) Essential criteria: Simple Efficient Desirable criteria: Flexible Standard, interchangeable with other applications or other organizations.
(b). For choosing its external representation(s)
Familiar (to end users) Not error prone, esp. with regard to data entry
(11 points)