Question: Jump to level 1 In the class definition, initialize the data members, string name, string color, and string type, with the default values Incomplete, Unknown,

Jump to level 1
In the class definition, initialize the data members, string name, string color, and string type, with the default values "Incomplete",
"Unknown", and "Unstated", respectively.
Ex: If the input is Dan camel pig, then the output is:
Name: Incomplete, Color: Unknown, Type: Unstated
Name: Dan, Color: camel, Type: pig
Note: The class's print function is called first after the default constructor, then again after the inputs are passed to the setters.
Here the code:
#include
#include
using namespace std;
class Animal {
public:
void SetName(string animalName);
void SetColor(string animalColor);
void SetType(string animalType);
void Print();
private:
/* Your code goes here */
};
void Animal::SetName(string animalName){
name = animalName;
}
void Animal::SetColor(string animalColor){
color = animalColor;
}
void Animal::SetType(string animalType){
type = animalType;
}
void Animal::Print(){
cout "Name: " name ", Color: " color ", Type: " type endl;
}
int main(){
string newName;
string newColor;
string newType;
Animal favoriteAnimal;
favoriteAnimal.Print();
cin >> newName;
cin >> newColor;
cin >> newType;
favoriteAnimal.SetName(newName);
favoriteAnimal.SetColor(newColor);
favoriteAnimal.SetType(newType);
favoriteAnimal.Print();
return 0;
}
 Jump to level 1 In the class definition, initialize the data

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!