Final CS exam

Ace your homework & exams now with Quizwiz!

List two benefits that C++ classes have over C-style structs:

1. Allow for different data protection. I.e. private, public. 2. Allow for polymorphic behavior to take place.

What is an advantage of using references (int&) over pointers (int*)?

1. references cannot be changed. 2.references don't produce dangling pointers, or require a change in syntax. Note: However references cannot be reassigned to point to something else, but a pointer can be.

At what point does a class' constructor get called?

When the constructor is created.

A default constructor has how many parameters? a. 0 b. 1 c. 2 d. variable number

a. 0

The Overloaded function must have: a. Different parameter list b. Different return type. c. The same number of parameters. d. The same number of default arguments

a. Different parameter list

The line: virtual double earnings() const = 0; appears in a class definition. You cannot deduce that: a.All classes that directly inherit from this class will override this method. b.This class is an abstract class. c.Any concrete class derived from this class will have an earnings function. d.This class will probably be used as a base class for other classes.

a.All classes that directly inherit from this class will override this method.

Member access specifiers (public and private) can appear: a.In any order and multiple times. b.In any order (public first or private first) but not multiple times. c.In any order and multiple times, if they have brackets separating each type. d. Outside a class definition.

a.In any order and multiple times.

If a member function of a class already provides all or part of the functionality required by a constructor or another member function then: a.Copy and paste that member function's code into this constructor or member function. b.Call that member function from this constructor or member function. c.That member function is unnecessary. d.This constructor or member function is unnecessary.

b.Call that member function from this constructor or member function.

An Algorithm that requires ____operations to complete its task on n data elements is said to have linear runtime: a. n^3 + 9 b. 3n^2+3n+2 c. 2n+1 d. 6

c. 2n+1

Attributes of a class are also known as: a. Constructor b.Local variables. c.Data members. d. Classes.

c. Data Members

Which of the following is not a kind of inheritance in C++? a. public b.private. c.static. d. protected.

c. static

Given that k is an integer array starting at location 2000,kPtr is a pointer to k and each integer is stored in 4 bytes of memory, what location does kPtr + 3 point to? a.2003 b.2006 c.2012 d.2024

c.2012

Which of the following statements will not produce a syntax error? a.Defining a const member function that modifies a data member of the object. b.Invoking a non-const member function on a const object. c.Declaring an object to be const. d.Declaring a constructor to be const.

c.Declaring an object to be const.

Every object of the same class: a.Gets a copy of every member function and member variable. b.Gets a copy of every member variable. c.Gets a copy of every member function. d. Shares pointers to all member variables and member functions.

c.Gets a copy of every member function.

[C++11]: Which of the following is true? a. The only way to define a constructor in a class is to explicitly define one. b. If you define any constructors with arguments, the compiler will also define a default constructor c.If you define any constructors with arguments, the compiler will not define a default constructor. d.You cannot explicitly create constructors.

c.If you define any constructors with arguments, the compiler will not define a default constructor.

What type of member functions allow a client of a class to assign values to private data members a.Client member functions. b.Get member functions. c.Set member functions. d. None of the above.

c.Set member functions.

The main difference between a pure virtual function and a virtual function is: a.The return type. b.The member access specifier. c.That a pure virtual function cannot have an implementation. d. The location in the class.

c.That a pure virtual function cannot have an implementation.

The compiler will implicitly create a default constructor if: a. The class does not contain any data members. b.The programmer specifically requests that the compiler do so. c.The class does not define any constructors. d.The class already defines a default constructor.

c.The class does not define any constructors.

In the expression n = x + rand() % y; a.y is the shifting value. b.x is the scaling value. c.y is the scaling value. d.Both (a) and (b).

c.y is the scaling value.

A constructor can specify the return type: a. int. b. string. c. void. d. A constructor cannot specify a return type.

d. A constructor cannot specify a return type.

Which of the following is not a valid way to pass arguments to a function in C++? a.By reference with reference arguments. b.By value. c.By reference with pointer arguments. d. By value with pointer arguments.

d. By value with pointer arguments.

If a set of functions have the same program logic and operations and differ only in the data type(s) each receives as argument(s) then a(n) __________ should be used. a.Overloaded function. b.Recursive function. c.Macro. d.Function template.

d.Function template.

At what point does a class' destructor get called?

when the constructor goes out of scope.

Given the following command: int* my_array = (int * ) calloc (X, Y); Explain the what the input parameters x and y refer to

x refers to the number of elements to be allocated. y refers to the size of those elements.

In UML, the top compartment of the rectangle modeling a class contains: a.The class's name. b.The class's attributes. c.The class's behaviors. d. All of the above.

a.The class's name.

Employee is a base class and HourlyWorker is a derived class, with a redefined non-virtual print function. Given the following statements, will the output of the two print function calls be identical? HourlyWorker h; Employee *ePtr = &h; ePtr->print(); ePtr->Employee::print(); a.Yes. b.Yes, if print is a static function. c.No. d.It would depend on the implementation of the print function.

a.Yes.

Static member functions: a. Can use this pointer. b. Can access only other static member functions and static data members. c. Cannot be called until an object of their class is instantiated. d. Can be declared const as well.

b. Can access only other static member functions and static data members.

The is-a relationship represents: a. Composition b. Inheritance c. Information Hiding d. A friend

b. Inheritance

