Question
C++ In the Moose class, complete the function definition for SetAge() that takes in the integer parameter newAge. Ex: If the input is beige Pat
C++
In the Moose class, complete the function definition for SetAge() that takes in the integer parameter newAge.
Ex: If the input is beige Pat 11, then the output is:
Color: beige Name: Pat Age: 11
using namespace std;
class Moose { public: void SetColor(string newColor); void SetName(string newName); void SetAge(int newAge); string GetColor() const; string GetName() const; int GetAge() const; private: string color; string name; int age; };
void Moose::SetColor(string newColor) { color = newColor; }
void Moose::SetName(string newName) { name = newName; }
/* Your code goes here */ { age = newAge; }
string Moose::GetColor() const { return color; }
string Moose::GetName() const { return name; }
int Moose::GetAge() const { return age; }
int main() { Moose moose1; string userColor; string userName; int userAge;
cin >> userColor; cin >> userName; cin >> userAge;
moose1.SetColor(userColor); moose1.SetName(userName); moose1.SetAge(userAge); cout << "Color: " << moose1.GetColor() << endl; cout << "Name: " << moose1.GetName() << endl; cout << "Age: " << moose1.GetAge() << endl;
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started