Question
Asap Code relate to eachother 3 different code - A Define a FoodItem class with the following data members : Name: string Type: V for
Asap Code relate to eachother 3 different code
- A
-
- Define a FoodItem class with the following data members :
- Name: string
- Type: V for vegetable, P for protein, D for dairy, W for water
- Calories: an integer for the number of calories from that food item
And the following function members:
- A default constructor which initializes a food item with the following ("water", W, 0)
- A parametrerized constructor that initializes a food item with provided arguments.
- Define member methods to get and set each data member.
- Define a function member Compare(FoodItem F) that compares the calorie content of two food items and returns 1 if the the calories in F are less than the calories of the instance.
2. Write the code corresponding to the implementation of each of the function members.
3. Test (on paper only !!) the class above by writing a function main() which defines two food items F1 ("apple", V, 95)
F2 ("egg",P,78) and compares the calorie content of F1 and F2.
-A.b
-
1. Using the class FoodItem defined above define a HealthyFoodItem class derived from FoodItem with the following extra data member: FatContent: a double
-Define HealthyFoodItem default constructor.
-Define HealthyFoodItem parameterized constructor.
-Define all relevant member methods (setters and getters)
2.
- Write the code corresponding to HealthyFoodItem default constructor using FoodItem default constructor and initializing the FatContent to 0.
- Write the code corresponding to HealthyFoodItem parameterized constructor re-using the parameterized constructor defined in FoodItem and initializing FatContent with provided argument.
-Write the code corresponding to all setters and getters reusing function members already defined in FoodItem.
-A.c
Test the class HealthyFoodItem by writing a function main() which will define an array Meal of 10 HelathyFoodItem objects, and prompts the user to enter the relevant data for each HealthyFoodItem object and store it in the array Meal.
Your program should take the number of calories for each food item using getCalories() getter function member and compute the total meal calories.
Your program should take the fat content for each food item using getFatContent() getter function member and compute the total meal fat content.
Finally, your program should display these two numbers.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started