Write the definition of the function setdata of the class


Discuss the below:

Q: What is wrong with the following code?

class classA
{
protected:
void setx(int a);
//Postcondition: x = a
private:
int x;
};
.
.
.
int main()
{
classA aObject;

aObject.setx(4);
return 0;
}

Consider the following code:

class one
{
public:
void print() const;
//Outputs the values of x and y.
protected:
void setData(int u, int v);
//Postcondition: x = u; y = v
private:
int x;
int y;
};

class two: public one
{
public:
void setData(int a, int b, int c);
//Postcondition: x = a; y = b; z = c
void print() const;
//Outputs the values of x, y, and z.
private:
int z;
};

a. Write the definition of the function setData of the class two.

b. Write the definition of the function print of the class two.

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Write the definition of the function setdata of the class
Reference No:- TGS01937822

Now Priced at $25 (50% Discount)

Recommended (90%)

Rated (4.3/5)