EBK C++ PROGRAMMING: FROM PROBLEM ANALY
EBK C++ PROGRAMMING: FROM PROBLEM ANALY
8th Edition
ISBN: 8220103648530
Author: Malik
Publisher: Cengage Learning US
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
PS: see image for question.
People in School Objective: At the end of the activity, the students should be able to: Create a program that exhibits inheritance. Procedure: Write a simple information system that will store and display the complete information of a student, faculty, or employee. Create four (4) no-modifier classes named Person, Student, Faculty, and Employee. Create a public class named CollegeList. This class shall contain the main method. Refer to the UML Class Diagram for the names of the variables and methods. The (-) symbol represents private variables, while (+) represents public method. This should be the sequence of the program upon execution: Prompt the user to select among Employee, Faculty, or Student, by pressing E, F, or S. Ask the user to type the name and contact For Employee, ask the user to type the employee's monthly salary and the department where he/she belongs to (Ex. Registrar). Then, display name, contact number, salary, and For Faculty, ask the user to press Y if…
Object passing checklist1. Go over each member function and add the const keyword after their declaration ifthey do not modify any of the class' member variables.2. When accepting objects as parameters, prefer to pass them by reference. Add reference declarator (& before the identifier name of an object parameter.3. If the member function does not modify the parameter, make the parameter constantby using the const keyword. apply the Object Passing Checklist. Modify food.h and volunteer.h to useobject references. Add const and & keywords in the appropriate places of the code.
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
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
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