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

Assume that a definition of the class Automobile has a composite object called m

ID: 642316 • Letter: A

Question

Assume that a definition of the class Automobile has a composite object called myEngine of the class Engine. Also assume that all the data members of class Engine that contain information about the engine (such as displacement, horsepower, torque, etc.) are all private data members of the Engine class.

Write the function prototype that would be required for an object of class Automobile to access the data member horsepower of the myEngine object, and explain your answer. Include what kind of a function this is, what class it would be defined in, what its access attribute is, and why it is necessary

Explanation / Answer

Assume that a definition of the class Automobile has a composite object called myEngine of the class Engine. Also assume that all the data members of class Engine that contain information about the engine (such as displacement, horsepower, torque, etc.) are all private data members of the Engine class.
Write the function prototype that would be required for an object of class Automobile to access the data member horsepower of the myEngine object,

//Function Prototype
double getHorsePower(){
   return horsepower;
}

Include what kind of a function this is its accessor function in class Engine.

, what class it would be defined in,   it will be defined in class Engine.

what its access attribute is   it is public as it needs to be accessed by class Automobile.

, and why it is necessary it is necessary because Automobile need access to horsepower.

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