Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE ANSWER ALL Who needs to know about the invariant of an ADT? Neither the programmer who implements the class nor the programmer who uses

PLEASE ANSWER ALL

Who needs to know about the invariant of an ADT?

Neither the programmer who implements the class nor the programmer who uses the class.
Both the programmer who implements the class and the programmer who uses the class.
Only the programmer who implements the class for the ADT.
Only the programmer who uses the class for the ADT.

Flag this Question

Question 2 10 pts

This question is appropriate if you implemented the sequence class. The sequence's insert member function normally puts a new item before the current item. What does insert do if there is no current item?

The new item is put at the beginning of the sequence.
The insert precondition is violated.
The new item is put at the end of the sequence.
None of the above.

Flag this Question

Question 3 10 pts

Which statement of the following is the most appropriate?

A container class is a class where each object contains a collection of items. Bags and sequences are two examples of container classes; the C++ Standard Library does not provide any container class.
A container class is a class where each object contains a collection of items. Bags and sequences are two examples of container classes; the C++ Standard Library also provides a variety of flexible container classes.
A container class is a class where each class contains a collection of items. Bags and sequences are two examples of container classes; the C++ Standard Library also provides a variety of flexible container classes.
A container class is a class where each class contains a collection of items. Bags and sequences are two examples of container classes; the C++ Standard Library does not provide any container class.

Flag this Question

Question 4 10 pts

For a sequence(Chapter3) of numbers, suppose that you attach 1, then 2, then 3, and so on up to n. What is the big-O time analysis for the combined time of attaching all n numbers?

O ( n )
O( n2 )
O ( n log n )
O ( log n )
O ( 1 )

Flag this Question

Question 5 10 pts

What does the following do?

#include // Provides cout and cin #include // Provides EXIT_SUCCESS #include "bag1.h" // chapter 3 bag1 with value_type defined as an int using namespace std; using namespace main_Chapter3_1;

// PROTOTYPES for functions used by this program:

void get_ages(bag& ages); // Postcondition: The user has been prompted to type in the ages of family members. These // ages have been read and placed in the ages bag, stopping when the bag is full or when the // user types a negative number.

void check_ages(bag& ages); // Postcondition: The user has been prompted to type in the ages of family members again. // Each age is removed from the ages bag when it is typed, stopping when the bag is empty.

int main( ) { bag ages; get_ages(ages); check_ages(ages); cout << "May your family live long and prosper." << endl; return EXIT_SUCCESS; }

void get_ages(bag& ages)

{ int user_input; cout << "Type the ages in your family." << endl; cout << "Type a negative number when you are done:" << endl; cin >> user_input; while (user_input >= 0) { if (ages.size( ) < ages.CAPACITY) ages.insert(user_input); else cout << "I have run out of room and cant add that age." << endl; cin >> user_input; } }

void check_ages(bag& ages) { int user_input; cout << "Type those ages again. Press return after each age:" << endl; while (ages.size( ) > 0) { cin >> user_input; if (ages.erase_one(user_input)) cout << "Yes, I've found that age and removed it." << endl; else cout << "No, that age does not occur!" << endl; } }

asks the user for a list of family member ages, the program will validate the ages(>=0), double check the inputed ages and then prints the list in the same order that it was given.
The program does not do anything as listed above.
asks the user for a list of family member ages, the program will validate the ages(>=0) and then double check the inputed ages.
asks the user for a list of family member ages, then prints the list in the same order that it was given.
asks the user for a list of input bag class member, double check the inputed bag and then prints the list in the same order that it was given.

Flag this Question

Question 6 10 pts

Which statement of the following is the most appropriate?(Ch3)

Our own bag class is based on the STLs multiset class. The multiset class does not require any template instantiation (to specify the type of the underlying elements), but it has iterators to step through the items one after another.
Our own bag class is based on the STLs multiset class. However, the multiset class requires a template instantiation (to specify the type of the underlying elements), and it has iterators to step through the items one after another.
Our own bag class is based on the STLs multiset class. The multiset class does not require any template instantiation (to specify the type of the underlying elements), or it does not have any iterator to step through the items one after another.
Our own bag class is based on the STLs multiset class. However, the multiset class requires a template instantiation (to specify the type of the underlying elements), but it does not have any iterator to step through the items one after another.

Flag this Question

Question 7 10 pts

Consider the following statements:

int *p; 
int i; 
int k; 
i = 42; 
k = i; 
p = &i; 

After these statements, which of the following statements will change the value of i to 75?

k = 75;
*p = 75;
p = 75;
Two or more of the answers will change i to 75.
*k = 75;

Flag this Question

Question 8 10 pts

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; 
1
2
4
3

Flag this Question

Question 9 10 pts

Can the following implementation work correctly for a bag x self-assignment ( x = x )(Section 4.3)?

void bag::operator =(const bag& source) // Library facilities used: algorithm { value_type *new_data; // Check for possible self-assignment: if (this == &source) return; // If needed, allocate an array with a different size: if (capacity != source.capacity) { new_data = new value_type[source.capacity]; delete [ ] data; data = new_data; capacity = source.capacity; } // Copy the data from the source array: used = source.used; copy(source.data, source.data + used, data); }

Most of the time yes.
No
Yes
Sometime yes and sometime no
Most of the time no.

Flag this Question

Question 10 10 pts

What would be the invariant(s) for the revised Bag Class in section 4.3?

1. The number of items in the bag is in the member variable used. 2. The actual items of the bag are stored in a partially filled array. The array is a dynamic array, pointed to by the member variable data. 3. The total size of the dynamic array is in the member variable capacity.

1 and 2
1, 2 and 3
1 and 3
1 only

Flag this Question

Question 11 10 pts

What statements about the destructor of an object are accurate?

a. The destructor of a class is a member function that is automatically activated when an object becomes inaccessible.

b. The destructor has no arguments and its name must be the character ~ followed by the class name (e.g., ~bag for the bag class).

c. Because the destructor is automatically called, programs rarely make explicit calls to the destructor, and we generally omit the destructor from the documentation that tells how to use the class.

d. The primary responsibility of the destructor is simply releasing dynamic memory.

a & b
a, b, & c
b & c
a, b, c, & d
c & d

Flag this Question

Question 12 10 pts

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

The user has been prompted for a size n, and this size has been read.
The pointer p has been set to point to a new dynamic array containing n doubles.
The user has been prompted for a variable n, and this n has been read. The pointer p has been set to point to a new dynamic array containing n doubles with 0 value in them.
The user has been prompted for a size n, and this size has been read. The pointer p has been set to point to a new dynamic array containing n doubles.

Flag this Question

Question 13 10 pts

Which expression computes a pseudorandom integer between -10 and 10 using rand() from stdlib.h?

(rand( ) % 21) - 11
(rand( ) % 22) - 10
(rand( ) % 20) - 11
(rand( ) % 21) - 10
(rand( ) % 20) - 10

Flag this Question

Question 14 10 pts

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

None of (A), (B), and (C) have a constant worst-case time
ALL of (A), (B), and (C) have a constant worst-case time
TWO of (A), (B), and (C) have a constant worst-case time
count
erase_one
insert

Flag this Question

Question 15 10 pts

What would be the best answer to why is a precursor node pointer necessary in the linked-list implementation of a sequence class(Section 5.4)?

A precursor node pointer is necessary in the sequence class because its insert function adds a new item at the current node. Because the linked-list toolkits insert function adds an item at a specified node, the precursor node is designated as that node.
A precursor node pointer is necessary in the sequence class because its insert function adds a new item immediately before the current node. Because the linked-list toolkits insert function adds an item after a specified node, the precursor node is designated as that node.
A precursor node pointer is necessary in the sequence class because its insert function adds a new item immediately after the current node. Because the linked-list toolkits insert function adds an item before a specified node, the precursor node is designated as that node.
Because the linked-list toolkits insert function adds an item after a specified node, the precursor node is designated as that node.
A precursor node pointer is necessary in the sequence class because its insert function adds a new item immediately before the current node.

Flag this Question

Question 16 10 pts

In a linked-list implementation of a bag (section 5.3), why is it a good idea to typedef node::value_type as value_type in the bags definition?

Yes, it is a good idea. The definition makes bag::value_type the same as node::value_type, so that a programmer can use bag::value_type to replace all the data types.
No, it is not a good idea. The definition makes bag::value_type the same as node::value_type, so that programmer can not know what would be a correct data type.
No, it is not a good idea. The definition makes bag::value_type different from node::value_type, although a programmer can use bag::value_type but will have tough time to really have a good grasp of the data.
Yes it is a good idea. The definition makes bag::value_type the same as node::value_type, so that a programmer can use bag::value_type without having to know the details of the linked-list implementation.
Yes it is a good idea, The definition makes bag::value_type become the only data type can be used in the program.

Flag this Question

Question 17 10 pts

What would be the best description of a new member function to remove a specified item from a sequence(Section 5.4)? The function has one parameter (the item to remove). After the removal, the current item is the item after the removed item (if there is one). You may assume that value_type has == and != operators defined.

First check that the item occurs somewhere in the list. If it doesnt, then return with no work.

If the item is in the list, then set the erase item to be equal to this item, and call the ordinary erase_one function.

First check that the item occurs somewhere in the list. If it doesnt, then return with no work.

If the item is in the list, then set the current item to be equal to this item, and call the ordinary erase_one function.

First check that the item occurs somewhere in the list. If it doesnt, then return with no work.

If the item is in the list, then call the ordinary erase_one function.

First check that the item occurs somewhere in the list. If it doesnt, then return with no work.

If the item is in the list, then set the first item to be equal to this item, and call the ordinary erase_one function.

First check that the item occurs somewhere in the list. If it doesnt, then return with no work.

If the item is not in the list, then set the current item to be equal to first item, and call the ordinary erase_one function.

Flag this Question

Question 18 10 pts

What underlying data structure is quickest for random access?

array
structure
bag
node
sequence

Flag this Question

Question 19 10 pts

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

head_ptr.data( );
(*head_ptr).data( );
*head_ptr.data( );
*head_ptr;
(head_ptr->data)( );

Flag this Question

Question 20 10 pts

What C++ function generates a pseudorandom integer?

The ranMax function from csdtlib generates a non-negative pseudorandom integer.
The rand function from system generates a non-negative pseudorandom integer.
The rand function from csdtlib generates a non-negative pseudorandom integer.
The srand function from csdtlib generates a non-negative pseudorandom integer.
The srand function from system generates a non-negative pseudorandom integer.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introductory Relational Database Design For Business With Microsoft Access

Authors: Jonathan Eckstein, Bonnie R. Schultz

1st Edition

1119329418, 978-1119329411

More Books

Students also viewed these Databases questions

Question

How flying airoplane?

Answered: 1 week ago