asked 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.?

asked
User Maoizm
by
7.5k 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.
answered
User ColOfAbRiX
by
8.1k points
Welcome to Qamnty — a place to ask, share, and grow together. Join our community and get real answers from real people.