128k views
2 votes
Define the yesterday class's setweather() mutator that sets data member weather to yesterday weather and the sethumidity() mutator that sets data member humidity to yesterday humidity.?

User Maoizm
by
7.0k points

1 Answer

3 votes

Final answer:

The setWeather() and setHumidity() mutators are methods that update the weather and humidity data members of a class to reflect yesterday's weather and humidity. They enhance data encapsulation by controlling access to the state of objects.

Step-by-step explanation:

To define the setWeather() and setHumidity() mutators for a class, we assume that the class is already defined and it has two private data members: weather and humidity.

The setWeather() mutator will typically take one parameter, which represents yesterday's weather, and set the private data member weather to this value. Similarly, the setHumidity() mutator will take a parameter representing yesterday's humidity level and update the private data member humidity accordingly.

Here is an example in a programming language like C++:

void setWeather(string w) {
weather = w;
}

void setHumidity(double h) {
humidity = h;
}
It's important to use these mutators to encapsulate the internal state of an object, allowing for controlled access to its properties.
User ColOfAbRiX
by
7.9k points