click below
click below
Normal Size Small Size show me how
CECS 342 Midterm SG
| Question | Answer |
|---|---|
| What can be said about C++ vs Python? a) They both allow recursion b) Python allows recursion but C++ does not. c) C++ allows recursion but Python does not d) Neither allows recursion | a) They both allow recursion |
| What can be said about C++ vs Python? a) Both languages are interpreted b) Both languages are compiled c) The performance of both languages appears to be similar d) None of these answers are correct | d) None of these answers are correct |
| All computer languages use compilation to create executable machine code. a) True b) False | b) False |
| What is a regular expression? a) a character b) all of these are correct c) a regular expression followed by a Kleene star d) the empty string | b) all of these are correct |
| What is a scanner NOT responsible for? a) tokenizing source b) building parse trees c) saving source locations for error messages d) removing comments | b) building parse trees |
| Context Free Grammars will always produce non-ambiguous parse trees a) True b) False | b) False |
| What does CFG stand for? a) Compound Function Generator b) None of these are correct c) Computers Forcing Graphics d) Compound Fraction Gradients | b) None of these are correct |
| There are basically 2 types of programming languages: Imperative and Declarative. Which of the following is considered Declarative? a) Prolog b) Fortran c) C++ d) The correct answer is not listed | a) Prolog |
| What is a clear benefit for compilation? a) Better diagnostics (error messages) b) Better performance c) Less memory use d) Program is easier to read | b) Better performance |
| What is the process that divides a program into tokens? a) interpreting b) parsing c) scanning d) compiling | c) scanning |
| We talked about the "dangling else" problem in class. This is a thing that only happens in C++. a) True b) False | b) False |
| What does the following code print? int x = 4; cout <<< ++x << x << x++ << x; a) 5566 b) 5556 c) None of these d) 4567 | b) 5556 |
| What String class member function is invoked by the 2nd line of the following code? String s("Ann"); String t = s; a) The non-overloaded=operator b) operator= c) The copy constructor d) The default constructor | c) The copy constructor |
| What is the term for the function in C++ class definition that can deallocate dynamic memory when the object goes out of scope, as in a return from a function which has created a local object? a) Tilde function b) Deconstructor c) Destructor d) Exit | c) Destructor |
| What is the correct function prototype to implement an equals comparison operation for a class such as Time? a) void operator==(Time a, Time b) b) void ==(Time a, Time b) c) bool ==(Time a, Time b) d) bool operator==(Time a, Time b) | d) bool operator==(Time a, Time b) |
| What if anything is wrong with the following class definition? class Fraction { public: Fraction(int n,int d); Fraction(int n); Fraction(); Fraction operator+(Fraction other) const; ... private: int numerator, denominator; }; | Questions: a) Nothing is wrong b) Not all the constructors are needed c) The operator functions should return type Fraction d) It is missing a private double data member to represent the decimal value of the fraction Answer: a) Nothing is wrong |
| Given a class Name with member functions get_first and get_last, which of the following functions overloads << so that one can print a name as Name name("Bjarne Stroustrup"); cout << name << endl; | b) ostream& operator<<(ostream& out, const Name& name) { return out << name.get_first() << " " << name.get_last(); } |
| Which of the following is the proper function prototype for the String class copy-constructor? a) String::String(String this, const String& other) b) String::String(const String& other) c) String::String=(const String& other) d) String::String() | b) String::String(const String& other) |
| A class can have ____ destructor functions(s) and ____ constructor function(s). a) one, several b) one, one c) many, one d) several, several | a) one, several |
| For any custom class that dynamically allocates memory, what member functions must be supplied? a) Copy constructor, constructor, destructor b) Constructor, destructor, operator== c) Assignment operator, Copy constructor, destructor | c) Assignment operator, Copy constructor, destructor |
| If you do not define a destructor function for your custom class: a) You will get a warning when you compile your program b) The C++ compiler defines a default destructor for you c) All of these | b) The C++ compiler defines a default destructor for you |
| What can be said about the following statement? "The scope of a variable is limited to the clause in which it appears." | d) that statement is true. |
| Prolog and other logic languages are based on... a) boolean binary b) predicate calculus c) logistical nightmares d) formal logic | b) predicate calculus |
| What can be said about the following prolog statement: grandparent(G, C) :- parent(G,P), parent(P, C). a) it is a rule b) it is a fact c) it is a query d) it is a goal | a) it is a rule |
| What can be said about this prolog statement: parent(steve, landon). a) it is hard to raise kids these days b) it is a fact c) it is a goal d) it is a rule | b) it is a fact |
| What term is used to describe how the prolog interpreter works in order to prove a goal? a) depth-first recursion b) backward chaining c) random tagging d) forward linking | b) backward chaining |
| The body of a Horn Clause... a) is a list of terms. b) is not transmittable c) is a single term. d) The correct answer is not shown. | a) is a list of terms. |
| Is this function tail recursive? int fibo(int n, int n1=1, int n2=1) { if (n == 0) return n2; if (n == 1) return n1 + n2; return fibo(n-1, n2, n1+n2); } a) True b) False | a) True |
| The head of a Horn Clause... a) The correct answer is not listed. b) is a list of terms c) is inverted when called d) is a single term | d) is a single term |
| Is this function tail recursive? int fibo(int n, int n1=1, int n2=1) { if (n == 0) return n2; if (n == 1) return n1 + n2; int result = fibo(n-1, n2, n1+n2); return result } a) True b) False | b) False |
| What is true about Horn Clauses? a) They have a head and a body b) It's Santa Clauses brother c) They are hard to implement d) They are tail-recursive | a) They have a head and a body |
| Does not remember entirely Every C++ program must have a header file. a) True b) False | b) False; Not every C++ program requires a separate header file |
| This code runs properly: #include <iostream> int main() { cout << "Hello World!"; return 0; } a) True b) False | b) False; Missing namespace and |
| This code runs properly: #include <iostream> int main() { std::cout << "Hello World!"; return 0; } a) True b) False | True |