Ask Question

Given the following class, what would be the best declaration for a mutator function that allows the user of the class to change the age?

class Wine

{

public:

Wine ();

int getAge ();

float getCost ();

private:

int age;

float cost;

}

a. int getAge (int newAge);

b. Wine ();

c. void setAge ();

d. void setAge (int newAge);

+4
Answers (1)
  1. 21 August, 12:01
    0
    Option D void setAge (int newAge);

    Explanation:

    In object oriented programming, mutator method is defined to change the value of the data member (s) in the class. Since the mutator method is aimed to change the value of a class data member, it is required to take in one new value as parameter to overwrite the existing value of data member. The mutator doesn't return any output. Hence, the best declaration for a mutator method to change the age is

    void setAge (int newAge);

    The new value of age is passed to parameter newAge and the void means the method doesn't return any value as output.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Given the following class, what would be the best declaration for a mutator function that allows the user of the class to change the age? ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers