Company is the base class that holds • Data fields named companyID (of integer type), and companyName (of string type). • A two-argument constructor to initialize data-fields with user-defined values • Appropriate accessor and mutator functions to set and get values of data fields Derive two classes from the Company class: • MobilePhone, which contains an attribute mobiulePhoneName of string type, mobileID of integer type, mobilePrice of integer type and setters and getters member function of all data members • Laptop which contains an string variable named laptopName along with a member function to set laptop name • Both derived classes have function display to show all data field values (including values inherited from the base class).
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Company is the base class that holds
• Data fields named companyID (of integer type), and companyName (of string type).
• A two-argument constructor to initialize data-fields with user-defined values
• Appropriate accessor and mutator functions to set and get values of data fields
Derive two classes from the Company class:
• MobilePhone, which contains an attribute mobiulePhoneName of string type, mobileID
of integer type, mobilePrice of integer type and setters and getters member function of all
data members
• Laptop which contains an string variable named laptopName along with a member
function to set laptop name
• Both derived classes have function display to show all data field values (including values
inherited from the base class).
In the main() function, create objects of MobilePhone and Laptop classes and show the advantages
of using protected access specifier.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 5 images