Concept explainers
Assume the definition of class foodType as given in Exercise 6.
Answer the following questions? (1, 2, 3, 5, 6)
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.
Write the definition of the member function print that prints the values of the data members.
Write the definitions of the member functions getName, getcalories, getFat, getSugar, getCarbohydrate, getPotassium to return the values of the instance variable.
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.
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.
Write a C + + statement that prints the value of the object fruit 2.
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.
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
C++ PROGRAMMING:FROM...(LL) >CUSTOM<
- 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 areference 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.arrow_forwardRewrite the calculator program using a class called calculator. Your program will keep asking the user if they want to perform more calculations or quit and will have a function displayMenu to display the different functions e.g .(1 - addition, 2- subtraction, 3- multiplication, 4- division) Your program must have appropriate constructors and member functions to initialize, access, and manipulate the data members as well as : A member function to perform the addition and return the result A member function to perform the subtraction and return the result A member function to perform the multiplication and return the result A member function to perform the division and return the resultarrow_forwardI'm confused about this question. Any help is appreciated!arrow_forward
- Nutritional information (classes/constructors) PYTHON ONLY Complete the FoodItem class by adding a constructor to initialize a food item. The constructor should initialize the name (a string) to "None" and all other instance attributes to 0.0 by default. If the constructor is called with a food name, grams of fat, grams of carbohydrates, and grams of protein, the constructor should assign each instance attribute with the appropriate parameter value. The given program accepts as input a food item name, fat, carbs, and protein and the number of servings. The program creates a food item using the constructor parameters' default values and a food item using the input values. The program outputs the nutritional information and calories per serving for both food items. Ex: If the input is: M&M's10.034.02.01.0 where M&M's is the food name, 10.0 is the grams of fat, 34.0 is the grams of carbohydrates, 2.0 is the grams of protein, and 1.0 is the number of servings, the output is:…arrow_forwardCreate an Employee class that includes three private data members— firstName (type string), lastName (type string), and monthlySalary (type int ).It also includes several public member functions.1. A constructor initializes the three data members. 2. A setFirstName function accepts a string parameter and does not return any data. It sets the firstName.3. A getFirstName function does not accept any parameter and returns a string. It returns the firstName.4. A setLastName function accepts a string parameter and does not return any data. It sets the lastName.5. A getLastName function does not accept any parameter and returns a string. It returns the lastName.6. A setMonthlySalary function accepts an integer parameter and does not return any data. It sets the monthlySalary. If the monthly salary is less than or equal zero, set it to 1000 and it displays the employee’s first name, last name and the inputted salary with a statement “**==The salary is set to $1000.”7. A getMonthlySalary…arrow_forwardWrite a class ‘Box’ which has three members height, width and depth; To set values and use these members, write mutator and accessor functions for these members. (Hint: there would be 3 Accessor and 3 Mutator functions).arrow_forward
- QUESTION 3 A constructor is like a function. It can return any type value needed. True Falsearrow_forwardTrue or False: In order to derive class A from class B, class A must contain a public member function that may be called by the rest of the class. (It is not a half-finished project.) A) This is correct. B) The answer is False.arrow_forwardTrue or false? Only instance member functions can be defined as constant functions.arrow_forward
- Task-1: Both computer and software engineering programs blend the broad engineering discipline courses with the computer science specific courses. Hence, it is a good idea to represent the "course" as an object before attempting to write a program to help students get register to the courses. The programmer can think of the abstraction of a course object as the representation of title, code, and credit values only. Write a class declaration for the course object that includes a constructor, a set and a get member function for each data member, and a member function that returns the course information upon request. For instance, for this course it should prepare a string like “COMP218 - Object-Oriented Programming". a) Use C++-strings for the representation of string of characters. b) Use C-strings for the representation of string of characters.arrow_forwardProblem (Online Address Book): Using classes, design an online address book to keep track of the names, addresses, phone numbers, and dates of birth of family members, close friends, and certain business associates. Define a class addressType that can store a street address, city, state, and ZIP code. Use the appropriate functions to print and store the address. Also, use constructors to automatically initialize the member variables. Define a class extPersonType using the class personType with following members and methods: firstname, lastname, and accessors and mutators, print to display, and constructors. Define a class dateType for month, day and year as members with its accessors, mutators, and constructors) Design a class addressType. Add a member variable to this class to classify the person as a family member, friend, or business associate. Also, add a member variable to store the phone number. Add (or override) the functions to print and store the appropriate information.…arrow_forwardC++ Friend function concepts Do not use operator overloading Create a class User with private member variables "id". In the class define a function increment_user_id() which will increment the id and return it as well. Create another method "void show_Id()" to show the id for a particular object. Create a constructor of User class where increment the Id by calling the increment_user_id() method for every new object . Finally create two objects of the class and print their corresponding id's on console.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr