CS 162

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

How many TAs do we have in this course?

11

What is the value of n after the following snippet? int n = 13, m = 16;int* np = &n; np = &m; *np = 10; a) 10 b) 13 c) 16 d) A memory address

13

Assume you've run a function of O(1) several times on randomized vectors of length 10,000 and found that, on average, it takes 13 ms to run. How long would you expect it to run on a vector of length 1,000,000?

13 ms

Given a class A that derives from a class B that derives from a class C, when an object of class A is deleted, in which order are the destructors called? a) depends on how the code is written for the constructors b) A, B, then C c) unable to determine d) C, B, then A

A, B, then C

Given the following class: class Point { private: int x; int y; public:Point(); void set_x (int x); void set_y (int y); int get_x(); int get_y(); }; The functions get_x() and get_y() are known as: a) Mutators b) Accessors c) Constructors d) Destructors

Accessors

(PART 2)Assume we have a Date class and two existing objects d1 and d2 of that class. Which big three function is called by the following statement? d2 = d1; a) destructor b) Non-default Constructor c) copy constructor d) Assignment Operator Overload

Assignment Operator Overload

Given a class A that derives from a class B that derives from a class C, when an object of class A is created, in which order are the constructors called? a) unable to determine b) A, B, then C c) C, B, then A. d) depends on how the code is written for the destructors

C, B, then A.

When a member function is defined outside of the class declaration, the function name must be qualified with the______. a) Class name, followed by a semicolon (;) b) Private access specifier c) Class name, followed by the scope resolution operator (::) d) Name of the first object

Class name, followed by the scope resolution operator (::)

(PART 1)Assume we have a Date class and an existing object d1 of that class. Which big three function is called by the following statement? Date d2 = d1; a) destructor b) Non-default Constructor c) copy constructor d) Assignment Operator Overload

Copy Constructor

Different class may not have member functions with the same name.

False

If a member function isn't supposed to change anything, put a const in the parameter listing

False

In a derived class, you cannot define new variables and member functions other than those that are in the base class

False

In a try block, the throw statement is always executed

False

Shallow copy is a default behavior when objects are copied or assigned, and it copies what each member variable it pointing so that you get a separate but identical copy

False

What kind of relationship between objects does class composition describe? a) Avoids-a b) Needs-a c) Has-a d) Is-a

Has-a

What is an iterator? a) It is another type of loop structure in C++. b) It is a special data type that helps traverse the elements in a container c) It is a special type of function that calls itself d) It serves as a counter over an incrementing/decrementing value

It is a special data type that helps traverse the elements in a container

The stack uses _______ to access and add elements, and queue uses ________ to access and add elements. Note: LIFO (last in first out), FIFO (first in first out) a) FIFO, LIFO b) LIFO, LIFO c) LIFO, FIFO d) FIFO, FIFO

LIFO, FIFO

Which choice below correctly orders growth order functions from slowest-growing to fastest-growing? a) O(log n) → O(n2) → O(n log n) → O(2n) b) O(n log n) → O(n2) → O(2n) → O(log n) c) O(log n) → O(n log n) → O(2n) → O(n2) d) O(log n) → O(n log n) → O(n2) → O(2n)

O(log n) → O(n log n) → O(n2) → O(2n)

What is the runtime complexity of the following snippet? int val = 0; for (int i = 0; i < n; i++) { val += i * i; } for (int i = 1; i < n; i *= 2) { val += i; } a) O(n) b) O(log n) c) O(n + log n) d) O(n log n)

O(n)

float mean(vector vec) { float m = 0; // 1 for (int i = 0; i < vec.size(); i++) { m += vec[i]; // 2 } return m; // 3 } Assume the line marked 1 takes time t1 to run, the line marked 2 takes t2 to run, and the line marked 3 takes time t3 to run. What is the computational complexity of the mean() function a) O(1+n+1) b) O(1) c) O( t1 + t2*n + t3) d) O(n)

O(n)

What tool is NOT used in this course?

Piazza

Which of the following is the correct way to implement the non-default (parameterized) constructor without an initialization list? a) Point::Point (int x, int y) { this->x = x; this->y = y; } b) void Point::Point (int x, int y) { this->x = x; this->y = y; } c) Point::Point (int x, int y) const { this->x = x; this->y = y; } d) void Point (int x, int y) { this->x = x; this->y = y; }

Point::Point (int x, int y) { this->x = x; this->y = y; }

Which of the following is the correct way to implement the non-default (parameterized) constructor with an initialization list? a) Point::Point(int x, int y) : x, y {} b) Point::Point(int x, int y) : this->x(x), this->y(y) {} c) void Point::Point(int x, int y) : x(x), y(y) {} d) Point::Point(int x, int y) : x(x), y(y) {}

Point::Point(int x, int y) : this->x(x), this->y(y) {}

What is the order of the steps of compilation? a) Preprocessing → Assembly → Linking → Compilation b) Assembly → Preprocessing → Linking → Compilation c) Preprocessing → Compilation → Assembly → Linking d) Linking → Compilation → Preprocessing → Assembly

Preprocessing → Compilation → Assembly → Linking

If you have a class defined in separate files, and change the way a member function is defined (the body of the function), which file(s) need to be re-compiled? a) makefile b) the Implementation c) All files d) The interfacce

The Implementation

What is "encapsulation" in the context of object-oriented programming? a) The practice of using dynamically-allocated memory for class members instead of statically-allocated memory b) The practice of limiting all definitions for a class, including definitions of member functions, to a single header file c) The practice of exactly capturing the characteristics of a real-world object in a class definition d) The practice of hiding a class's implementation details behind a well-defined public interface

The practice of hiding a class's implementation details behind a well-defined public interface

What is the purpose of the compilation step of the compilation process? a) To translate C++ code into assembly code b) To translate C++ code into executable binary code c) To translate assembly code into machine code d) To resolve references in object code in order to produce executable binary code

To translate C++ code into assembly code

If a member is declared static, all objects of that class have access to that variable

True

The constructor of a class that does not have any parameters is called a default constructor.

True

The overloaded = operator copies data from one object to another so it is known as the assignment operator

True

If you do not furnish a __________, a default one will be provided by the compiler. a) copy_constructor b) constructor c) all of these d) destuctor

all of these

Using inheritance allows us to a) make our class more modular b) implement an "is-a" relationship c) all of these d) eliminate duplicate code

all of these

Which of the following are valid template prefixes? a) template <class T, class M> b) template <class M> c) all of these d) template <class T>

all of these

If a base class has public member functions that are not listed by a derived class, then these functions ______________ a) do not exist in the derived class b) are not available to the derived class c) are inherited unchanged in the derived class d) are private to the derived class

are inherited unchanged in the derived class

A(n) __________ is a special function that is called whenever a new object is created and initialized with another object's data. a) mutator b) static function c) destructor d) copy constructor

copy constructor

A struct is a(n) __________ that is defined by the programmer a) method b) function c) attribute d) data type

data type

A friend function is a member of the class, and it may directly modify or access both protected and private data members.

false

Different class may not have member functions with the same name.

false

If a function throws an exception, it must be caught inside that function

false

If an exception is not caught, it is stored for later use.

false

Nodes in a linked list are stored in contiguous memory

false

The member function eof() returns false when we are ready to read the end of file character

false

The runtime complexity of different data structures on performing the same task is always the same.

false

True or False? The following makefile rule correctly specifies the files cats.hpp , dogs.hpp , and petstore.cpp as dependencies of the target petstore: cats.hpp dogs.hpp petstore.cpp: petstoreg++ petstore.cpp -o petstore

false

Vector is an array that can grow and shrink in length while the program is running, where capacity refers to the number of elements in the vector

false

You can overload the dot operator(.).

false

You may not have more than one input and one output stream open at one time

false

The Space Complexity of Selection Sort is O(n2)

false O(1)

Who can access private data in a class? a) classes derived from the class b) no one c) everyone d) friends of the class

friends of the class

What is the correct way to halt the compilation process before linking when using g++? a) g++ -o file.cpp b) g++ -g file.cpp c) g++ file.cpp -o file.o d) g++ -c file.cpp

g++ -c file.cpp

If the compiler encounters the line #ifndef BUTTON_H for the first time, it will: a) do nothing b) go to next line c) skip all the lines up to and including #endif d) look for the file button.h

go to next line

Struct type declarations (the interface) and function prototypes are usually stored __________. a)in makefile b)on separate disk volumes c)in c.pp files, along with function definitions d)in their own header files

