The apple-management system A local apple farmer has asked you to write a progra
ID: 3693846 • Letter: T
Question
The apple-management system
A local apple farmer has asked you to write a program to help him manage his apple inventory. The farmer needs to keep track of how many apples he sells everyday, how many apples he picks, and how many apples he has in storage. Your apple inventory system needs to track data for 30 days. The inventory and harvest data should be stored as private C++ arrays as part of a class. You also need to include private variables for the inventory, current day, and maximum number of entries in your array, and then access all private variables through public methods. The AppleFarmer.h file includes the following class definition: Class AppleFarmer{ public: AppleFarmer(int); void sellApples(int Demand); void harvestApples(int dayHarvest); bool endOfMonth(); void updateCurrentDay(); int getInventory(); double calculateAverageSales(); double calculateAverageHarvest(); void printSales(); void printHarvest(); private: int sales[30]; int harvest[30]; int maxDays = 30; int currentDay = 0; int inventory = 0; } Functionality for each method: AppleFarmer(int initVal) /* initialize all elements in the sales[] and harvest[] to initVal */ void sellApples(int demand) /* if demand <= inventory update sales[] to set sales[currentDay] = demand the demand should be subtracted from the inventory if the demand > inventory set sales[currentDay] = 0 (and leave inventory unchanged) */ void harvestApples(int dayHarvest) /* update harvest[] to set harvest[currentDay] = dayHarvest the dayHarvest should be added to the inventory */ bool endOfMonth() /* check if currentDay = maxDays, indicating that the sales[] and harvest[] arrays are full if currentDay = maxDays, return true. Otherwise return false */ void updateCurrentDay() /* add 1 to currentDay */ double calculateAverageHarvest() /* return the average daily harvest calculation for the harvest[] array */ double calculateAverageSales() /* return the average daily apple sales for the sales[] array */ int getInventory() /* return inventory */ void printHarvest() /* print the contents of the entire harvest[] array using cout statement: cout<<”Day: “<>harvest; Call harvestApples to update the harvest and inventory variables. Ask the user for the sales amount, or read it in from an array. cout<<”Enter a sales amount: “<>sales; Call sellApples to update the sales and inventory variables Print the current inventory: cout<<”Apple inventory: “Class 2. Enter the name of the class and the arguments for the constructor. For this assignment, the name should be AppleFarmer. In the Arguments textbox, enter int initVal as the one argument for the constructor. Unselect Virtual Destructor. 3. Click Create. Your project should now have directories for Sources and Headers. The sources directory contains the .cpp file for your class and the Headers directory contains the .h file for your class. 4. Save the project: File->Save project 5. Copy and paste the code in the AppleFarmer.h file on the Moodle to overwrite the AppleFarmer.h file you just created (or delete the AppleFarmer.h file you just created and add the one from the Moodle to the include directory in your project). 6. Implement the methods defined in the AppleFarmer.h in the AppleFarmer.cpp file.
Explanation / Answer
AppleFarmer.h file includes the following class definition:
Class AppleFarmer
{
public:
AppleFarmer(int);
void sellApples(int Demand);
void harvestApples(int dayHarvest);
bool endOfMonth();
void updateCurrentDay();
int getInventory();
double calculateAverageSales();
double calculateAverageHarvest();
void printSales();
void printHarvest();
private:
int sales[30];
int harvest[30];
int maxDays = 30;
int currentDay = 0;
int inventory = 0;
}
public int main()
{
AppleFarmer af(0);
double harvestavg;
harvestavg= calculateAverageHarvest();
}
AppleFarmer :: AppleFarmer(int initVal)
{
AppleFarmer af;
for(int i=0;i<af.maxDays;i++)
{
af.sales[i]=initVal;
af.harvest[i]=initVal;
}
}
void sellApples(int demand)
{
AppleFarmer af;
If(demand<=af.inventory)
{
sales[af.currentDay]=demand;
af.inventory=af.inventory-demand;
}
else if(demand>inventory)
sales[currentDay]=0;
}
void harvestApples(int dayHarvest)
{
AppleFarmer af;
af.harvest[currentDay] = dayHarvest;
af.inventory+=dayHarvest;
}
bool endOfMonth()
{
AppleFarmer af;
if(af.currentDay=af.maxDays)
return true;
else return false;
}
void updateCurrentDay()
{
currentDay++;
}
double calculateAverageHarvest()
{
AppleFarmer af;
private double harvestavg=0;
for(int i=0;i<af.currentDay;i++)
harvestavg+=af.harvest[i];
harvestavg=harvest/af.currentDay;
return harvestavg;
}
double calculateAverageSales()
{
private double sales=0;
for(int i=0;i<currentDay;i++)
sales+=sales[i];
sales= sales/currentDay;
return sales;
}
int getInventory()
{
AppleFarmer af;
return af.inventory;
}
void printHarvest()
{
for(int i=0;i<af.currentDay;i++)
{
cout<<”Day: “+ calculateAverageHarvest();
}
}
void printSales()
{
cout<< “Day:”+ calculateAverageSales();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.