• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/40

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

40 Cards in this Set

  • Front
  • Back

Suppose the bag and sequence are both implemented with a fixed-size array as in Chapter 3. What is the difference between the private member variables of the bag and the private member variables of the sequence?

The sequence has one extra size_t variable.

Suppose that the bag and the sequence have both been implemented with partially filled arrays. Which statement is true about the worst-case run time of the erase_one operations.

Neither removal function has constant worst-case run time.

Suppose that the goop function from the following changes the value of z[1]. Does this change effect the value of the actual argument?void goop(int z[ ]); int x[10];

Yes

Which situation does not use the copy constructor?

Calling a function with a reference parameter

What is the expression for generating a pseudorandom number in the range 1...N?

(rand() % N) + 1;

In the linked list version of the bag class a member variable many_nodes is used to keep track of how long the linked list is. Why not just make a call to the list toolkit function list_length()?

The list_length() function is O(n) and the alternative is O(1).

For a sequence (chapter 3) of numbers, suppose that you insert n first, then n–1, and so on down to 1—always using insert. What is the big-O time analysis for the combined time ofinsert all n numbers?

O( n2 )

What would be the best statement about operator + function of the bag class in section 3.1?

That is an union operator. It adds the contents of the second bag to the existing contents of the firstr bag.

Why are typedef statements useful?

A typedef statement allows for flexibility when the data type for an item needs to be modified for a program depending on the application. The data type may simply be modified in the typedef statement rather than in the entire program.

Suppose g is a sequence of chapter3 with 10 items. You activate g.start( ), then activate g.advance( ) three times. What value is then in g.current_index?

3

Which of the string (section 4.5) member functions are likely to activate reserve?a. operator =,b. operator +,c. operator +=d. operator >>e. copy constructor

a, b, c, d, and e

What is the primary responsibility of the destructor?

The primary responsibility of a destructor is to free the dynamic memory used by an object.

What would be the best statement about is_42 function in section 4.2?

Before coming into this function i_ptr is pointing to an integer variable. The function will return true if *i_ptr is 42.

What would be a major motivation for implementing a string class instead of using ordinary string variables.

Ordinary string variables do not support operations such as assignment and comparisons.

What is NULL?

It is a null pointer constant. It can be converted to any pointer type (or pointer-to-member type), which acquires a null pointer value. This is a special value that indicates that the pointer is not pointing to any object.

What underlying data structure is quickest for insertions/deletions at a cursor?

linked list

Suppose you want to use a linked list where the items are strings from the Standard Library string class. How would you need to change the node1.h header file in Section 5.2?

The #include directive must be added to the other include directives in the toolkit’s header file. Then we can change the typedef statement to: typedef string value_type;


Suppose you want to use a bag(Section 5.3) where the items are strings from the Standard Library string class. How would you do this?

The #include directive must be added to the other include directives in the node class's header file. Then we can change the typedef statement to: typedef string value_type;


Suppose that head_ptr is a head pointer for a linked list(Section 5.2) with just one node. What will head_ptr be after list_head_remove(head_ptr)?

It will be the null pointer.

What additional code is needed in a program in order to use NULL?

The cstdlib library should be included to use NULL, but because NULL is not part of the std namespace, it can be written without a preceding std::.

Suppose that you are working on a machine where arrays may have up to 4,000,000,000 items. What is the guaranteed range of the size_t data type?

Zero to 4,000,000,000

I have an array named data, which contains n integers. I want to print all of the numbers, starting at data[0]. BUT if the number 42 occurs, then I want to stop my printing just before the 42 (without printing the 42!) Here is most of my for-loop to accomplish my goal: for (i = 0; ___________________________________________; i++) cout << data[i] << endl; What is the correct way to fill in the blank? (If there is more than one correct answer, please select E.)

(i < n) && (data[i] != 42)

What is the usual worst-case performance for resizing a container class that stores its data in a dynamic array?

Linear time

What is printed by these statements? int i = 1; int k = 2; int* p1; int* p2; p1 = &i; p2 = &k; *p1 = *p2; *p1 = 3; *p2 = 4; cout << i;

3

What is the output of these statements, using your sequence ADT implemented as a linked list with Item defined as integer: sequence x; sequence y; x.insert(41); // Inserts 41 into the sequence x x.insert(42); // Inserts 42, so that x is now 42, 41 with cursor at front y = x; x.attach(43); // Attaches 43 so that x is now 42, 43, 41 with cursor at 43 y.advance( ); cout << "y size is " << y.size( ); cout << " and y current item is " << y.current( ) << endl;

y size is 2 and y current item is 41.

Suppose that the bag is implemented with a linked list. Which of these operations are likely to have a constant worst-case time? (Ch5)

insert

Which statement of the following is the most appropriate?

You don’t have to write every container class from scratch. The C++ Standard Template Library (STL) provides a variety of container classes that are useful in many different settings.

Why isn’t the Chapter 3 bag’s operator + function a friend function?

It does not need to be a friend function because it does not directly access any private members of the bag.

Name the library facilities that provide EXIT_SUCCESS

cstdlib

What is value of toupper('+')?

'+'.

What statement about dynamic variables is correct?

Dynamic variables are not declared, but are created during the execution of a program.

Suppose that you declare a bag(chapter4) like this: bag exercise; What is the initial capacity?

DEFAULT_CAPACITY

What would be the best description of the following function?void copyints(int target[ ], const int source[ ],size_t n)// Postcondition: source[0] through// source[n –1] have been copied to// target[0] through target[n –1].{ size_t i; for (i = 0; i < n; ++i) target[i] = source[i];}

The copyints function copies n elements from the front of the source array to the front of the target array. The source array arrays is set be a const parameter, and the target array is an ordinary array parameter.

Which statement of the following is the most appropriate?

The size of a dynamic array does not need to be determined until a program is running. Such behavior, determined at run time, is called dynamic behavior. Dynamic behavior is more flexible than decisions that are made at compile time (i.e., static behavior).

What are the invariant for the Third Bag Class in section 5.3?


a. The bag is empty.


b. The items in the bag are stored in a linked list.


c. The head pointer of the list is stored in the member variable head_ptr.


d. The total number of items in the list is stored in the member variable many_nodes.


e. The return data all need to be bag objects.

b, c, and d

What value does the default constructor of value_type give if the value_type is bool types?

False

What would be a good statement to set the tail pointer of a list(section 5.2) when a new first node has been added to the list? Assume that head_ptr points to the new first node.

if (head_ptr->link( )==NULL) tail_ptr = head_ptr;

Which one of the following statement will display the data value of the head_ptr of section 5.1?

(*head_ptr).data( );

What value does the default constructor of value_type give if the value_type is one of the built-in number(Section 5.1)?

0

What statement is most proer regarding: an implementation that uses previously defined linked-list functions, or manipulating a linked list directly?

Generally we will choose the approach that makes the best use of the previously written functions. This saves us work and also reduces the chance of new errors from writing new code to do an old job. The preference would change if writing new functions offered better efficiency.