in their own header files

Which snippet below correctly frees all of the memory it allocates? a)int* n = new int; double* d[5]; delete n; delete d; b)int* n = new int; double* d = new double[5]; delete n; delete d; c)int* n = new int; double* d[5]; delete n; delete[] d; d)int* n = new int; double* d = new double[5]; delete n; delete[] d;

int* n = new int; double* d = new double[5]; delete n; delete[] d;

A constructor _____ accept arguments. A destructor _____ have zero to many parameters. a) maynot, may b) may, maynot c) maynot, maynot d) may, may

may, maynot

A class may have ________ constructor(s), and __________ destructor(s). a) more than one, more than one b) at most one, more than one c) more than one, at most one d) at most one, at most one

more than one, at most one

If you have a class named myPersonClass, which of the following correctly declare a constructor in the class definition? a) myPersonClass(); b) ~myPersonClass(); c) myPersonClass::myPersonClass(); d) myPersonClass myPersonClass();

myPersonClass();

Member variables (attributes) or member functions of a class that are declared to be private may a) only be accessed by members of that class b) be considered to be global variables c) not be accessed by the class d) only be accessed by the main program

only be accessed by members of that class

In Linked Lists, the pointer variable Linked_List* head a) is always NULL b) is the first node in the list c) points to the first node in the list d) is undefined

points to the first node in the list

In a struct, all members are _________ by default. In a class, all members are _________ by default. a) public, private b) private, private c) public, public d) private, public

public, private

Which of the following member function is NOT common to the sequential containers (vector, list, deque)? a) end(); b) begin(); c) push_front(); d) rbegin();

push_front();

Giving the following struct: struct student { std::string name; int id; float gpa; }; Which snippet correctly sets the GPA for the student s1 declared below? student* s1 = new struct student; a) s1.gpa = 3.9; b) s1->set_gpa(3.9); c) s1.set_gpa(3.9); d) s1->gpa = 3.9;

s1->gpa = 3.9;

If the member variables in a base class are private, then ________ a) making them private causes a syntax error b) you must declare them in the derived class also c) they can be directly accessed or changed in the derived class d) the derived class must use accesssors or mutators from the base class to access them

the derived class must use accesssors or mutators from the base class to access them

If a base class has a virtual member function named print, and a pointer variable of that class, ptr, is pointing to a derived object, then the code ptr->print( ); calls a) the derived print function b) the base class print function c) both the derived and base print function d) it causes a run-time error

the derived print function

The block of code that checks if an unusual situation or error occurs is called a) the throw statement b) the catch block c) the error block d) the try block

the try block

A template class allows the class to be used with different data types

true

Both destructors and constructors are not inherited into derived class.

true

If you need to implement either a copy constructor, a destructor, or an assignment operator overload, you should probably implement all three in your program.

true

If your program defines a class template, then the compiler will generate a class for each different data type for which it is instantiated.

true

In the derived class, you should only list functions in the base class that will be redefined.

true

The fail() can be used to determine whether an error occurred during a call to open().

true

True or False? This snippet correctly allocates a 3 x 7 array of double elements. double** array = new double*[3]; for (int i = 0; i < 3; i++) { array[i] = new double[7]; }

true

True or False? This snippet correctly frees the memory it allocates. int** nums = new int*[10]; for (int i = 0; i < 10; i++) { nums[i] = new int; } for (int i = 0; i < 10; i++) { delete nums[i]; } delete[] nums;

true

To add an int value 5 to a vector v of integers, use_______. a) v.add(5); b) v.append(5); c) v.insert(5); d) v.push_back(5);

v.pushback(5)

In order to tell the compiler to wait to decide which version of a function to use, you must precede the function declaration in the base class with the keyword a) operator b) void c) virtual d) friend

virtual

Which of the following is a pure virtual function? a) virtual double area(); b) double area() = 0; c) virtual double area() = 0; d) virtual double area() {}

virtual double area() = 0;


Kaugnay na mga set ng pag-aaral

6.4(B) apply qualitative and quantitative reasoning to solve prediction and comparison of real-world problems involving ratios and rates.

View Set

AP Biology Chapter 9 Questions Study Guide

View Set

ACCT 323: QBO Purchases/Money-Out Test

View Set