This is C++ Suppose your program contains the following class definition: class
ID: 3665487 • Letter: T
Question
This is C++
Suppose your program contains the following class definition: class Automobile { public: void set_price(double new_price); void set_profit(double new_profit); double get_price(); prvate: double price; double profit; double get_profit (); }; and suppose the main part of your program contains the following declarations and that the program somehow sets the values of all the member variables to some values Automobile hyundai, jaguar; Which of the following statements are then allowed in the main part of your program? a. hyundai.price = 4999.99; b. jaguar.set_price(30000.97); c. double a_price, a_profit; ; d. a_price = jaguar.get_price(); e. a_profit = jaguar.get_profit(); f. a_profit = hyundai. get_prof it () ; g. if (hyundai ==jaguar) coutExplanation / Answer
b,c,d are allowed in main function
Concept: We can't access the private member of the object but we can access the public member of object in main function
Explanation: a: It is not allowed because it is trying to access the private variable "price" in main method.
b: It is allowed because set_price is public function in class.
c: It is allowed because it is just a local variable declaration in main function.
d: It is allowed because it is invoking public function get_price() of object.
e: It is not allowed because get_profit() is the private function.
f: It is not allowed because get_profit() is the private function.
g: You can't directly compare two object. For this to be possible, you need to overload the comparison(==) operator.
f: You can't directly copy one object into the other. For this to be possilbe you need to overload the assignment operator or you need to use a copy constructor.
If you have any doubt then please comment below and please don't forget to give the feedback :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.