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

Using C++. Please do the following: 3) Given a class “SmartPhone” that contains

ID: 3577879 • Letter: U

Question

Using C++. Please do the following:

3) Given a class “SmartPhone” that contains a method “int getNumberOfBars()”, write a class called “IPhone” that inherits from SmartPhone. IPhones will have a property called “int barStrength”. Write the code for the default constructor which uses the SmartPhone default constructor followed by setting the barStrength to 1. Then, override the getNumberOfBars method that simply returns a value of 5. After that, overload the getNumberOfBars method that takes the barStrength as an input parameter and returns that value as the number of bars.

Explanation / Answer

note* we can't set "SmartPhone default constructor followed by setting the barStrength to 1". because barStrength property was present in IPhone we can access it in SmartPhone class. so we get error if we mention barStrength to 1 in SmartPhone class

Here is code:

class SmartPhone {
public:

int getNumberOfBars();
};

// Derived class
class IPhone: public SmartPhone {
public:
int barStrength;
IPhone()
{
barStrength = 1;
}
int getNumberOfBars()
{
return 5;
}
int getNumberOfBars(int b)
{
barStrength = b;
return barStrength;
}
};

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