Given the following class definition, what is missing? class ItemClass \{ public: ItemClass(int newSize, float newCost); int getSize(); float getCost(); void setSize (int newSize); void setCost(float newCost); private: int size; float cost; \}; accessor functions a default constructor mutator functions nothing
Real Tutor Solution
Answer
Solution
Reviewed and approved by the UpStudy tutoring team
Extra Insights
To make the `ItemClass` fully functional, it needs a default constructor. A default constructor allows you to create an instance of `ItemClass` without specifying any parameters. Without it, if you ever want to create an `ItemClass` object without defining its size and cost right away, you’ll be left high and dry! Additionally, while you have accessor methods like `getSize()` and `getCost()`, it ensures your class provides clear access to these private members, fostering encapsulation. Those mutator methods like `setSize()` and `setCost()` will also help in modifying the internal state of your object after it’s created, adding a little flexibility!