Question

Multiple Choice Multiple Choice Section 3.1 The Bag ADT For the bag class in Chapter 3...

Multiple Choice

Multiple Choice
Section 3.1
The Bag ADT
  1. For the bag class in Chapter 3 (using a fixed array and a typedef statement) what steps were necessary for changing from a bag of integers to a bag of double values?
    • A. Change the array declaration from
      int data[CAPACITY] to double data[CAPACITY] and recompile.
    • B. Change the int to double in the typedef statement and recompile.
    • C. Round each double value to an integer before putting it in the bag.
    • D. Round each double value to an integer after taking it out of the bag.
  2. Who needs to know about the invariant of an ADT?
    • A. Only the programmer who implements the class for the ADT.
    • B. Only the programmer who uses the class for the ADT.
    • C. Both the programmer who implements the class and the programmer who uses the class.
    • D. Neither the programmer who implements the class nor the programmer who uses the class.
  3. Suppose that the bag 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
  4. 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
  5. 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. Choose the best description of b's member variables after we execute these statements:
        bag b;
        b.insert(5);
        b.insert(4);
        b.insert(6);
    
    What will be the values of b.used and b.data after the statements?
    • A. b.used is 3, b.data[0] is 4, b.data[1] is 5, and b.data[2] is 6
    • B. b.used is 3, b.data[0] is 5, b.data[1] is 4, and b.data[2] is 6
    • C. b.used is 3, b.data[0] is 6, b.data[1] is 4, and b.data[2] is 5
    • D. b.used is 3, b.data[0] is 6, b.data[1] is 5, and b.data[2] is 4
  6. 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
  7. 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.)
    • A. (data[i] != 42) && (i < n)
    • B. (data[i] != 42) || (i < n)
    • C. (i < n) && (data[i] != 42)
    • D. (i < n) || (data[i] != 42)
    • E. More than one of the above answers is correct.
  8. 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
    Multiple Choice
    Section 3.2
    The Sequence ADT
  9. 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.
  10. 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.
  11. 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
  12. 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?
    • A. The bag has an extra array of Items.
    • B. The bag has one extra size_t variable.
    • C. The sequence has an extra array of Items.
    • D. The sequence has one extra size_t variable.
  13. 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.
  14. Suppose that the bag 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. TWO of the above are likely to have a constant worst-case time.
    • D. ALL of (A), (B), and (C) are likely to have a constant worst-case time.
    Multiple Choice
    Section 3.3
    Interactive Test Programs
  15. 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
0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

1)

OPTION B IS CORRECT

2)

OPTION A IS CORRECT

3)

OPTION A IS CORRECT

4)

OPTION B IS CORRECT

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Multiple Choice Multiple Choice Section 3.1 The Bag ADT For the bag class in Chapter 3...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Multiple Choice Multiple Choice Section 4.1 Pointers and Dynamic Memory Consider the following statements: int *p;...

    Multiple Choice Multiple Choice Section 4.1 Pointers and Dynamic Memory 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? A. k = 75; B. *k = 75; C. p = 75; D. *p = 75; E. Two or more of the answers will change i to 75. Consider the following statements: int i =...

  • 1.Suppose that the goop function from the previous question changes the value of z[1]. Does this...

    1.Suppose that the goop function from the previous question changes the value of z[1]. Does this change effect the value of the actual argument? A. Yes B. No 2.Here is a function declaration: void goo(int* x) { *x = 1; } Suppose that a is an int* variable pointing to some integer, and *a is equal to zero. What is printed if you print *a after the function call goo(a)? A. 0 B. 1 C. address of a D. address...

  • c++ Sequence class is a class that supports sequence of integers. Run the project ad verify...

    c++ Sequence class is a class that supports sequence of integers. Run the project ad verify that project works for integers. Next convert your sequence class into a template class. Demonstrate in your main function by using a sequence of int, float, string. sequence.cxx #include // Provides assert using namespace std; namespace main_savitch_3 { sequence::sequence() { used = 0; current_index = 0; } void sequence::start() { current_index = 0; } void sequence::advance() // Library facilities used: assert.h { assert(is_item()); current_index++;...

  • members of a class non-friends, non-members of a class All of the above be 13. Why...

    members of a class non-friends, non-members of a class All of the above be 13. Why do you want to usually make data members private in a class? so that no one can use the class ensure data integrity b. provide data abstraction c provide information hiding. d. e. Band D B.C and D 14. The copy constructor for a class is called when an object of the class is passed by value to a function. when an object of...

  • PLEASE HURRY. Below is the prompt for this problem. Use the code for bag1.cxx, bag1.h and...

    PLEASE HURRY. Below is the prompt for this problem. Use the code for bag1.cxx, bag1.h and my code for bag.cpp. Also I have provided errors from linux for bag.cpp. Please use that code and fix my errors please. Thank you The goal of assignment 3 is to reinforce implementation of container class concepts in C++. Specifically, the assignment is to do problem 3.5 on page 149 of the text. You need to implement the set operations union, intersection, and relative...

  • In class, we discussed the priority queue (PQ) ADT implemented using min-heap. In a min-heap, the...

    In class, we discussed the priority queue (PQ) ADT implemented using min-heap. In a min-heap, the element of the heap with the smallest key is the root of the binary tree. On the other hand, a max-heap has as root the element with the biggest key, and the relationship between the keys of a node and its parent is reversed of that of a min-heap. We also discussed an array-based implementation of heaps. In this assignment, your task is to...

  • The purpose of this lab is to help reinforce container class concepts and linked list concepts...

    The purpose of this lab is to help reinforce container class concepts and linked list concepts in C++. Specifically, the lab to repeat the sequence lab from last week except to use a linked list. You need to use the author's files sequence3.h and sequence_exam3.cpp. Author - Michael Main, Book - Data Structures and other objects using c++, 4th edition // FILE: sequence3.h // CLASS PROVIDED: sequence (part of the namespace main_savitch_5) // This is the header file for the...

  • The purpose of this program is to help reinforce container class concepts and linked list concepts...

    The purpose of this program is to help reinforce container class concepts and linked list concepts in C++. Specifically, the task is to implement the sequence class using a linked list. You need to use the author's file sequence3.h to create your implementation file named sequence3.cpp. Please make your code as efficient and reusable as possible. Please make sure code can pass any tests. sequence3.h // FILE: sequence3.h // CLASS PROVIDED: sequence (part of the namespace main_savitch_5) // This is...

  • You will write the following files: mystack.h - contains the class definition for the mystack class....

    You will write the following files: mystack.h - contains the class definition for the mystack class. mystack.cpp - contains the definitions for member functions of the mystack class. inpost.cpp - contains your convert() function. inpost.h - contains the function prototype for convert() so that the main() can call it. Each of the files (with the exception of inpost.h) is described in more detail below. All header files should contain header guards to prevent them from being included multiple times in...

  • 41. True or False? Searching the components of an unordered list ADT is faster with a...

    41. True or False? Searching the components of an unordered list ADT is faster with a linked list representation than with a direct array representation. a) true b) false 42. True or False? If an operation that allows random access to individual components of a list ADT is defined and occurs frequently, it is better to represent the list directly as an array than to use a linked list. a) true b) false 43. To prevent a compile-time error, how...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT