Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

First fragment: class ClassOne{ public: ClassOne(); ClassOne(int, int); int m_member1; int func1(); private: int member2; void func2(int); }; class ClassTwo{ public: ClassTwo(); ClassTwo(double); ClassOne m_data1;

First fragment:

class ClassOne{

public:

ClassOne();

ClassOne(int, int);

int m_member1;

int func1();

private:

int member2;

void func2(int);

};

class ClassTwo{

public:

ClassTwo();

ClassTwo(double);

ClassOne m_data1;

double m_data2;

};

1.Suppose that x is a ClassOne object. Which of the following expressions can be used to invoke the member function func1()?

a. x-> func1()

b. ClassOne::func1()

c. (*x).func1()

d. x.func1()

Second Fragment:

ClassTwo *ptr;

ptr = new ClassTwo(3.1);

2.Using the class definitions for ClassOne and ClassTwo in Question #1, suppose that a ClassTwo pointer ptr is defined as above. Which constructors are invoked? *

a. The default constructor for ClassOne and the default constructor for ClassTwo are invoked.

b. The alternate constructor for ClassOne and the default constructor for ClassTwo are invoked.

c. The default constructor for ClassOne and the alternate constructor for ClassTwo are invoked.

d. The alternate constructor for ClassOne and the alternate constructor for ClassTwo are invoked.

3. After the code in program fragment #2 is executed, how can we access the ClassOne data member called m_member1 using ptr? *

a. ptr->m_data1->m_member1

b. ptr.m_data1->m_member1

c. ptr->m_data1.m_member1

d. ptr.m_data1.m_member1

Third Fragment:

ClassOne::ClassOne(){

int local=13;

m_member1=15;

}

4. Consider the ClassOne constructor above. What is the difference between local and m_member1?

a. m_member1 is already defined in ClassOne, but local is added as a member after the constructor is executed.

b. the storage for local goes away after the constructor finishes, but the storage for m_member1 persists for as long as the host object exists.

c. m_member1 is accessible by func1(), but local is not accessible by func1() because it is not public.

d. There is no difference between local and m_member1. They are both data members of the ClassOne object being created by the constructor.

5. Considering the definitions of ClassOne and ClassTwo in Question #1, which of the following statements has access to the private member function func2( )? *

a. any statement in any function that declares an object of ClassOne can access func2( ) through that object.

b. any statement in the implementation of the ClassOne member function func1( ).

c. any statement in the implementation of the ClassTwo alternate constructor.

d. all of the above

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Case Studies In Business Data Bases

Authors: James Bradley

1st Edition

0030141346, 978-0030141348

More Books

Students also viewed these Databases questions