Data structures and algorithms in C++
Data structures and algorithms in C++
2nd Edition
ISBN: 9780470460443
Author: Goodrich
Publisher: WILEY
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
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.
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