C++ Programming: From Problem Analysis to Program Design
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 10, Problem 7SA

Assume the definition of class foodType as given in Exercise 6.

Answer the following questions? (1, 2, 3, 5, 6)

  1. Write the definition of the member function set so that private members are set according to the parameters. The values of the int and double instance variables must be nonnegative.

  2. Write the definition of the member function print that prints the values of the data members.

  3. Write the definitions of the member functions getName, getcalories, getFat, getSugar, getCarbohydrate, getPotassium to return the values of the instance variable.

  4. Write the definition of the default constructor of the class foodType so that the private member variables are initialized to 0, 0. 0, 0, 0. 0, 0. 0, respectively.

  5. Write the definition of the constructor with parameters of the class foodType so that the private member variables are initialized according to the parameters. The values of the int and double instance variables must be nonnegative.

  6. Write a C + + statement that prints the value of the object fruit 2.

  7. Write a C++ statement that declares an object my Fruit of type foodType, and initializes the member variables of myFruit to “Apple”, 52, 0. 2, 10,13.8, and 148.0, respectively.

Blurred answer
Students have asked these similar questions
"Do not use AI tools. Solve the problem by hand on paper only and upload a photo of your handwritten solution."
| √ (r² + r + 1)e^ dr
Ensure you answer the question asked at the end of the document. Do not just paste things without the GNS3 console outputs
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY