1. Suppose that foo is a new class and you want to declare an array of 10 foo ob
ID: 644902 • Letter: 1
Question
1. Suppose that foo is a new class and you want to declare an array of 10 foo objects. Which constructor will be used to initialize the 10 foo components of the array?
A. Only the copy constructor can be used
B. Only the default constructor can be used
C. Any constructor can be used
2.
Suppose that the bag class is efficiently implemented with a fixed array with a capacity of 4000, as in Chapter 3 of the class text. We execute these statements:
bag b;
b.insert(5);
b.insert(4);
b.insert(6);
b.erase_one(5);
A. b.used is 2, b.data[0] is 4, b.data[1] is 6
B. b.used is 2, b.data[0] is 6, b.data[1] is 4
C. b.used is 3, b.data[0] is 4, b.data[1] is 6
D. b.used is 3, b.data[0] is 6, b.data[1] is 4
3. 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?
A. Negative 4,000,000,000 to positive 4,000,000,000.
B. Zero to positive 32,767
C. Zero to positive 65,535
D. Zero to 4,000,000,000
E. Zero to 8,000,000,000
4. In Chapter 3, there was a suggested implementation of the sequence class with a fixed CAPACITY and these private member variables:
class sequence
{
public:
typedef double value_type;
typedef std::size_t size_type;
static const size_type CAPACITY = 30;
...
private:
value_type data[CAPACITY];
size_type used;
};
The sequence's constructor sets used to zero, but does not place any values in the data array. Why?
A. Integer arrays are automatically initialized to zero.
B. The first activation of insert or attach initializes the entire array.
C. The array initialization was part of the project that was left to the student.
D. The programmer who uses the sequence is responsible for initializing the array.
E. When a sequence is first created, none of the array is being used.
5. 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?
A. The insert precondition is violated.
B. The new item is put at the beginning of the sequence.
C. The new item is put at the end of the sequence.
D. None of the above.
6. Suppose that the sequence is implemented with a fixed-size array. Which of these operations are likely to have a constant worst-case time?
A. insert
B. count
C. erase_one
D. None of (A), (B), and (C) have a constant worst-case time
E. TWO of (A), (B), and (C) have a constant worst-case time
F. ALL of (A), (B), and (C) have a constant worst-case time
7. 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.
A. Both removal functions have constant worst-case run times.
B. The bag's removal is constant time, but the sequence's removal is not.
C. The sequence's removal is constant time, but the bag's removal is not.
D. Neither removal function has constant worst-case run time.
8. What is the best C++ statement to use when a program must choose between several alternatives that are controlled by the value of a single variable?
A. do-while statement
B. for-statement
C. if-else statement
D. switch statement
E. while statement
Explanation / Answer
1. Suppose that foo is a new class and you want to declare an array of 10 foo objects. Which constructor will be used to initialize the 10 foo components of the array?
B. Only the default constructor can be used
2.
Suppose that the bag class is efficiently implemented with a fixed array with a capacity of 4000, as in Chapter 3 of the class text. We execute these statements:
bag b;
b.insert(5);
b.insert(4);
b.insert(6);
b.erase_one(5);
C. b.used is 3, b.data[0] is 4, b.data[1] is 6
3. 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?
D. Zero to 4,000,000,000
4. A. Integer arrays are automatically initialized to zero.
5.B. The new item is put at the beginning of the sequence.
6.B. count
7.B. The bag's removal is constant time, but the sequence's removal is not.
8. What is the best C++ statement to use when a program must choose between several alternatives that are controlled by the value of a single variable?
D. switch statement
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.