Assuming that text is a variable of type string, what will be the contents of text after the statement cin >> text; is executed if the user types Hello World! then presses Enter? a."H" b."Hello" c."Hello World" d."Hello World!"

b."Hello"

Which of the following assignments would be a compilation error? a.Assigning the address of a base-class object to a base-class pointer. b.Assigning the address of a base-class object to a derived-class pointer. c.Assigning the address of a derived-class object to a base-class pointer. d.Assigning the address of a derived-class object to a derived-class pointer.

b.Assigning the address of a base-class object to a derived-class pointer.

Virtual functions must: a.Be overridden in every derived class. b.Be declared virtual in every derived class. c.Be declared virtual in the base class. d.Have the same implementation in every derived class.

b.Be declared virtual in every derived class.

A default constructor: a.Is a constructor that must receive no arguments. b.Is the constructor generated by the compiler when no constructor is provided by the programmer. c.Does not perform any initialization. d.Both (a) and (b).

b.Is the constructor generated by the compiler when no constructor is provided by the programmer.

If Americans are objects of the same class, which of the following attributes would most likely be represented by a static variable of that class? a.Age. b.The President. c.Place of birth. d.Favorite food.

b.The President.

Virtual destructors must be used when: a.The constructor in the base class is virtual. b.delete is used on a base-class pointer to a derived-class object. c.delete is used on a derived-class object. d.A constructor in either the base class or derived class is virtual.

b.delete is used on a base-class pointer to a derived-class object.

From most restrictive to least restrictive, the access modifiers are: a.protected, private, public b.private, protected, public c.private, public, protected d. protected, public, private

b.private, protected, public

If objects of all the classes derived from the same base class all need to draw themselves, the draw function would most likely be declared: a.private b.virtual c.protected d. friend

b.virtual

Polymorphism is implemented via: a.Member functions. b.virtual functions and dynamic binding. c.inline functions. d.Non-virtual functions.

b.virtual functions and dynamic binding.

Static data members of a certain class: a. Can be accessed only if an object of that class exists. b. Cannot be changed, even by objects of the same that class c. Have class scope. d. Can only be changed by static member functions.

c. Have class scope.

Which of the following does the C++ compiler not examine in order to select the proper overloaded function to call? a. Types and order of the arguments in the function call b. The number of arguments in the function call. c. The return type of the function. d. It examines all of the above.

c. The return type of the function.

If the function in volume (int x = 1, int y = 1, int z = 1); is called by the expression volume(3), how many default arguments are used? a. None. b. One. c. Two. d. Three

c. Two.

The type of function a client would use to check the balance of a bank account would be a.A utility function. b.A predicate function. c.An access function. d A constructor.

c.An access function.

Which of the following statements about virtual functions is false? a.They allow the program to select the correct implementation at execution time. b.They can use either static or dynamic binding, depending on the handles on which the functions are called. c.They do not remain virtual down the inheritance hierarchy. d.They can be called using the dot operator.

c.They do not remain virtual down the inheritance hierarchy.

Why are circular queues faster than standard vector-based queues?

circular queues don't require constant shifting and re-sizing unless specific circumstances arrive.

Select the false statement regarding inheritance. a.A derived class can contain more attributes and behaviors than its base class. b.A derived class can be the base class for other derived classes. c.Some derived classes can have multiple base classes. d. Base classes are usually more specific than derived classes.

d. Base classes are usually more specific than derived classes.

In regards to default arguments, which of the following is false? a. When an argument is omitted in a function call, the default value of that argument is automatically inserted by the compiler and passed in the function call. b. They must be the rightmost(trailing) arguments in a function's parameter list c. Default values can be constants. d. Default values cannot be global variables of function calls.

d. Default values cannot be global variables of function calls.

Which of the following is not a good example of a hierarchy likely to be modeled by inheritance? a.Airplanes. b.Geometric shapes. c.Animals. d. Prime numbers.

d. Prime numbers.

The given class definition: class CreateDestroy { public: CreateDestroy() {cout << "constructor called,";} ~CreateDestroy() {cout << "destructor called, " } }; what will the following program output? int main() { CreateDestroy c1; CreateDestroyc2; return 0; } a. constructor called, destructor called,constructor called, destructor called b.constructor called, destructor called, c.constructor called, constructor called, d. constructor called, constructor called, destructor called, destructor called,

d. constructor called, constructor called, destructor called, destructor called,

Abstract classes: a.Contain at most one pure virtual function. b.Can have objects instantiated from them if the proper permissions are set. c.Cannot have abstract derived classes. d.Are defined, but the programmer never intends to instantiate any objects from them.

d.Are defined, but the programmer never intends to instantiate any objects from them.

Which forms of inheritance are is-a relationships? a.All forms of inheritance are is-a relationships. b.Only public and private. c.Only public and protected. d.Only public.

d.Only public.

Which of the following would not be a member function that derived classes Fish, Frog and Bird should inherit from base class Animal and then provide their own definitions for, so that the function call can be performed polymorphically? a.eat b.sleep c.move d.flap Wings

d.flap Wings


Related study sets

Fund IS Section 5 Physical and Network Security

View Set

AMH 2020-Chapters: 27, 28, 29 and 30

View Set

Test Review Chapter 4: Personal Finance

View Set

Anatomy of the Hand (digits+palm+carpals)+Wrist (Distal Radius/Ulna=wrist joint)

View Set

Chapter 31: Cognitive and Sensory Alterations

View Set