Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Description Objective: practice writing and testing a class. Create and test a Plant class. You will enhance the Plant class in the future labs. Specifications
Description
Objective: practice writing and testing a class.
Create and test a Plant class. You will enhance the Plant class in the future labs.
SpecificationsRequirements
Plant class
plant class manages one plant only
member variables to store
number of branches
number of roots
name
mutator function to
write setPlant function to set all member variables
accessor functions to return
number of branches
number of roots
a plant object as a string toString for example, Rose
function to grow a plant by applying water and sun; levels of watering and sun are randomly generated
water
nothing happens
grows branch
grows branches
grow branches and root
sun
nothing happens
grows root
grows roots
main
an array of plants
a menu with the following options
print the array of plants name number of branches and roots in a table format with headings
for testing purposes, get the names from an array of const strings or from a file
update the array of plants by applying water and sun once each
print the results in a table format with headings
sort with submenu to sort in descending order by any field name number of branches, number of roots
add a submenu with all sorting options and an option to go back to the main menu without sorting; use enum to implement the submenu
use Bubble Sort; it is not the most effective but the easiest to modify
do not copy and paste sort code three times into the same function or switch; ask yourself what the differences isare in the sort code if you sort by name or number of branches?
write an outerwrapper menu sort function which you will call when a user select Sort menu option
ask a user for the sort key field you want to sort by
call the inner function that does the sorting; to make the inner sort function reusable, the inner sort function should only sort based on a user choice and nothing else
and then call the print function this way you'll have reusable sort and print functions
do not write or use swap function to swap creatures in the array sort does enormous amounts of swaps and executing a function is a computational expense. It takes statements to swap creatures, do it in the sort function directly
print results in a table format a table format with headings; print the results of the sort outside of the sort function to make the sort function more flexible; sometimes you need to sort without printing the results
exit
use enum to implement menu and submenu switches
no dynamic memory allocation
no vectors
use const where appropriate
main should be wellmodularized
use enum if you know how and switch to implement the menu
print plants in a table format with headings, right align numeral values; use toString member function to print individual creature
Tips
toString
to format the string use stringstream #include
sample.... is here for demonstration purposes only
stringstream ss;
ss library
Submenu
a submenu must have an option to go back to the previous menu or main menu. If a user got into a submenu by mistake, a user should be able to go back without executing other menu choices; for example, if a user entered Sort submenu, a user should be able to go back to the previous menu or main without being forced to sort
submenu should be implemented as a switch with enum; let it fall through
The general structure for Search and Sort menu options
case SORT: SortMenuOption whatever you need to pass; break menu option in main
SortMenuOption whatever you need to pass outerwrapper function
get criteria
cal the Sort inner function, which does an actual sorting
SortCreatures whatever you need to pass; inner function
print results
enum example
enum SortMenu ID STRENGTH, HEALTH, BACKTOMAIN
SortMenu is a data type, not a variable; STRENGTH here is to the previous and so on
enum SortMenu ID STRENGTH HEALTH BACKTOMAIN setting values for STRENGTH, HEALTH, and BACKTOMAIN is not a great idea because if you add another menu option, it will be before BACKTOMAIN and you will have to renumber
court
Sort by:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started