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
Suppose that a class employeeType is derived from the class personType. Give examples of members—data and functions— that can be added to the class employeeType. Also write the definition of the class employeeType that you derived from the class personType, and the definitions of the member functions of this class.
Example 10-10 defined a class personType to store the name of a person. The member functions that we included merely print the name and set the name of a person. Redefine the class personType so that, in addition to what the existing class does, you can: Set the first name only. Set the last name only. Store and set the middle name. Check whether a given first name is the same as the first name of this person. Check whether a given last name is the same as the last name of this person.
Object Oriented Programing Consider the following details of all classes in diagram A person can be an employee or a student. An employee may have rights of admin officer or of academic officer. These class hierarchies represent multi-level inheritance. However, a Dean or Head of Department(HOD) may have rights to modify the status already defined by an administrator academic officer. Implement all these classes with appropriate data members and proper suitable functions and within the main function, create instances of all classes and test the described working of all these classes.
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
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