Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

4. Given the following code: struct Circle { int radius; }; struct Cylinder : pu

ID: 665792 • Letter: 4

Question

 4. Given the following code:      struct Circle {      int radius;    };     struct Cylinder : public Circle {      int height;    };    Circle *cirptr, cir;    Cylinder *cylptr, cyl;     Which of the following statements are legal?    cirptr = &cyl;   cylptr = ○   cirptr = cylptr;   cylptr = cirptr;  -------------------------------------------------------------------- 5. Which of the following operator functions are legal?    For those not legal, indicate why not.   a. Complex Complex::operator+(const Complex& a) const {...}   b. Clock Clock::operator++(int) {...}   c. Menu Menu::operator++(const Menu& a, const Menu& b) {...}   d. Menu Menu::operator**(const Menu& a) const {...}  --------------------------------------------------------------------  6. a) What behavior can occur when overloaded conversion operators     and/or single argument constructors are defined for a class?        b) What can you do in the class design to eliminate the problem    for single argument constructors?        c) Assuming the class needs to provide conversion capabilities,     what can you do in the class design to eliminate the problem    for conversion operators? 

Explanation / Answer

4) from the above program we can get information that cylinder is getting inheroted from Cirlce class
So from above options we can choose best option is-------- cylptr = ○
as circle object value is assigned to cylinder class...it will overide that object
since it is inherited.

5)
a. Complex Complex::operator+(const Complex& a) const {...}
---here operator + declared..which is wrong initialization

b)Clock Clock::operator++(int) {...}
this is valid...if parametres are passed that are matched to clock....like int / double...

c) c. Menu Menu::operator++(const Menu& a, const Menu& b) {...}   
---here operator ++ declared..which is wrong initialization. for menu we must give ** instead of ++

d. Menu Menu::operator**(const Menu& a) const {...}
---explained in above statement

----------------------------------------------------------------------------

6)
a)It may throw errors..since compiler may not decide which function to run

b)
to avoid single parametrized constructors..use setter methods.

c)Use type casting is one of the solution for this.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote