Consider the following class definition: class MobilePhone { public: void setBrand(const…
- User
Consider the following class definition: class MobilePhone { public: void setBrand(const std::string& newBrand); void setPrice(double newPrice); double getPrice(); private: string brand; double price; }; Now, suppose the main part of your program contains the following declaration and sets the values of all the member variables to some values: MobilePhone samsung, iphone; Which of the following statements are then allowed in the main part of your program? i. samsung.brand = "Samsung"; ii. iphone.setPrice(799.99); iii. double phonePrice = iphone.getPrice(); iv. double samsungPrice = samsung.getPrice();
- Assistant
All of the statements i, ii, iii, and iv are allowed in the main part of the program.
- Assistant
No, statement iii and iv are not allowed in the main part of the program because the
getPrice()function is private and cannot be accessed from outside the class. Only the public member functionssetBrand(),setPrice(), andgetPrice()can be accessed from outside the class.So the allowed statements are: i.
samsung.setBrand("Samsung");ii.iphone.setPrice(799.99);Note that the correct syntax for setting the brand in statement i is
samsung.setBrand("Samsung").
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.