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

PROGRAMMING:The growth of pets

Luz5年前 (2021-05-10)题库456
Now we need to develop a system to manage the growth status of pets.
The following basic class framework is given
class Pet
{
protected:
  string name;// full name
int length;// length
int weight;// Weight
int current;// Current date
public:
virtual void display(int day)=0;// Output the length and weight of the target date
}
Based on pet, cat and dog classes are constructed
Cat gains 1 in length and 2 in weight.
Dog adds two to his length and one to his weight.
Generate the above class and write the main function, which requires a base class pet pointer array with no more than 10 elements.
Pet *pt[10];
According to the input information, the main function establishes cat class object or dog class object, and gives the pet's length and weight on the target date.
Input format: each test case occupies one line, and each line gives the basic pet information. The first is the current pet type: 1 is cat, 2 is dog. The next is its name, the next two numbers are body length and weight, and the last is the date of measuring body length and weight (a positive integer no more than 10). The last line is the target date (a positive integer greater than 10).
The target date, pet name, length and weight are required
Hint: using virtual function to realize polymorphism
Input sample
1 Marry 22 12 5
2 Jack 10 9 9
1 Jim 11 8 6
eleven
Output sample
Marry 28 24
Jack 14 11
Jim 16 18






answer:If there is no answer, please comment