10 Quick Questions. NO EXPLAINATION NECESSARY just the answer only. Will rate if
ID: 3607718 • Letter: 1
Question
10 Quick Questions. NO EXPLAINATION NECESSARY just the answer only. Will rate if fully complete.
Unless explicitly stated otherwise, every one of the following questions concern only the code found in the files Problem.cpp, Problem.h, Parent.h, Parent.cpp, Child1.h, Child1.cpp, Child2.h, Child2.cpp, Component.h, and Component.cpp
21. Study of the detailed output produced by Problem.cpp should convince you that the CHILD2 object— that was dynamically allocated from the heap and is pointed to by pchild2A—is destructed before the CHILD1 object, child1A, and the PARENT object, parent1. T or F? The CHILD2 object, *pchild2A, is destructed when the statement shown below is executed: If the statement shown below were removed, the CHILD2 object would not be destructed even when execution of the Problem.cpp function main() ends.
delete pchild2A;
22. T or F? The statements shown below (taken from the source file Parent.h) define two distinct and inheritable public static inline member functions in the PARENT class.
public:
static bool GetShowDetails() { return( showDetails ); }
static void SetShowDetails(bool TOrF) { showDetails = TOrF; }
23. (Continuing 22) GetShowDetails() and SetShowDetails() serve as accessor (or get) and mutator (or set) functions, respectively, T or F? for the information-hidden data member showDetails defined in the statements shown below.
protected:
static bool showDetails;
24. T or F? An application program that includes Parent.h (and links with Parent.obj) can directly access the PARENT protected data member name.
25. T or F? The PARENT constructor prototyped below is the default constructor for the PARENT class.
PARENT(TYPE type = NOTYPE,string name = DEFAULTNAME);
26. (Continuing 25) In the member initializer type(type) shown below, which occurrence of type is the reference to the PARENT data member type that is being initialized?
A: the first one B: the second one C: both of them D: neither of them
//---------------------------------------------------
PARENT::PARENT(TYPE type,string name):
type(type),name(name)
//---------------------------------------------------
27. (Continuing 25) T or F? The member initializer type(type) must be used to initialize the PARENT data member type.
28. (Continuing 25) T or F? The order of the member initializers in the function header cannot be changed.
29. (Continuing 25) The assignment statement shown below (that certainly could be included in the body of the PARENT constructor function) is obviated (made unnecessary) by the member initializer type(type). Should you choose to use the assignment statement method for initializing data members, T or F? the use of the this pointer is absolutely necessary to resolve the ambiguity caused by the overlapping scopes of the formal parameter type (function scope) and the PARENT data member type (class scope).
this->type = type;
30. T or F? The PARENT copy constructor never executes when you run Problem.cpp.
//---------------------------------------------------
// Dr. Art Hanna
// Chapter #11 Problem
// Problem.h
//---------------------------------------------------
#ifndef PROBLEM_H
#define PROBLEM_H
enum TYPE
{
NOTYPE=0,
PARENTTYPE=1,
CHILD1TYPE=2,
CHILD2TYPE=3,
CHILD3TYPE=4,
SUBCHILD1TYPE=5
};
#define DEFAULTNAME "[Default]"
#define DEFAULTCOMPONENT COMPONENT(0,0)
#define DEFAULTDESCRIPTION "Default description"
#define DEFAULTPATTERN 0
#define DEFAULTWEIGHT 0.00
#define INDENTION " "
#endif
//---------------------------------------------------
// Dr. Art Hanna
// Chapter #11 Problem
// Problem.cpp
//---------------------------------------------------
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
using namespace std;
#include ".Problem.h"
#include ".Parent.h"
#include ".Child1.h"
#include ".Component.h"
#include ".Child2.h"
//---------------------------------------------------
template<class TYPE>
void DisplayObject(TYPE object)
//---------------------------------------------------
{
if ( object.GetShowDetails() ) cout << " Start of DisplayObject() "
<< "------------------------ ";
TYPE copyOfObject;
copyOfObject = object;
copyOfObject.Print(); cout << endl;
if ( object.GetShowDetails() ) cout << "------------------------ "
<< "End of DisplayObject() ";
}
//---------------------------------------------------
int main()
//---------------------------------------------------
{
cout << "Start of main() ";
PARENT::SetShowDetails(true);
PARENT parent1(PARENTTYPE,"parent1");
DisplayObject(parent1);
CHILD1 child1A(CHILD1TYPE,"child1A",COMPONENT(1,1));
CHILD2 *pchild2A = new CHILD2(CHILD2TYPE,"child2A","a child2 object");
COMPONENT::SetShowDetails(false);
pchild2A->SetShowDetails(false);
DisplayObject(child1A);
DisplayObject(*pchild2A);
child1A.SetShowDetails(true);
PARENT *objects[] =
{
&parent1,
&child1A,
pchild2A
};
cout << " Start of for (int i = 0; i <= 2; i++) loop ";
cout << "------------------------------------------ ";
for (int i = 0; i <= 2; i++)
{
cout << "Correct? ", objects[i]->Print(), cout << endl;
cout << " ";
switch ( objects[i]->GetType() )
{
case NOTYPE:
cout << "Should not happen!!! ";
break;
case PARENTTYPE:
objects[i]->PARENT::Print();
break;
case CHILD1TYPE:
(*((CHILD1 *) objects[i])).CHILD1::Print();
break;
case CHILD2TYPE:
((CHILD2 *) objects[i])->CHILD2::Print();
// *OR* ((CHILD2 *) objects[i])->Print();, right?
break;
default:
cout << "Should not happen!!! ";
break;
}
cout << endl;
}
cout << "------------------------------------------ ";
cout << "End of for (int i = 0; i <= 2; i++) loop ";
delete pchild2A;
cout << " End of main() ";
system("PAUSE");
return( 0 );
}
//---------------------------------------------------
// Dr. Art Hanna
// Chapter #11 Problem
// Parent.h
//---------------------------------------------------
#ifndef PARENT_H
#define PARENT_H
#include ".Problem.h"
//---------------------------------------------------
class PARENT
//---------------------------------------------------
{
protected:
static bool showDetails;
public:
static bool GetShowDetails() { return( showDetails ); }
static void SetShowDetails(bool TOrF) { showDetails = TOrF; }
protected:
TYPE type;
string name;
public:
PARENT(TYPE type = NOTYPE,string name = DEFAULTNAME);
PARENT(const PARENT &RHS);
~PARENT();
PARENT &operator=(PARENT &RHS);
TYPE GetType() { return( type ); }
void Print();
};
#endif
//---------------------------------------------------
// Dr. Art Hanna
// Chapter #11 Problem
// Parent.cpp
//---------------------------------------------------
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
#include ".Problem.h"
#include ".Parent.h"
bool PARENT::showDetails = false;
//---------------------------------------------------
PARENT::PARENT(TYPE type,string name):
type(type),name(name)
//---------------------------------------------------
{
if ( showDetails ) cout << INDENTION << "Construction of ", Print(), cout << endl;
}
//---------------------------------------------------
PARENT::PARENT(const PARENT &RHS):
type(RHS.type),name(RHS.name)
//---------------------------------------------------
{
if ( showDetails ) cout << INDENTION << "Copy construction of ", Print(), cout << endl;
}
//---------------------------------------------------
PARENT::~PARENT()
//---------------------------------------------------
{
if ( showDetails ) cout << INDENTION << "Destruction of ", Print(), cout << endl;
}
//---------------------------------------------------
PARENT &PARENT::operator=(PARENT &RHS)
//---------------------------------------------------
{
if ( this != &RHS )
{
type = RHS.type;
name = RHS.name;
if ( showDetails ) cout << INDENTION << "Assignment of ", Print(), cout << endl;
}
return( *this );
}
//---------------------------------------------------
void PARENT::Print()
//---------------------------------------------------
{
cout << "PARENT(" << type << "," << name << ")";
}
//---------------------------------------------------
// Dr. Art Hanna
// Chapter #11 Problem
// Component.h
//---------------------------------------------------
#ifndef COMPONENT_H
#define COMPONENT_H
#include <iostream>
using namespace std;
#include ".Problem.h"
//---------------------------------------------------
class COMPONENT
//---------------------------------------------------
{
protected:
int x;
int y;
protected:
static bool showDetails;
public:
static bool GetShowDetails() { return( showDetails ); }
static void SetShowDetails(bool TOrF) { showDetails = TOrF; }
public:
COMPONENT(int x,int y);
COMPONENT(const COMPONENT &RHS);
~COMPONENT();
//friend:
friend ostream &operator<<(ostream &OUT,const COMPONENT &RHS);
};
#endif
//---------------------------------------------------
// Dr. Art Hanna
// Chapter #11 Problem
// Component.cpp
//---------------------------------------------------
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
#include ".Problem.h"
#include ".Component.h"
bool COMPONENT::showDetails = true;
//---------------------------------------------------
COMPONENT::COMPONENT(int x,int y):
x(x),y(y)
//---------------------------------------------------
{
if ( showDetails ) cout << INDENTION << "Construction of " << *this << endl;
}
//---------------------------------------------------
COMPONENT::COMPONENT(const COMPONENT &RHS)
//---------------------------------------------------
{
x = RHS.x;
y = RHS.y;
if ( showDetails ) cout << INDENTION << "Copy construction of " << *this << endl;
}
//---------------------------------------------------
COMPONENT::~COMPONENT()
//---------------------------------------------------
{
if ( showDetails ) cout << INDENTION << "Destruction of " << *this << endl;
}
//---------------------------------------------------
/*friend*/ostream &operator<<(ostream &OUT,const COMPONENT &RHS)
//---------------------------------------------------
{
OUT << "COMPONENT(" << RHS.x << "," << RHS.y << ")";
return( OUT );
}
//---------------------------------------------------
// Dr. Art Hanna
// Chapter #11 Problem
// Child1.h
//---------------------------------------------------
#ifndef CHILD1_H
#define CHILD1_H
#include ".Problem.h"
#include ".Parent.h"
#include ".Component.h"
//---------------------------------------------------
class CHILD1: public PARENT
//---------------------------------------------------
{
protected:
COMPONENT component;
public:
CHILD1(TYPE type = NOTYPE,string name = DEFAULTNAME,COMPONENT component = DEFAULTCOMPONENT);
CHILD1(const CHILD1 &RHS);
~CHILD1();
CHILD1 &operator=(CHILD1 &RHS);
void Print();
};
#endif
//---------------------------------------------------
// Dr. Art Hanna
// Chapter #11 Problem
// Child1.cpp
//---------------------------------------------------
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
#include ".Problem.h"
#include ".Parent.h"
#include ".Child1.h"
#include ".Component.h"
//---------------------------------------------------
CHILD1::CHILD1(TYPE type,string name,COMPONENT component):
PARENT(type,name),component(component)
//---------------------------------------------------
{
if ( showDetails ) cout << INDENTION << "Construction of ", Print(), cout << endl;
}
//---------------------------------------------------
CHILD1::CHILD1(const CHILD1 &RHS):
PARENT(RHS.type,RHS.name),component(RHS.component)
//---------------------------------------------------
{
if ( showDetails ) cout << INDENTION << "Copy construction of ", Print(), cout << endl;
}
//---------------------------------------------------
CHILD1::~CHILD1()
//---------------------------------------------------
{
if ( showDetails ) cout << INDENTION << "Destruction of ", Print(), cout << endl;
}
//---------------------------------------------------
CHILD1 &CHILD1::operator=(CHILD1 &RHS)
//---------------------------------------------------
{
if ( this != &RHS )
{
type = RHS.type;
name = RHS.name;
component = RHS.component;
if ( showDetails ) cout << INDENTION << "Assignment of ", Print(), cout << endl;
}
return( *this );
}
//---------------------------------------------------
void CHILD1::Print()
//---------------------------------------------------
{
cout << "CHILD1("; PARENT::Print(); cout << "," << component << ")";
}
//---------------------------------------------------
// Dr. Art Hanna
// Chapter #11 Problem
// Child2.h
//---------------------------------------------------
#ifndef CHILD2_H
#define CHILD2_H
#include ".Problem.h"
#include ".Parent.h"
//---------------------------------------------------
class CHILD2: public PARENT
//---------------------------------------------------
{
protected:
string description;
public:
CHILD2(TYPE type = NOTYPE,string name = DEFAULTNAME,string description = DEFAULTDESCRIPTION);
CHILD2(const CHILD2 &RHS);
~CHILD2();
CHILD2 &operator=(CHILD2 &RHS);
void Print();
};
#endif
//---------------------------------------------------
// Dr. Art Hanna
// Chapter #11 Problem
// Child2.cpp
//---------------------------------------------------
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
#include ".Problem.h"
#include ".Parent.h"
#include ".Child2.h"
//---------------------------------------------------
CHILD2::CHILD2(TYPE type,string name,string description):
PARENT(type,name),description(description)
//---------------------------------------------------
{
if ( showDetails ) cout << INDENTION << "Construction of ", Print(), cout << endl;
}
//---------------------------------------------------
CHILD2::CHILD2(const CHILD2 &RHS):
PARENT(RHS.type,RHS.name),description(RHS.description)
//---------------------------------------------------
{
if ( showDetails ) cout << INDENTION << "Copy construction of ", Print(), cout << endl;
}
//---------------------------------------------------
CHILD2::~CHILD2()
//---------------------------------------------------
{
if ( showDetails ) cout << INDENTION << "Destruction of ", Print(), cout << endl;
}
//---------------------------------------------------
CHILD2 &CHILD2::operator=(CHILD2 &RHS)
//---------------------------------------------------
{
if ( this != &RHS )
{
type = RHS.type;
name = RHS.name;
description = RHS.description;
if ( showDetails ) cout << INDENTION << "Assignment of ", Print(), cout << endl;
}
return( *this );
}
//---------------------------------------------------
void CHILD2::Print()
//---------------------------------------------------
{
cout << "CHILD2("; PARENT::Print(); cout << "," << description << ")";
}
Explanation / Answer
ANSWER
21) true
22) true
23) true
24) false
25) true
26) option c (both of them)
27) true
28) false
29) true
30) false
As mentioned there is no need of explanation i have provided all answers
Thank you
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.