Data Structures and Algorithms in C++
Data Structures and Algorithms in C++
2nd Edition
ISBN: 9780470383278
Author: Michael T. Goodrich
Publisher: Wiley, John & Sons, Incorporated
bartleby

Videos

Question
Book Icon
Chapter 2, Problem 4P
Program Plan Intro

Collision of animals

Program plan:

  • Declare header file.
  • Declare namespace.
  • Create a class “Animal”,
    • Declare public access modifier.
    • Declare the default and parameterized constructor and public member functions.
    • Declare the necessary private member variables.
  • Define the default constructor to set the default values for the member variables.
  • Define the parameterized constructor to set the argument values to the variables.
  • Define the method “get_Type()” to return the type of animal.
  • Define the method “get_Gender()” to return the gender of animal.
  • Define the method “get_Strength()” to return the strength of animal.
  • Define the method “print_Animal()” to print the details of animal,
  • Define the method “collide1()”,
    • Create a new animal.
    • Call the method “print_Animal()” to print the details of animal.
    • Check whether the two animals are of same type,
      • If it is true check whether they are different gender,
        • If it is true, set the type.
        • Set the random gender.
        • Set the random strength.
        • Create new animal and print the details of animal.
      • Otherwise, check whether they have different strength,
        • If it is true, print the message and return the new animal.
      • Otherwise,
        • Print another corresponding message and return the new animal.
          • Otherwise,
            • Print corresponding message and return new animal.
  • Declare the method “printAll_Animals()”.
  • Define the method “main()”,
    • Initialize the random number generator.
    • Create vector of animals.
    • Create instances for Animal class.
    • Insert the instances into the vector.
    • Call the method “printAll_Animals()”.
    • Check whether there is empty type,
      • Insert into the vector.
      • Call the method “printAll_Animals()”.
  • Define the method “printAll_Animals()”.
    • Print the heading.
    • Execute till vector size,
      • Call the method “printl_Animal()”.
      • Print new line.

Blurred answer
Students have asked these similar questions
I would like to know the main features about the following 3 key concepts:1. Backup Domain Controller (BDC)2. Access Control List (ACL)3. Dynamic Memory
In cell C21, enter a formula to calculate the number of miles you expect to drive each month. Divide the value of number of miles (cell A5 from the Data sheet) by the average MPG for the vehicle multiplied by the price of a gallon of gas (cell A6 from the Data sheet).
Microsoft Excel
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY