Ask Question
10 April, 17:37

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);

+2
Answers (1)
  1. 10 April, 20:44
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers