CECS 342 Midterm Study Guide

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/33

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 9:22 PM on 9/3/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

34 Terms

1
New cards

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

2
New cards

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

3
New cards

All computer languages use compilation to create executable machine code.

a) True

b) False

b) False

4
New cards

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

5
New cards

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

6
New cards

Context Free Grammars will always produce non-ambiguous parse trees

a) True

b) False

b) False

7
New cards

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

8
New cards

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

9
New cards

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

10
New cards

What is the process that divides a program into tokens?

a) interpreting

b) parsing

c) scanning

d) compiling

c) scanning

11
New cards

We talked about the "dangling else" problem in class. This is a thing that only happens in C++.

a) True

b) False

b) False

12
New cards

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

13
New cards

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

14
New cards

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

15
New cards

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)

16
New cards

What if anything is wrong with the following class definition?

class Fraction //represents fractions of the type 1/2, 3/4, 17/1

{

public:

Fraction(int n, int d);

Fraction(int n);

Fraction();

Fraction operator+(Fraction other) const;

Fraction operator-(Fraction other) const;

Fraction operator*(Fraction other) const;

bool operator

a) Nothing is wrong

17
New cards

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;

a) ostream& operator<

b) ostream& operator<

18
New cards

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)

19
New cards

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

20
New cards

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

d) Copy constructor, destructor

c) Assignment operator, Copy constructor, destructor

21
New cards

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

d) Your class may leave memory leaks from strings and vectors used as data members

b) The C++ compiler defines a default destructor for you

22
New cards

What can be said about the following statement?

"The scope of a variable is limited to the clause in which it appears."

a) the statement is theoretically true, but the implementation of prolog does not enforce this concept.

b) the statement is false - prolog variables do not have "scope" in the traditional computer language sense.

c) that is false. Prolog makes use of global variables so the clauses can pass information to each other

d) that statement is true.

d) that statement is true.

23
New cards

Prolog and other logic languages are based on...

a) boolean binary

b) predicate calculus

c) logistical nightmares

d) formal logic

b) predicate calculus

24
New cards

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

25
New cards

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

26
New cards

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

27
New cards

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.

28
New cards

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

29
New cards

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

30
New cards

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

31
New cards

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

32
New cards

*Does not remember entirely* Every C++ program must have a header file.

a) True

b) False

a) True?

33
New cards

*Does not remember entirely*

This code runs properly:

#include

int main() {

cout << "Hello World!";

return 0;

}

a) True

b) False

a) False?

Needs "using namespace std;" after the "#include ___" part since you're not using std::cout << "Hello World!";

34
New cards

*Does not remember entirely*

This code runs properly:

#include

int main() {

std::cout << "Hello World!";

return 0;

}

a) True

b) False

b) False?

Ran in onlinegdb and gave error message