Question: I need help with this c++ assignment: In this assignment you will simulate growing crops on a farm over a period of time. You will
I need help with this c++ assignment:
In this assignment you will simulate growing crops on a farm over a period of time. You will define a base class: Crop, that is inherited by several different Crop derived classes: Cauliflower, Kale, Parsnip, and Strawberry. The base class defines attributes that are common to all Crop classes: the time it takes for a crop to grow, the name of the crop, the base value for the crop, and whether or not the crop will continue to grow after it has been harvested. Each derived class has a special attribute that contributes to the final sale cost for that type of crop which is defined in the Crop values section below. The base Crop class will define a virtual function called harvest, takes in the current day in the simulation as a parameter and returns the value for the crop if it is ready to be harvested on that day. If the crop isnt ready to be harvested, it returns 0. Derived Crop classes Each derived class from the base class Crop has a special attribute that is unique to that type of crop. The special attribute is used as a multiplier on the base value for the crop when the crop is ready to be harvested. The Parsnip class is defined below as an example: class Parsnip : public Crop { public: Parsnip() : Crop("Parsnip", 2, 35, false) { srand(time(NULL)); int randomNum = rand() % 100; // create a random length multiplier between and and 2 (e.g., 1.75) lengthMultiplier = static_cast(randomNum) / 100 + 1; } int harvest(int numDays) { int value = Crop::harvest(numDays); return value * lengthMultiplier; } private: double lengthMultiplier; }; Sample input Your program will read in data from a text file. The file contains information about the crops your farm will be simulating. The user of the program will enter the filename from a prompt from your program. The first line of the file will contain the number of crops in the file. Each subsequent line that follows will contain a character that represents a crop that your farm will be growing. The character in the file maps to the first letter of each crop that your farm grows (e.g., c maps to Cauliflower). Here is an example: 8 c c k p k s s k Crop values Name: Cauliflower Grow time: 6 days Base value: 175 Regrows: Yes Special attribute: Size Name: Kale Grow time: 4 days Base value: 110 Regrows: No Special attribute: Crunchiness Name: Parsnip Grow time: 2 days Base value: 35 Regrows: No Special attribute: Length Name: Strawberry Grow time: 3 days Base value: 120 Regrows: Yes Special attribute: Juiciness Growing crops After reading in the text file into a dynamic array of type Crop* (notice that it is an array of base class pointersthis will allow you to use polymorphism later), your program will begin the simulation for the farming period. Your program will prompt the user to enter the number of days, n, they would like to simulate. After n days have been simulated, your program needs to calculate the yield of your farm. For each Crop class, the crop is ready to harvest when n equals the time it takes for that crop to grow. When a crop is harvested, it is also sold and your farm receives payment equal to the sale of that crop. If the crop is a type of crop that continues to grow after it has been harvested, it can be harvested multiple times if the simulation continues (i.e., Cauliflower takes 6 days to harvest so if our simulation runs for 24 days it can be harvested four times). Sample output Your output will need to contain detailed results of your farm simulation. For each day, you need to print out how many crops were harvested that day and how much they were sold for. If no crops were harvested, just print No crops were harvested today. After the day-by-day breakdown, your program must also print the total yield for your farm over that period of time. Here is output for a 6-day simulation using the input file from above: Day 1: No crops harvested today. Day 2: 1 crop(s) harvested for 35g. Day 3: 2 crop(s) harvested for 240g. Day 4: 2 crop(s) harvested for 220g. Day 5: No crops harvested today. Day 6: 4 crop(s) harvested for 600g. Total yield: 1095g NOTE: The actual values will change from run-to-run unless you seed your random number generate with the same number each time.
Thanks!!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
