Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(a) Write a C++ class for a fruit basket. The following are the properties: Frui

ID: 3805564 • Letter: #

Question

(a) Write a C++ class for a fruit basket. The following are the properties: Fruit Basket apples = an integer equal to the number of apples in the basket oranges = an integer equal to the number of oranges in the basket peaches = an integer equal to the number of peaches in the basket getApples rightarrow returns an integer equal to the number of apples getOranges rightarrow returns a integer equal to the number of oranges getPeaches rightarrow returns an integer equal to the number of oranges getTotal rightarrow returns the total number of apples and oranges (b) Write a main C++ function that will: 1. Instantiate and object called myBasket of the class FruitBasket 2. Assign a value of 5 to the apples field of myBasket 3. Assign a value of 7 to the oranges field of myBasket 4. Assign a value of 10 to the peaches field of myBasket 5. Use the method getTotal to display the total number of fruit items in the basket 6. Use the "using" statement to define the namespace.

Explanation / Answer

// C++ code
#include <iostream>
using namespace std;

class FruitBasket
{
private:
   int apples;
   int oranges;
   int peaches;
public:
   FruitBasket(int a, int o, int p)
   {
       apples = a;
       peaches = p;
       oranges = o;
   }

   int getApples(){return apples;}
   int getOranges(){return oranges;}
   int getPeaches(){return peaches;}
   int getTotal(){return getApples()+getOranges()+getPeaches();}
};

int main()
{
   FruitBasket myBasket(5,7,10);
   cout << "Total number of fruits in basket: " << myBasket.getTotal() << endl;
}

/*
output:

Total number of fruits in basket: 22

*/