Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE ANSWER ALL Who needs to know about the invariant of an ADT? Flag this Que

ID: 3756110 • Letter: P

Question

PLEASE ANSWER ALL

Who needs to know about the invariant of an 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?

Flag this Question

Question 3 10 pts

Which statement of the following is the most appropriate?

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?

Flag this Question

Question 5 10 pts

What does the following do?


#include <iostream> // Provides cout and cin
#include <cstdlib> // 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 can’t 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;
      }
}

Flag this Question

Question 6 10 pts

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

Flag this Question

Question 7 10 pts

Consider the following statements:

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

Flag this Question

Question 8 10 pts

What is printed by these statements?

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);
    }

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.

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.

Flag this Question

Question 12 10 pts

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

Flag this Question

Question 13 10 pts

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

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)

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)?

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 bag’s definition?

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 doesn’t, 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 doesn’t, 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 doesn’t, 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 doesn’t, 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 doesn’t, 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?

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?

Flag this Question

Question 20 10 pts

What C++ function generates a pseudorandom integer?

Neither the programmer who implements the class nor the programmer who uses the class.

Explanation / Answer

Please Note: The post contains more than One Question, as per the Chegg Answering Guidelines, I have answered the first question. For receiving the answers to the rest of the Questions, please Re-post for the other Questions.

Answers)

Q1)

Answer)

C. Only the programmer who implements the class for the ADT

Only the programmer who implements

the class for the ADT needs to know about the invariant of an ADT.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote