Question

Multiple Choice Multiple Choice Section 2.1 - 2.2 Introduction to Classes Here is the start of...

Multiple Choice

Multiple Choice
Section 2.1 - 2.2
Introduction to Classes
  1. Here is the start of a class declaration:
        class foo
        {
        public:
          void x(foo f);
          void y(const foo f);
          void z(foo f) const;
          ...
    
    Which of the three member functions can alter the PRIVATE member variables of the foo object that activates the function?
    • A. Only x can alter the private member variables of the object that activates the function.
    • B. Only y can alter the private member variables of the object that activates the function.
    • C. Only z can alter the private member variables of the object that activates the function.
    • D. Two of the functions can alter the private member variables of the object that activates the function.
    • E. All of the functions can alter the private member variables of the object that activates the function.
  2. Is it possible for a member function of a class to activate another member function of the same class?
    • A. No.
    • B. Yes, but only public member functions.
    • C. Yes, but only private member functions.
    • D. Yes, both public and private member functions can be activated within another member function.
  3. Can two classes contain member functions with the same name?
    • A. No.
    • B. Yes, but only if the two classes have the same name.
    • C. Yes, but only if the main program does not declare both kinds
    • D. Yes, this is always allowed.
  4. What is the common pattern of class definitions that is used in Chapter 2?
    • A. Member functions and member variables are both private.
    • B. Member functions are private, and member variables are public.
    • C. Member functions are public, and member variables are private.
    • D. Member functions and member variables are both public.
  5. Consider this class definition:
        class quiz
        {
        public:
            quiz( );
            int f( );
            int g( ) const;
        private:
            double score;
        };
    
    Which functions can carry out an assignment score=1.0; to the private member variable score?
    • A. Both f and g can carry out the assignment.
    • B. f can carry out the assignment, but not g.
    • C. g can carry out the assignment, but not f.
    • D. Neither f nor g can carry out the assignment.
  6. What is the primary purpose of a default constructor?
    • A. To allow multiple classes to be used in a single program.
    • B. To copy an actual argument to a function's parameter.
    • C. To initialize each object as it is declared.
    • D. To maintain a count of how many objects of a class have been created.
  7. Suppose that the foo class does not have an overloaded assignment operator. What happens when an assignment a=b; is given for two foo objects?
    • A. The automatic assignment operator is used
    • B. The copy constructor is used
    • C. Compiler error
    • D. Run-time error
    Multiple Choice
    Section 2.4
    Classes and Parameters
  8. When should you use a const reference parameter?
    • A. Whenever the data type might be many bytes.
    • B. Whenever the data type might be many bytes, the function changes the parameter within its body, and you do NOT want these changes to alter the actual argument.
    • C. Whenever the data type might be many bytes, the function changes the parameter within its body, and you DO want these changes to alter the actual argument.
    • D. Whenever the data type might be many bytes, and the function does not change the parameter within its body.
  9. Here is a small function definition:
        void f(int i, int &k)
        {    
            i = 1;         
            k = 2;
        }                      
    
    Suppose that a main program has two integer variables x and y, which are given the value 0. Then the main program calls f(x,y); What are the values of x and y after the function f finishes?
    • A. Both x and y are still 0.
    • B. x is now 1, but y is still 0.
    • C. x is still 0, but y is now 2.
    • D. x is now 1, and y is now 2.
  10. Here is a function prototype and some possible function calls:
        int day_of_week(int year, int month = 1, int day = 1);
        // Possible function calls:
           cout << day_of_week( );
           cout << day_of_week(1995);
           cout << day_of_week(1995, 10);
           cout << day_of_week(1995, 10, 4);
    
    How many of the function calls are legal?
    • A. None of them are legal
    • B. 1 of them is legal
    • C. 2 of them are legal
    • D. 3 of them are legal
    • E. All of them are legal
    Multiple Choice
    Section 2.5
    Operator Overloading and Friends
  11. Which kind of functions can access private member variables of a class?
    • A. Friend functions of the class
    • B. Private member functions of the class
    • C. Public member functions of the class
    • D. All of the above can access private member variables
    • E. None of the above
0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
Multiple Choice Multiple Choice Section 2.1 - 2.2 Introduction to Classes Here is the start of...
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
  • 1. Write TWO different but equivalent statements to do the same thing: use a for statement...

    1. Write TWO different but equivalent statements to do the same thing: use a for statement to print the elements of array numbers by using pointer ptr. 2. Write an expression that uses ptr to copy element 1 (zero-based) of the array to element 3. Do not use numbers in the array in Here is the start of a class declaration: class foo { public: void x(foo f); void y(const foo f); void z(foo f) const; ... 3. Which of...

  • Data Structures using C++ Here is the start of a class declaration: class ClassA { public:...

    Data Structures using C++ Here is the start of a class declaration: class ClassA { public:        void func1(const ClassA& a);        void func2(const ClassA& a) const;        void func3(ClassA a) const;        ... Which of the three member functions can alter the private member variables of the ClassA object that activates the function? A. None of the three functions. B. Only func1.       C. Only func2.       D. Only func3. E. Only two of the three functions.

  • 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...

  • 2 Class Vec Message1 2.1 Introduction • Write a class Vec Message1 with the following declaration....

    2 Class Vec Message1 2.1 Introduction • Write a class Vec Message1 with the following declaration. class Vec_Message1 { public: Vec_Message1(); Vec_Message1(int n); Vec_Message1(int n, const Message1 &a); Vec_Message1(const Vec_Message1 &orig); Vec_Message1& operator= (const Vec_Message1 &rhs); ~Vec_Message1(); int capacity() const; int size() const; Message1 front() const; Message1 back() const; void clear(); void pop_back(); void push_back(const Message1 &a); Message1& at(int n); private: void allocate(); void release(); int _capacity; int _size; Message1 * _vec; }; 2.2 allocate() and release() • Examine the...

  • I need help implementing class string functions, any help would be appreciated, also any comments throughout...

    I need help implementing class string functions, any help would be appreciated, also any comments throughout would also be extremely helpful. Time.cpp file - #include "Time.h" #include <new> #include <string> #include <iostream> // The class name is Time. This defines a class for keeping time in hours, minutes, and AM/PM indicator. // You should create 3 private member variables for this class. An integer variable for the hours, // an integer variable for the minutes, and a char variable for...

  • c++ Error after oveloading, please help? LAB #8- CLASSES REVISITED &&    Lab #8.5 …      Jayasinghe...

    c++ Error after oveloading, please help? LAB #8- CLASSES REVISITED &&    Lab #8.5 …      Jayasinghe De Silva Design and Implement a Program that will allow all aspects of the Class BookType to work properly as defined below: class bookType { public:    void setBookTitle(string s);            //sets the bookTitle to s    void setBookISBN(string ISBN);            //sets the private member bookISBN to the parameter    void setBookPrice(double cost);            //sets the private member bookPrice to cost    void setCopiesInStock(int noOfCopies);            //sets the private member copiesInStock to...

  • Please answer all the questions thank you 1) (Classes – 20 Points) Consider the following class...

    Please answer all the questions thank you 1) (Classes – 20 Points) Consider the following class declaration for Time to complete the questions below: DO NOT WRITE MORE THAN ASKED FOR. class Time private: int hours; int minutes; public: Time(); Time (int , int m = 0); void addMin(int m); void addHr(int h); void reset(int h = 0, int m = 0); Time operator+(const Time & t) const; Time operator-(const Time & t) const; Time operator*(double n) const; friend Time...

  • Redefining Base Functions (C++) Create two simple C++ classes (Use separate files please and include appropriate...

    Redefining Base Functions (C++) Create two simple C++ classes (Use separate files please and include appropriate headers) Define a base class named "Venue" that holds the following member variables and functions: Type of venue (string), e.g. public venue, private venue, community venue Year opened (int) Capacity (int) Base price (float), holds the average ticket price for the venue Potential revenue (float), a function returning capacity * base price Next, define a class named "Theater" that is derived from the "Venue"...

  • Objectives: 1. Classes and Data Abstraction?2. User-defined classes?3. Implementation of a class in separate files Part...

    Objectives: 1. Classes and Data Abstraction?2. User-defined classes?3. Implementation of a class in separate files Part 1: In this assignment, you are asked: Stage1:?Design and implement a class named memberType with the following requirements: An object of memberType holds the following information: • Person’s first name (string)?• Person’s last name (string)?• Member identification number (int) • Number of books purchased (int)?• Amount of money spent (double)?The class memberType has member functions that perform operations on objects of memberType. For the...

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