137k views
0 votes
Write a class "Dog" with a private int field called months and two public member functions setAge and GetStage. setAge takes as argument monthsToSet and sets the member field months. setAge returns void. getStage is a const member function that takes no argument and returns a string "Puppy" if the dog is less than 9 months old, "Adolescence" if more than 9 and less than 13 months, "Adulthood" if more than 13 and less than 60 months and "Senior" otherwise. The main should create a Dog called Buddy, set its age to 14 and cout the string returned by GetStage.

User Dadep
by
5.3k points

1 Answer

4 votes

Answer:

see explaination

Step-by-step explanation:

#include <iostream>

using namespace std;

class Dog {

int months;

public:

void SetAge(int mnths);

string GetStage() const;

//FIXME: Add declarations of member functions and fields

};

//FIXME: Add definitions of member functions

void Dog::SetAge(int mnths)

{

months = mnths;

}

string Dog::GetStage() const

{

if(months<9)

return string("Puppy");

else if(months<13)

return string("Adolescence");

else if(months<60)

return string("Adulthood");

else

return string("Senior");

}

int main() {

Dog buddy;

buddy.SetAge(14);

cout << buddy.GetStage();

return 0;

}

See attachment for screenshot and output.

Write a class "Dog" with a private int field called months and two public-example-1
User Morgi
by
4.3k points