Question

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 of x
  • E. None of the above

3.Here is a small function that uses the dynamic bag class from Chapter 4:

    void quiz( )
    {
        bag::size_type i;   // Line 1
        bag b;              // Line 2

        b.insert(42);       // Line 3
        i = b.size( );      // Line 4
        cout << i;    // Line 5
    }

When is the bag's dynamic array allocated?

  • A. During the execution of Line 2.
  • B. During the execution of Line 3.
  • C. Just after Line 4 and before line 5.
  • D. After Line 5.

4.Here is a small function that uses the dynamic bag class from Chapter 4:

    void quiz( )
    {
        bag::size_type i;  // Line 1
        bag b;             // Line 2

        b.insert(42);      // Line 3
        i = b.size( );     // Line 4
        cout << i;   // Line 5
    }

When is the bag's dynamic array returned to the heap?

  • A. During the execution of Line 2.
  • B. During the execution of Line 3.
  • C. Just after Line 4 and before line 5.
  • D. After Line 5.

5.The + operator which combines two bags was not declared as a member function of the bag class. How can this function access the private data members of the two bags passed as arguments?

  • A. It cannot.
  • B. The operator is declared to be a friend to the class.
  • C. The operator is implemented in the header file containing the bag class definition.
  • D. The operator is implemented in the same implementation file as the bag class.

6.Suppose that a new foo class has this prototype for an overloaded assignment operator:

    void operator =(const foo& source);

In an assignment statement a = b, what will be the actual argument for the parameter source?

  • A. a
  • B. b

7.Suppose you are implementing an assignment operator, a copy constructor, and an operator +=. For which of these functions do you need to worry about possible "self-application" (where the argument is the same as the object that activates the function):

  • A. Only one of the three functions has possible self-application
  • B. The assignment operator and the copy construtor have possible self-application
  • C. The assignment operator and the operator += have possible self-application
  • D. The copy construtor and the operator += have possible self-application
  • E. All three functions have possible self-application

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

  • A. Constant time
  • B. Logarithmic time
  • C. Linear time
  • D. Quadratic time

9.When a class uses dynamic memory, what member functions should be provided by the class?

  • A. The assignment operator.
  • B. The copy constructor.
  • C. A destructor.
  • D. All of the above.

10.Which situation does not use the copy constructor?

  • A. Calling a function with a reference parameter
  • B. Calling a function with a value parameter
  • C. Declaring a variable to be a copy of another existing object
  • D. Returning a value from a function
  • E. All of the above situations use the copy constructor

11.Suppose that you want to declare an array of characters to hold a C++ string with exactly 9 letters. Which declaration is best?

  • A. char s[8];
  • B. char s[9];
  • C. char s[10];
  • D. char s[11];
  • E. char s[12];

12.Suppose that x and y are two C++ strings. Which expression will return true whenever x and y contain the same sequence of characters?

  • A. (x = y)
  • B. (x == y)
  • C. (x != y)
  • D. (strcmp(x, y))

13.Suppose that you want to develop two different + operators that calculate and return an object of some class. Which statement is correct?

  • A. One operator must be a friend and the other must not.
  • B. One operator must be public and the other private.
  • C. The operators must have a different parameter lists.
  • D. It is not possible to have two different + operators.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:-----------

  1. Yes
  2. A. 0
  3. A. During the execution of Line 2.
  4. D. After Line 5.
  5. B. The operator is declared to be a friend to the class.
  6. B. b
  7. C. The assignment operator and the operator += have possible self-application
  8. C. Linear time
  9. B. The copy constructor.
  10. ---------------
  11. B. char s[9];
  12. B. (x == y)
  13. C. The operators must have a different parameter lists.
