Final answer:
The question asks about defining a class in C++ with default values for its data members. The solution is to use a constructor to initialize string 'name' to 'Unknown' and integer 'rating' to 1. Two methods, setName and setRating, are used to update the values, and a print function displays them.
Step-by-step explanation:
The student is asking how to initialize data members in a class with default values in C++ programming. Specifically, they want to set a string called name to "Unknown" and an integer called rating to 1 by default.
To achieve this, you will need to use a constructor in your class definition to set the default values upon the object's creation. Here is how you could write your class:
class Restaurant {
private:
string name;
int rating;
public:
Restaurant() : name("Unknown"), rating(1) {}
void setName(string newName) { name = newName; }
void setRating(int newRating) { rating = newRating; }
void print() const {
cout << "Name: " << name << "'s Bistro's Buffet, Rating: " << rating << endl;
}
};
After defining the class, you create an object and call the print method twice, as per the instructions: first to print the default values, and then again after using the setters to update the object with the provided input.