-->
当前位置:首页 > 题库

PROGRAMMING:Animal World

Luz5年前 (2021-05-10)题库608
Supplementary procedure:
1. Methods to implement the mammal class
2. The dog class is derived from the mammal class, and the itscolor member (color type) is added to the dog class
3. Add the following methods to the dog class:
constructors: Dog()、Dog(int age)、Dog(int age, int weight)、Dog(int age, COLOR color)、 Dog(int age, int weight, COLOR color)、~Dog()
accessors: GetColor()、SetColor()
Other methods: Wagtail (), begforfood (), and implement the above methods.
Tip: for actions like speak(), wagtail(), the function body can output a sentence. For example: mammal is spaeking..., the dog is wagging its tail
4. Supplement the question mark part of the main function, and run the program to check whether the output is reasonable.
```
enum COLOR{ WHITE, RED, BROWN, BLACK, KHAKI };
class Mammal
{
public:
//constructors
Mammal();
Mammal(int age);
~Mammal();
//accessors
int GetAge() const;
void SetAge(int);
int GetWeight() const;
void SetWeight(int);
//Other methods
void Speak() const;
void Sleep() const;
protected:
int itsAge;
int itsWeight;
};
int main()
{
Dog Fido;
Dog Rover(5);
Dog Buster(6, 8);
Dog Yorkie(3, RED);
Dog Dobbie(4, 20, KHAKI);
Fido.Speak();
Rover.WagTail();
cout << "Yorkie is " << ?? << " years old." << endl;
cout << "Dobbie weighs " << ?? << " pounds." << endl;
return 0;
}
```
###Input format:
nothing
###Output format:
Output according to program format.
###Input example:
Here is a set of inputs. For example:
```in
nothing
```
###Output example:
The corresponding output is given here. For example:
```out
Mammal is speaking...
The dog is wagging its tail...
Yorkie is 3 years old.
Dobbie weighs 20 pounds.
```







answer:If there is no answer, please comment