(COMP2012)[2014](s)final_=in8gpimcc^_56359.pdf

I 4 marks write a function animaleatorganisms which

Info icon This preview shows pages 16–20. Sign up to view the full content.

(i) [4 marks] Write a function animalEatOrganisms , which has 2 input parameters: animal and orgVec . Inside this function, all organism objects stored in orgVec will be eaten by the (COMP2012)[2014](s)final~=in8gpimcc^_56359.pdf downloaded by xjiae from at 2018-03-13 17:27:35. Academic use within HKUST only.
Image of page 16

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Page 17 of 23 animal . Note that the organisms consumed by the animal should be deallocated/deleted from the memory. The function should clear (making empty) the vector orgVec before returning. void animalEatOrganisms(Animal* animal, vector<Organism*>& orgVec) { for (int i=0; i<orgVec.size(); i++) { animal->eat(orgVec[i]); delete orgVec[i]; // If no “delete” is applied // orgVec[i]->setLifePoint(0); // set a zero or negative value } orgVec.clear(); } (ii) [5 marks] A crazy monkey eats a banana, an opium and an ant. Their attributes are as follows: Object Name Type Description crazyMonkey Animal Its initial life point is 110 units The list of victim is given below: Object Name Type Description banana HealthyPlant Its initial life point is 10 units and the weight is 5 units Opium PoisonPlant Its initial life point is 6 units, the weight is 10 units and the degree of poison is 2.5 units. Photosynthesis should be conducted on Opium once and its weight should be increased by 10% before it is eaten by the crazy monkey. ant Animal The initial life point is 10 units (COMP2012)[2014](s)final~=in8gpimcc^_56359.pdf downloaded by xjiae from at 2018-03-13 17:27:35. Academic use within HKUST only.
Image of page 17
Page 18 of 23 The expected output is as follows: crazyMonkey's initial life point : 110 crazyMonkey's final life point: 5 Please complete the following main function. Please note that you MUST call animalEatOrganisms defined above for the crazy monkey to eat each of the organisms. int main() { vector<Organism*> orgVec; Animal *crazyMonkey = new Animal(110.0); HealthyPlant *banana = new Plant(5, 10); PoisonPlant *opium = new PoisonPlant(2.5, 10, 6); Animal *ant = new Animal(10.0); opium->photosynthesis(10.0); // +10% weight orgVec.push_back(banana); orgVec.push_back(opium); orgVec.push_back(ant); cout << "crazyMonkey's initial life point : " << crazyMonkey->getLifePoint() << endl; animalEatOrganisms(crazyMonkey, orgVec); cout << "crazyMonkey's final life point: " << crazyMonkey->getLifePoint() << endl ; delete crazyMonkey; return 0; } (COMP2012)[2014](s)final~=in8gpimcc^_56359.pdf downloaded by xjiae from at 2018-03-13 17:27:35. Academic use within HKUST only.
Image of page 18

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Page 19 of 23 Q4 Manipulations on a Family Tree [21 marks] A family tree represents descendant and ascendant relationships using a tree structure. We show in Figure 1 below an example of a family tree, where the children of a parent are ordered in descending seniority from left to right. In the figure, George has three children: Sarah, William and David. The most senior child, Sarah has two children, elder Edward and younger Annie. William has a child named Harry, and the youngest son of George, David, has one child named Charles.
Image of page 19
Image of page 20
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern