Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

    1. 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. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Modeling And Design

Authors: Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish

5th Edition

0123820200, 978-0123820204

More Books

Students also viewed these Databases questions

Question

In Problems 6980, find the sum of each sequence. 20 k=5 3

Answered: 1 week ago

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago