I need the .ccp files for this problem please: C++ PROGRAMMING: POLYMORPHISM ASSIGNMENT INSTRUCTIONS OVERVIEW The object

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

I need the .ccp files for this problem please: C++ PROGRAMMING: POLYMORPHISM ASSIGNMENT INSTRUCTIONS OVERVIEW The object

Post by answerhappygod »

I need the .ccp files for this problem please:
C++ PROGRAMMING: POLYMORPHISM ASSIGNMENT INSTRUCTIONSOVERVIEWThe objective of this assignment is to give you some practice usinginheritance, virtual functions, and polymorphism. With a focus ondynamic binding, this program shifts the focus from design timestatic binding of functions to objects to run-time (or dynamicbinding). It leverages the use of virtual functions and introducesthe concept of abstract and concrete classes in its implementationof pure virtual functions as it also demonstrates polymorphicbehavior.
INSTRUCTIONS1. Create a base class called Insect. All insects belong to anOrder [i.e. “Hemiptera” (ants), “Siphonaptera” (fleas),“Termitoidae” (termites), “Gryllidae” (crickets), etc.] and have asize that is measured in millimeters (use a double data type).Provide a default constructor that initializes the size to zero andoutputs the message “Invoking the default Insect constructor” andanother constructor that allows the Order and size to be set by theclient. This other constructor should also output the message“Invoking the 2-argument Insect constructor.” Also create adestructor for this class that outputs the message “Invoking thedefault Insect destructor.” Your Insect class should have afunction called Eat that cannot be implemented. That is, it shouldbe declared as a purely virtual function. Your class should alsohave Get and Set methods to allow the order and size to beaccessed.
2. From the Insect class, derive Ant, Locust, Butterfly, andTermite classes. The derived classes should each have constructorsand destructors that output an appropriate message (e.g., the Antconstructor outputs “Invoking Ant constructor,” and the Antdestructor outputs “Invoking Ant destructor”). The constructor ofeach derived class should allow the Order and size of the Insect tobe set (think member initialization list). The derived classesshould each have a member function called Eat that overrides theInsect Eat version. Ant Eat should output “As an ant, I eateverything,” Locust Eat should output “As a locust, I eat leaves,”Butterfly Eat should output “As a butterfly, I eat nectar,” andTermite Eat should output “As a termite, I eat wood.”
3. Write a main function that uses the Insect and derivedclasses as needed to do the following. You must perform the actionsbelow in the sequence described (i.e., do not take a shortcutaround using dynamic memory allocation/deallocation and virtualmethods since they are the whole point of the lab).
a. Use the rand() function in a formula to generate a random sizein millimeters based on the insect selected.The range of sizes for each insect are as follows:Ant: .01 to 1.0 millimetersLocust: 10.5 to 50.0 millimetersButterfly: 40.0 to 75.5 millimetersTermite: 1.5 to 5.5 millimetersAs a refresher on the rand() function, recall that it generates aninteger between 0 and the largest integer that can be stored. Ifyou don’t want the low end of the range to start at 0, you add anumber to the rand() function that represents the smallest numberin the range of numbers you want to generate. This is the offset.Using the modulus operator (%), you can specify the interval. Forexample, to generate a random number between 2.75 and 4.00, you canuse this formula (note that since rand() generates an integer, thismultiplies the desired offset and interval by 100 and then dividingthe final result by 100.0):double randomNumber = ((rand() % interval ) + (offset))/100.0randomNumber = ((rand() % (125+1)) + (275))/100.0where 125 = 400-275“1” is added to the 125 to make the range inclusive on the upperend.
b. Your program should use a seed value of 100 for the randomnumber generator. You should set the seed only once at thebeginning of main(). Use the srand() function to set the seed.
c. Prompt the user to make an Insect selection [e.g. (1) forAnt, (2) for Locust, (3) for Butterfly, and (4) for Termite] and toenter 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 Orderand size. Save the object (use an array called “insects” – creditwill not be awarded if you use a vector for this). You may hardcodethe size of the array to hold 3 elements. That is, you don’t needto dynamically create this array unless you want to. If you dodynamically allocate it, though, be sure to deallocate its memoryproperly.
d. Repeat steps a. and b. 2 more times. You do not know whatinsects the user will select or in what order, so you must figureout how to create and store the appropriate objects. Notice thatthere are 4 insects from which to choose, but the user will onlymake 3 selections. Therefore, one insect will not be chosen.
e. After the user has entered all 3 selections, execute anotherloop that cycles through the 3 selections and invokes the Eatfunction and alsodisplays the Order and size of the insect. If youhave done it properly, each of your outputs will correspond to thetype of Insect the user selected in the order he or she enteredthem.
Your input screen should look something like this:
------------------------------------------
Main Menu
1- Ant
2- Locust
3- Butterfly
4- Termite
Enter Selection:
-----------------------------------------As each insect is selected, you should be prompted to enter theinsect’s Order:
------------------------------------------
Enter Selection: 3
Enter the Order associated with the insect you selected:WhateverOrder
-------------------------------------------As each insect is created, you should see messages like thefollowing:
------------------------------------------
Invoking insect two-argument constructor
Invoking butterfly two-argument constructor
-------------------------------------------Your final output screen shout look something like this:
-------------------------------------------
My order is WhateverOrder, and I am 43 millimeters long.
As a butterfly, I eat nectar.
My order is AnotherOrder, and I am 2 millimeters long.
As a termite, I eat wood.
My order is SomeOrder, and I am 25.2 millimeters long.
As a locust, I eat leaves.
Invoking the butterfly destructor
Invoking the insect destructor
Invoking the termite destructor
Invoking the insect destructor
Invoking the locust destructor
Invoking the insect destructor
-----------------------------------------------
Make sure that you code:
1) Has a virtual function as described above
2) Has a total of 9 files (4 header, 4 implementation, 1driver)
3) Uses an array, not a vector
4) Loops 3 times for 3 user selections
5) Uses constructors and destructors to output messages asdescribed
6) Uses the rand() function
Again, I need the .ccp files. It is fine to include the headers,but it WILL NOT HELP if you only give me headers. Thank you verymuch.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply