C++ Advanced Programming

Instructions are attached. Thank you
C++ Programming: Polymorphism Assignment Instructions
The objective of this assignment is to give you some practice using inheritance, virtual functions, and polymorphism.With a focus on dynamic binding, this program shifts the focus from design time static binding of functions to objects to run-time (or dynamic binding).It leverages the use of virtual functions and introduces the concept of abstract and concrete classes in its implementation of pure virtual functions as it also demonstrates polymorphic behavior.
1. Create a base class called
. All insects belong to an
[i.e. “Hemiptera” (ants),“Siphonaptera” (fleas), “Termitoidae” (termites), “Gryllidae” (crickets), etc.] and have a
that is measured in millimeters (use a double data type). Provide a default constructor that initializes the size to zero and outputs the message “Invoking the default Insect constructor” and another constructor that allows the Order and size to be set by the client. This other constructor should also output the message “Invoking the 2-argument Insect constructor.”Also create a destructor for this class that outputs the message “Invoking the default Insect destructor.” Your Insect class should have a function called
that cannot be implemented.That is, it should be declared as a
purely virtual
function. Your class should also have Get and Set methods to allow the order and size to be accessed.
2. From the Insect class, derive Ant, Locust, Butterfly, and Termite classes. The derived classes should each have constructors and destructors that output an appropriate message (e.g., the Ant constructor outputs “Invoking Ant constructor,” and the Ant destructor outputs “Invoking Ant destructor”). The constructor of each derived class should allow the Order and size of the Insect to be set (think member initialization list). The derived classes should each have a member function called Eat that overrides the Insect Eat version. Ant Eat should output “As an ant, I eat everything,” Locust Eat should output “As a locust, I eat leaves,” Butterfly Eatshould output “As a butterfly, I eat nectar,” and Termite Eat should output “As a termite, I eat wood.”
3. Write a main function that uses the Insect and derived classes as needed to do the following. You must perform the actions below in the sequence described (i.e., do not take a shortcut around using dynamic memory allocation/deallocation and virtual methods since they are the whole point of the lab).
a. Use the rand() function in a formula to generate a random size in millimeters based on the insect selected.
The range of sizes for each insect are as follows:
.01 to 1.0 millimeters
10.5 to 50.0 millimeters
40.0 to 75.5 millimeters
1.5 to 5.5 millimeters
As a refresher on the rand() function, recall that it generates an integer between 0 and the largest integer that can be stored.If you don’t want the low end of the range to start at 0, you add a number to the rand() function that represents the smallest number in the range of numbers you want to generate.This is the
.Using the modulus operator (%), you can specify the
.For example, to generate a random number between 2.75 and 4.00, you can use this formula (note that since rand() generates an integer, I am multiplying the desired offset and interval by 100 and then dividing the final result by 100.0):
double randomNumber = ((rand() % interval ) + (offset))/100.0
randomNumber = ((rand() % (125+1)) + (275))/100.0
where 125 = 400-275
“1” is added to the 125 to make the range inclusive on the upper end.
for this assignment…
An alternative to using the rand() function is to use the uniform_real_distribution class, which is described in section 13-6 of your textbook.It’s actually much easier to use and more robust in terms of generating random numbers that are more random.The rand() function is somewhat predictable, but it’s still used in programs today.It’s always good to know both techniques, though.In this assignment, though, to receive credit for generating the random number, you
use the rand() function.
b. Your program should use a
value of 100 for the random number generator.You should set the seed only once at the beginning of main().Use the
() function to set the seed.
c. Prompt the user to make an Insect selection [e.g.(1) for Ant, (2) for Locust, (3) for Butterfly, and (4) for Termite] and to enter an Order for the insect. Dynamically create an Ant, Locust, Butterfly, or Termite object (depending on what the user entered) and initialize it with a constructor to which is passed its Order and size. Save the object (use an
array called “insects” – credit will not be awarded if you use a vector for this
).You may hardcode the size of the array to hold 3 elements.That is, you don’t need to dynamically create this array unless you want to.If you do dynamically allocate it, though, be sure to deallocate its memory properly.
d. Repeat steps a. and b. 2 more times. You do not know what insects the user will select or in what order, so you must figure out how to create and store the appropriate objects. Notice that there are 4 insects from which to choose, but the user will only make 3 selections.Therefore, one insect will not be chosen.
e. After the user has entered all 3 selections, execute another loop that cycles through the 3 selections and invokes the
function and also displays the Order and size of the insect. If you have done it properly, each of your outputs will correspond to the type of Insect the user selected in the order he or she entered them.
Your input screen should look something like this:
As each insect is selected, you should be prompted to enter the insect’s Order:
As each insect is created, you should see messages like the following:
Your final output screen shout look something like this:
· Complete the programming assignment described above and submit your completed assignment in accordance with the lab submission policies.
To give you an idea of the general criteria that will be used for grading, here is a checklist that you might find helpful:

Compiles and Executes without crashing

Word document contains screen shots and integrity statements

Appropriate internal documentation


No global variables

Code is modular

Appropriate Pre-processing and using directives

Member functions and variables are declared with appropriate protection (i.e. private or public)

Correct implementation of inheritance to enable polymorphism


Base Insect class

Correct Private Data Members

Constructors/destructor function appropriately (correct number of constructors, number ofarguments, output of messages, etc.)

Correct get and set functions

Derived Ant, Locust, Butterfly, and Termite classes

Correct Private Data Members

Constructors/destructors function appropriately (correct number of constructors, number ofarguments, output of messages, etc.)

Correct get and set functions

Program functionality

Eat function implementation and usage

Dynamic allocation of insects

Random generation of insect sizes

Output contains appropriate information

Array used to store 3 insects correctly

Memory is deallocated appropriately
Page 2 of 2

Place your order
(550 words)

Approximate price: $22

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
The price is based on these factors:
Academic level
Number of pages
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more