Write a class that represents the farm object from labs 10 and 11. Also write a class for a robot that manages the tending of a farm.
TheFarmclass should have four private fields:
int rows
int columns
int age
char **plot//will represent the farm crops and have dimension rows X columns
TheFarmclass should also have eight public methods (functions) that match each of the functions from lab 10:bool plant(char, int, int)– plants a crop at a particular location, but only if there is no plant in that location. Returns
true if a plant was planted and false if not.(note that this is an adjustment to this function)
char harvest(int, int)– picks a plant at a particular location. The character of the plant is returned and at that location
on the farm a ‘0’ is placed. If there is no plant at that location a ‘0’ is returned. A spoiled crop (‘X’) counts as a plant.void wait()– this method lets time pass. Every crop in the array that is lowercase becomes uppercase. Every crop in
the array that is uppercase becomes an ‘X’.The private field age should be incremented.
string report()– the farm generates a string that represents itself. Each plant should be represented by its character
separated by a comma and each new row should be separated by a newline character (‘\n’)int getAge()- return the value of the age of the farm (int age)
int getRows()- returns the number of rows
int getColumns()- returns the number of columns
char at(int, int) const– returns the value of the farm at a particular location in the plot without altering what is there.
Notice that each function has almost the same signature as those from lab 10, with the notable difference being that the array of characters representing the farm no longer needs to be passed in as a parameter because it is now a private member variable with each instance of the class possessing its own copy.
Because Farm is a class, it will need a constructor. In fact, we will give it two constructors. The default constructor will create a Farm object that is 10 X 10. The second constructor will create a Farm object of any size, determined by the number of rows and columns passed to it as parameters. Both constructors should initialize the age of the farm to 0 and create a 2-dimensional array of the appropriate size.
Because the Farm dynamically allocates a two-dimensional array of variable size using a double pointer, you will also need to write a destructor that deallocates the memory used for that member variable.
Page 1 of 4
CSC111 Fall 2021
TheRobotclass should have the following private static fields:
static int riceCount; static int beanCount; static int potatoCount; static int wasteCount; static int robotCount;
The variables are shared by all objects of the class (because of thestatickeyword).
TheRobotclass should have the following private member fields:vector produce;
int seedVault;
Each instance (object) of the robot class will have its own copy of the private member variables.
The Robot class should also have the following public methods:
Professor Conroy
void plant(Farm &f, char c)– plants a crop at all spaces in the farm where there is an empty plot using the character passed in as parameter as the plant of choice. So if the farm is something similar to:
0, 0, X, X, p, R, b, 0, 0, 0, 0, 0
And you callmy_bot.plant(my_farm, ‘r’);The new plot should look like this:
r, r, X, X, p, R, b, r, r, r, r, r,
You should use the farm’s plant() function to plant a single plant (from Lab 10) inside this new plant function to save yourself some work. Each time the robot successfully plants a plant, you should increment the static variable (riceCount, beanCount, or potatoCount) that matches what you have successfully planted. You should also decrement the private member variable seedVault. You should only call the farm’s plant function and the related incrementing and decrementing if the robot’s seedVault attribute is > 0.Note that this function now returns void whereas it previously returned an int in lab 11.
Page 2 of 4
CSC111 Fall 2021 Professor Conroy
void harvest(Farm &f)– picks all plants that are ready to be eaten (those that are capital but not 0 or X). The character of the plants should be added to the robot’s private member variablevector produce.Note that this is an adjustment from lab 11.At any location on the farm where a plant is harvested a ‘0’ is placed. If there is no plant ready to be harvested at a location nothing needs to be done for that cell. You can use your original harvest function to harvest each individual plant inside this harvest function to save yourself some work. For example, the farm:
0, 0, X, X,
p, R, b, B,
0, 0, P, 0
void clean(Farm &f)– removes all X’s from the farm and replaces the X’s with a zero.The function should increment the static wasteCount variable each time a plant is successfully removed. So for instance, the farm:
0, 0, X, X, p, R, b, 0, 0, 0, 0, 0
Should become -->
0, 0, 0, 0, p, R, b, 0, 0, 0, 0, 0
should become -->
0, 0, X, X, p, 0, b, 0, 0, 0, 0, 0
and increment wasteCount twice for having removed two dead plants. You can use your harvest function from the previous lab to make the code simpler to write.
static int getRiceCount()- returns the riceCount
static int getBeanCount()- returns the beanCount
static int getPotatoCount()- returns the potatoCount
static int getWasteCount()- returns the wasteCount
static int getRobotCount()- returns the robotCount
int getSeedVaultCount() const– returns seedVault
int getProduceCount() const– returns how many plants have been harvested by a particular robot. This is not a sum of the static rice/bean/potato count but rather the size of the produce member variable for a particular robot.
void addSeeds(int)– adds the parameter passed in to the seedVault member variable
Page 3 of 4
CSC111 Fall 2021 Professor ConroyYour Robot class should have two private methods:
void bubble_sort()- takes any collection of plants and sorts them into alphabetical order using the bubble sort algorithm. Please consult your textbook for guidance on writing this.
void insertion_sort() - takes any collection of plants and sorts them into alphabetical order using the insertion sort algorithm. Please consult your textbook for guidance on writing this.
Your Robot class should have a constructor. Inside the constructor, the private static robotCount variable should be incremented.