Question 1A)= What is the output of the following program? class Top { protected
ID: 3688926 • Letter: Q
Question
Question 1A)=What is the output of the following program?
class Top
{ protected:
int a;
public:
Top(int a1) { a =a1;}
};
class Bottom : public Top { int b;
public:
Bottom(int p, int q) : Top(q) { b = p; }
void Display () { cout << "a: " <<a << ", b: " << b; }
};
int main()
{ Bottom barrel(4, 5); barrel.Display();
}
Question )=1B What would go wrong with this program if data member 'a' were changed to private status?
Question 3)=
In this program, within the class, add prototypes for
a constructor that works, for all the objects, result begins with 0,0
friend operator function for '+' to add two complex numbers
a unary member opeator function for '~' to change a complex number to its conjugate. You might need this
a member function for Display of a complex number
class Complex { float x, y;
};
int main()
{ Complex z1(2,3), z2(4,5);
Complex result;
result = z1 + z2; ~result; result.Display();
if (z1 == z2)
cout << "same"; else
cout << "different";
}
Write the code for these four functions below:
class Top
{ protected:
int a;
public:
Top(int a1) { a =a1;}
};
class Bottom : public Top { int b;
public:
Bottom(int p, int q) : Top(q) { b = p; }
void Display () { cout << "a: " <<a << ", b: " << b; }
};
int main()
{ Bottom barrel(4, 5); barrel.Display();
}
Question )=1B What would go wrong with this program if data member 'a' were changed to private status?
Question 3)=
In this program, within the class, add prototypes for
a constructor that works, for all the objects, result begins with 0,0
friend operator function for '+' to add two complex numbers
a unary member opeator function for '~' to change a complex number to its conjugate. You might need this
a member function for Display of a complex number
class Complex { float x, y;
};
int main()
{ Complex z1(2,3), z2(4,5);
Complex result;
result = z1 + z2; ~result; result.Display();
if (z1 == z2)
cout << "same"; else
cout << "different";
}
Write the code for these four functions below:
Explanation / Answer
Answers:)
Output for 1A)
a: 5, b: 4
1B) error: within this context is obtained if data member 'a' were changed to private status because private access specifier allows to access the data members only within the class in which it is defined.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.