Question: 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.
Specifications/Requirements
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 (to_String()), for example, " Rose 35"
function to grow a plant by applying water and sun; levels of watering and sun are randomly generated
water 0-3
0- nothing happens
1- grows 1 branch
2- grows 2 branches
3- grow 2 branches and 1 root
sun 0-2
0- nothing happens
1- grows 1 root
2- grows 2 roots
main()
an array of 10 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 difference(s) is/are in the sort code if you sort by name or number of branches?
write an outer/wrapper 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 3-4 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 well-modularized
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 to_String() member function to print individual creature
Tips
to_String()
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*/)// outer/wrapper 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=1, STRENGTH, HEALTH, BACK_TO_MAIN}
// SortMenu is a data type, not a variable; STRENGTH here is 2(+1 to the previous), and so on
/*enum SortMenu { ID=1, STRENGTH=2, HEALTH=3, BACK_TO_MAIN=4}, setting values for STRENGTH, HEALTH, and BACK_TO_MAIN is not a great idea because if you add another menu option, it will be before BACK_TO_MAIN and you will have to renumber*/
court<<"
Sort by:
"<<
"["<

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!