You are provided here with the header files for classes Pare

You are provided here with the header files for classes Parent and Child, each of which has one constructor declared. Write the code below using best practices. Assume all functions have been defined other than what you have to write below.//headers, other functions, etc.//a. Write the definition for the constructor of Child Write the child\'s overloaded output operator definition below Do not worry about formatting, but be sure to output the value of each data member. Place its declaration in Child\'s, and its definition in Child.cpp.

Solution

parent:

Parent :: Parent(double x)
{
cout<<\"parent id like\"<<x;
}
double Parent :: getX()
{
double i;
cin>>i;
return i;
}

child:

Child :: Child(double x,int a,char c)
{
cout<<\"parent id\"<<x<<\"child id\"<<a<<\"child character\"<<c;
}
int Child::getA()
{
int i;
cin>>i;
return i;
}
char Child::getC()
{
char i;
cin>>i;
return i;
}


a)
constructor is a kind of member function that initializes an instance of its class.
child constructor is a constructor. it is parameter constructor(not default constructor) why because
it have function parameters like x,a,c by different data types.

b)
child.h:
//output operator declaration
friend std::ostream& operator<< (std::ostream &out, const Point &point);

child.cpp:
//implementation

std::ostream& operator<< (std::ostream &out, const Point &point)
{
    out <<\"parent id\"<<Child.x<<\"child id\"<<Child.a<<\"child character\"<<Child.c;
    return out;
}

definition:
normal or default output operator is used to display built in data types.
overloaded output operator is used to display the user defined data types like objects

 You are provided here with the header files for classes Parent and Child, each of which has one constructor declared. Write the code below using best practices
 You are provided here with the header files for classes Parent and Child, each of which has one constructor declared. Write the code below using best practices

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site