Add a comment
Know the answer?
Add Answer to:
1.Suppose that the goop function from the previous question changes the value of z[1]. Does this...
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 =...

  • please write in c++. 4 Derived class JPG 4.1 Class declaration • The class JPG inherits...

    please write in c++. 4 Derived class JPG 4.1 Class declaration • The class JPG inherits from File and is a non-abstract class. 1. Hence objects of the class JPG can be instantiated. 2. To do so, we must override the pure virtual function clone() in the base class. • The class declaration is given below. class JPG : public File { public: JPG(const std::string& n, int n, int w, const double rgb()) : File(...) { // ... } *JPG()...

  • 2. (50 marks) A string in C++ is simply an array of characters with the null...

    2. (50 marks) A string in C++ is simply an array of characters with the null character(\0) used to mark the end of the string. C++ provides a set of string handling function in <string.h> as well as I/O functions in <iostream>. With the addition of the STL (Standard Template Library), C++ now provides a string class. But for this assignment, you are to develop your own string class. This will give you a chance to develop and work with...

  • C++ Assignment - Only Implementation file( VectorDouble.cpp file) required. The header file is already given. Please help, thumbs up guaranteed. Chapter 8 discussed vectors, which are like arrays that...

    C++ Assignment - Only Implementation file( VectorDouble.cpp file) required. The header file is already given. Please help, thumbs up guaranteed. Chapter 8 discussed vectors, which are like arrays that can grow in size. Suppose that vectors were not defined in C++. Define a class called VectorDoublethat is like a class for a vector with base type double. Your class VectorDoublewill have a private member variable for a dynamic array of doubles. It will also have two member variables of type...

  • 1. Here are codes to define a stack class based on dynamic array, please complete the...

    1. Here are codes to define a stack class based on dynamic array, please complete the copy constructor //--- Definition of Stack copy constructor Stack::Stack(const Stack & original) : myCapacity(original.myCapacity), myTop(original.myTop) { //--- Get new array for copy myArray = new(nothrow) StackElement[myCapacity]; if (myArray != 0) // check if memory available                         // copy original's array member into this new array {              // Please complete the function here        } else {          cerr << "*Inadequate memory to allocate...

  • In C++ and comment so I UNDERSTAND Implement a class named DynamicArray that has the following...

    In C++ and comment so I UNDERSTAND Implement a class named DynamicArray that has the following members: A pointer to hold a dynamically allocated array, of type int. A member variable to hold the size of the array. A default constructor, which will allocate an array of size 10 A parameterized constructor, which takes a size and use the size to allocate array. A copy constructor, which performs deep copy. A copy assignment operator, which performs deep copy and supports...

  • please write the code in C++ 2 Base class File 3 Derived class PDF 3.1 Class...

    please write the code in C++ 2 Base class File 3 Derived class PDF 3.1 Class declaration • The class PDF inherits from File and is a non-abstract class 1. Hence objects of the class PDF can be instantiated. 2. To do so, we must override the pure virtual function clone) in the base class • The class declaration is given below. • The complete class declaration is given below, copy and paste it into your file. . It is...

  • Can anyone explain this? 1. Suppose the following function is in the application program that uses...

    Can anyone explain this? 1. Suppose the following function is in the application program that uses the Coord class (Coord_app.cpp): int print_x(int x) { return x; } And we want to be able to do the following in main: int main() { Coord C1(5, 8); cout << get_x(C1) << endl; } The idea is that the function get_x expects an integer to be passed to it, but if a Coord object is passed to the function it will be converted...

  • Write a code in C++ by considering the following conditions :- Tasks :- 1. Create a...

    Write a code in C++ by considering the following conditions :- Tasks :- 1. Create a class Employee (with member variables: char * name, int id, and double age). 2. Create a constructor that should be able to take arguments and initialize the member variables. 3. Create a copy constructor for employee class to ensure deep copy. 4. Create a destructor and de allocate the dynamic memory. 5. Overload the assignment operator to prevent shallow copy and ensure deep copy....

  • Requirements Print a range Write a bag member function with two parameters. The two parameters are...

    Requirements Print a range Write a bag member function with two parameters. The two parameters are Items x and y. The function should write to the console all Items in the bag that are between the first occurrence of x and the first occurrence of y. You may assume that items can be compared for equality using ==. Use the following header for the function: void print_value_range(const Item& x, const Item& y); print_value_range can be interpreted in a number of...

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