Example Midterm

advertisement
Name: __________________________________
UAID: __________________________________
CSCE 3193 – Programming Language Paradigms
Spring 2011 Practice Midterm Exam
You may bring in a 1 page, 8.5 x 11 inch sheet of paper with whatever you want
on it (front and back). Calculators are not allowed.
There are 10 questions on 9 pages worth a total of 100 points.
Signature: _________________________________
I certify that I have neither given, nor received, unauthorized help on this exam.
1 of 9
1. (4 points) Write the letter corresponding with the application domain each
programming language was designed to support in the space provided. Each
letter should be used exactly once.
A:
B:
C:
D:
Scientific Applications
Business Applications
Artificial Intelligence
Systems Programming
__D__ C
__B__ COBOL
__A__ FORTRAN
__C__ LISP
2. (10 points) For each of the following questions, circle True or False.
True False Programming languages tradeoff reliability for speed of execution.
True False FORTRAN introduced many control structures, but few data
structures.
True False C++ uses a hybrid of compilation and interpretation.
True False In general, Perl programs are compiled and interpreted every time
they are executed.
True False In general, Java programs are compiled and interpreted every time
they are executed.
True False Java supports multiple inheritance.
True False In Java, by default, method calls are bound to implementations at
run time.
True False In C++, the friends construct violates the protection offered by the
private sections of the class definition.
True False Lisp is a purely compiled language.
2 of 9
True False Scripting languages make small programs simple and large
programs complicated.
3. (20 points) For each of the following questions, fill in the blank.
FORTRAN stands for ____________Formula Translation___________________.
The area within the source code within which an identifier can be referenced is
called its ____scope_____.
When a process could be run, but never does, it suffers from
_____starvation_______.
______Algol_____________ was the first language designed by an
international committee.
______Ada_____________ was a language designed at the request of the U.S.
Department of Defense.
A Hash table size needs to be ____a prime number__________ if you handle
collisions using secondary hashing.
_____Pascal___________ and ______Basic____ were designed specifically as
languages for instruction.
_____Aliasing_______ is when multiple identifiers can refer to the same
address.
The time between the allocation and deallocation of memory for a variable is
called its ________lifetime_____.
4. (10 points) Which language, Java, C++ or Both, supports the following
language features. Write in the space provided.
__Both___ Explicit dynamic allocation of objects on the heap
__C++__ Operator overloading
3 of 9
__C++_ Multiple Inheritance
__Java__ Compiler checking for exception handlers
_Both__ Private Inheritance
_Java_ Nested classes
_Java__ Garbage Collection
__Both_ Polymorphic methods
__Java_ Automatic initialization of variables
_Both_ Method overloading
5. (4 points) Answer each of the following multiple choice questions by circling
the letter corresponding to the best answer.
Java’s HashMap handles collisions using
a) linear probing
b) secondary hashing
c) separate chaining
d) what’s a collision
Good hash functions should distribute the keys:
a) uniformly
b) normally
c) in sorted order
d) what’s a hash function
4 of 9
6. (6 points) For each language, indicate whether it is compiled, interpreted, or a
hybrid of both.
__Hybrid__ Perl
__Compiled___ ALGOL
_Interpreted__ Basic
__Interpreted__ Javascript
_Compiled__ Ada
_Hybrid__ Java
7. (12 points) Which programming language feature is bound at each of the
following times (for C++)? Write the letter corresponding with the correct
binding time in the space provided. Each letter should be used exactly once.
A: Language Design Time
B: Language Implementation Time
C: Compile Time
D: Link Time
E: Load Time
F: Run Time
_B__ Use of a single byte to store a character
__D_ Binding call to an external function to the code implementing that function
_A__ Use of { and } for begin and end of blocks of code
_E__ Binding global variables to a memory address
_F_ Binding local variable to a memory address
__C__ Binding a particular identifier to a particular data type
5 of 9
7, 8 , 9: Questions on Collections class; Generics; Memory Model; Concurrency
A similar question to the below, but on Java
10. (10 points) Consider the following C++ program:
Class Employee
{
public:
… constructors etc …
string GetName();
float GetSalary();
void Print() {prints Name and Salary};
void Fire() {sets Salary to 0.0};
protected:
void Raise (const float Amount) { adds Amount to Salary };
private:
string Name;
float Salary;
};
Class Manager : public Employee
{
public:
… constructors etc …
string GetDepartment();
void Print() {prints Name, Salary, and Department somehow};
void Promotion() (const float Amount) { gives the Manager a raise};
too };
private:
string Department;
};
int main()
{
Employee Emp1;
Manager Manager1;
}
6 of 9
If Manager inherits publicly from Employee, which of the following would be
valid? Circle either Valid or Invalid for each of the following statements:
Valid Invalid Inside main: Emp1.Raise( 1000.0 );
Valid Invalid Inside main: Manager1.Raise( 1000.0 );
Valid Invalid Inside Manager::Promotion: Raise( 1000.0 );
Valid Invalid Inside Manager::Print: cout << Name;
Valid Invalid Inside Manager::Print: Employee::Print();
7 of 9
Download