Computer Science

¡Supera tus tareas y exámenes ahora con Quizwiz!

(What is the output) stack <int> s; int a = 33, b = 66; s.push(2); s.push(a); s.push(a + b); b = s.top(); s.pop(); s.push(b); s.push(a - b); s.pop(); while (!s.empty()) { cout << s.top() << endl; s.pop(); }

99 33 2

Before a variable in C++ is used, it must be (A)defined (B)initialized (C)used in some expression (D)begin with a capital letter

a

The item that is removed first from a stack is called the ______ of the stack. a) front b) top c) base d) prime

a

Which can be used to associate a stream variable (infile) with a disk file (raw.dat) and open the file for reading? (A) ifstream infile("raw.dat"); (B) istream infile("raw.dat"); (C) ofstream infile("raw.dat"); (D) none of the above

a

Which function is used to initialize an object's data when it is created? (A) constructor (B) accessor (C) mutator (D) none of the above

a

Which is used to represent input stream object connected to keyboard? (A)std::cin (B)std::cout (C)std::endl (D)none of the above

a

Which must be included for any program that outputs data to the screen or inputs data from the keyboard using C++-style stream input/output? (A)iostream (B)stdio.h (C)sstream (D)none of the above

a

Which of the following is true? (A) When class D is derived from class B, the base class has fewer member functions and/or member variables. (B) A subclass usually has fewer member functions and/or member variables than the superclass. (C) A parent class usually has more member functions and/or member variables than a child class. (D) none of the above

a

Which operator allocates storage of the proper size for an object at execution time? (A) new (B) create (C) init (D) allocate

a

Which statement about a constructor is false? (A) A class must have at least one constructor. (B) A constructor must be defined with the same name as the class. (C) A class can have multiple constructors. (D) It can have the returned type.

a

Which statement about overloaded functions is false? (A) They have the same set of parameters but different returned type. (B) They have the same name. (C) They have different sets of parameters. (D) none of the above

a

______ describes the ability of a variable name to represent, during program execution, instances of different but related classes that descend from a common superclass. a) Inheritance b) Containment c) Polymorphism d) Encapsulation

a

which is used to specify that an object is not modifiable? (A) const (B) static (C) fix (D) none of the above

a

A member of a class is accessed using the (A) Comma operator (B) The dot operator (C) The indexing operator (D) The ampersand operator

b

An abstract base class cannot have ______. a) descendants b) instances c) data members d) virtual methods

b

Dynamic binding is also known as ______. a) early binding b) late binding c) template binding d) inheritance binding

b

Given the class declaration, class D:public class B {/*...*/}; Which of the following is false? (A) public members of B become public members of D (B) private members of D become public members of B (C) protected members of B become protected members of D (D) private members of B are inaccessible in D.

b

If a class is named Student, what must the constructors be named? (A) _Student (B) Student (C) ~Student (D) None of the above.

b

Which is not a benefit of inheritance? (A) Reuse code (B) Allow for class template (C) Better model the real world (D)Provide facilities for class libraries.

b

Which is not the C++ keyword? (A) while (B) null (C) bool (D) if

b

Which of the following class declarations indicates that Ball is a derived class of Sphere? a) class Sphere: public Ball b) class Ball: public Sphere c) class Ball::Sphere d) class Ball(Sphere)

b

A constructor (A) can only be used to initialize (B) must initialize all member variables (C) can do anything any other method can do. (D) must be declared with a return type

c

Suppose class Child is derived from class Parent was in turn derived from class GrandParent. The class Parent and GrandParent are the (A) Predecessor classes of class Child (B) Forebearer classes of class Child (C) Ancestor classes of class Child (D) Descendant classes of class Child

c

The ADT _____ allows you to insert into, delete from, and inspect the item at any position of the ADT. a) stack b) queue c) (unsorted)list d) array

c

The enqueue operation of the ADT queue is similar to the _____ operation of the ADT stack. a) isEmpty b) getFront c) push d) pop

c

Which function is used to get the values of private data members of a class? (A) mutator (B) constructor (C) accessor (D) none of the above

c

Which of the following #include directives is illegal? (A) #include <iostream> (B) #include "net.h" (C) #include <io stream> (D) none of the above

c

Which of the following are the correct preprocessor commands necessary to prevent multiple inclusions of header files? (A)#include "header.h" (B) #define HEADER_H #ifndef HEADER_H //declarations for header.h go here #endif (C) #ifndef HEADER_H #define HEADER_H //declarations for header.h go here #endif (D)#ifndef HEADER_H //declarations for header.h go here #endif

c

Which of the following strings contains balanced braces? a) ab{cde{fg}hi{jkl} b) ab{cde{fghi}j}kl} c) {abc{de}{fg}hij}kl d) {ab{cde{fgh}ijkl}

c

______ is the ability of a class to derive properties from a previously defined class. a)Encapsulation b)Simulation c)Inheritance d)Polymorphism

c

Given the language L, where: L = {w$w' : w is a possibly empty string of characters other than $, w' = reverse(w) } which of the following strings is NOT in L? a) XY$YX b) Z$Z c) $ d) XYZ$ZXY

d

If infile is an input file stream, which can be used to read an int variable, num? (A) infile.scanf(num) (B) infile.peek(num) (C) infile << num (D) infile >> num

d

In C++, related data of different types can be treated as a unit in (A) array variable (B) a function (C) a library (D) a class variable

d

Which is not an example of container/collection classes? (A) Arrays (B) Stacks (C) Queues (D) Strings

d

Which of the following is an illegal definition with the initialization? (A) int count=0, limit = 19; (B) int count(0), limit(19); (C) int count =0, limit(19); (D) int namespace(0);

d

Which of the following methods can be omitted from a statically allocated array-based implementation of a stack? a) isEmpty() b) pop() c) a constructor d) a destructor

d

Which operator destroys a dynamically allocated object? (A) destroy (B) desctruct (C) deallocate (D) delete

d

Which statement about void functions is wrong? (A) It performs some action and returns a value. (B) It performs some action but does not return a value. (C) It is a statement (D) It may have a return statement but is not required to have one.

d

(T/F) A program can use the operations of the ADT stack without knowing how the operations are implemented.

f

(T/F) If the characters in a string are added to a stack one at a time, characters removed from the stack will occur in the order in which they appear in the original string.

f

(Short Answer) Write C++ statements that declare a pointer named "p", which points to an integer variable named "a".

int * p int a p = &a

Balanced-braces problem: given expression can contain three types of delimiters: ( ), { }, and [ ]. Thus, {ab(c[d])e} is valid, but {ab(c)) is not. Write pseudo code for your algorithm. Input of the problem is a string with a mix of expressions and delimiters above, then your solution outputs whether the delimiters are matched.

int main { int x [5] = {0,1,2,3,4} somefunction(x[5]) }

(Short Answer) What is meant by static binding?

static binding occurs at compile time

(T/F) If 5 items are added to a stack, the first item to be removed from the stack is the first item that was added to the stack.

t

(T/F) In a link-based implementation of a stack, the stack can grow and shrink dynamically.

t


Conjuntos de estudio relacionados

Lesson 7: loan types, terms, issues

View Set

CSS 310 Final Exam Study Session

View Set

FUNDAMENTALS OF NURSING PRACTICE QUESTIONS

View Set

HK Book 8 L3 Where were you last night?

View Set

Econ 202 Chapter 2 UL Cary Heath

View Set

Chapter 59 Assessment and Management of Problems Related to Male Reproductive Processes

View Set