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 Problem Analysis to Program Design
- Assume the definition of class houseType as given in Exercise 11. Answer the following questions. (1, 2, 3, 5, 7) a. Write the definition of the member function set so that private members are set according to the parameters. b. Write the definition of the member function print that prints the values of the data members. c. Write the definition of the constructor of the class houseType so that the private member variables are initialized to according to the parameters. d. Write a C++ statement that prints the value of the object newHouse. e. Write a C + + statement that declares an object house of type newHouse, and initializes the member variables of house to "Ranch", 3, 2, 2, 2005, 1300, 185000, and 3600.0, respectively. f. Which function members are accessors and which are mutators?arrow_forwardConsider the definition of the class product Type as given in Exercise 8. Answer the following questions. (1, 2, 3, 5, 7) a. Write the definition of the function set so that instance variables are set according to the paramaters. Instance variables quantitieslnStock, price, and discount must be nonnegative. b. Write the definition of the function print to output the values of the instance variables. c Write the definition of the function setQuantitiesInStock to set the value of the instance variable quantitiesInStock according to the parameter. d. Write the definition of the function updateQuantitiesInStock to update the value of instance variable quantitiesInStock by adding the value of the parameter. e. Write the definition of the function getQuantitiesInStock to return the value of instance variable quantitiesInStock. f. Write the definition of the function setPrice to set the value of the instance variable price according to the parameter. g. Write the definition of the function getPrice to return the value of the instance variable price. h. Write the definition of the function setDiscount to set the value of the instance variable discount according to the parameter. i. Write the definition of the function getDiscount to return the value of the instance variable discount.arrow_forwardDifferentiate between static and instance class members. Explain with proper example when you should make members static?arrow_forward
- Q1) Write the Code the following scenario. Write an abstract function named receivePay in interface with return type double and no parameters. Write another incomplete function, name Show with return type void and an argument of type int in that interface. Build a class with name Bill that implements the above interface. Bill class with name BillId , itemsquantity and itemsprice with proper datatypes with private access . Define two constructors,one default and other is parameterized to initialize the class members . Now receivePay has to beimplemented in such a way that its displays product of itemsquantity and itemsprice and Display function will display the BillId.Can we do same task with abstract class instead of interface? NOTE:SUBJECT:CSHARP (VISUAL PROGRAMMING)arrow_forwardWrite a definition of a class named Point that might be used to store and manipulate the location of a point in the plane. You will need to declare and implement the following member functions:a. A member function set that sets the private data after an object of this class is created.b. A member function to move the point by an amount along the vertical and horizontal directions specified by the first and second arguments.c. A member function to rotate the point by 90 degrees clockwise around the origin.d. Two const inspector functions to retrieve the current coordinates of the point.Document these functions with appropriate comments. Embed your class in a test program that requests data for several points from the user, creates the points, then exercises the member functions.arrow_forward4、Programming practice (homework 10)Define two class types: Student and Graduate, where Graduate inherits from Student. Class Student includes (1) member variables: name, id, and score (protected)(2) member functions: (public) a default constructor Student::Student(): name(“no name”), id(0), score(0) constructor Student::Student(string n, int i, double s): name(n), id(i), score(s). void output()Class Graduate has(1) additional member variables: string supervisor; (private)(2) additional member functions: (public) a default constructor Graduate::Graduate(): Student(),supervisor(“no name”) constructor Graduate:: Graduate (string n, int i, double s, string sn): Student(n,I,s), supervior(sn). void output() ---redefine the functionDefine three graduate student g1, g2,g3 in main functionarrow_forward
- Write a program IN C++ to model a student class with roll number and name as the sensitive information. Initialize default values for the sensitive information using a default constructor, use a copy constructor to copy from another object, use a member function to take user input and update the name and roll number and display the same using another member function. b.Add constructor overloading to the above code and enable initialization of name, roll number via constructor arguments. NAME ROHI ROLLNO 18arrow_forwardModel a room class, whose member data is three integers length, width and height. The classcontains two constructors to initialize the room class objects, first is no argumentconstructor, while the second in three arguments constructor. Class also contains threemember functions i.e., getdatat) to get the data from user and store in the memory of callingobject and showdata) to show the room data of calling object, int volume(int I, int w, int h)function should receive the length, width and height values from the objects one by one andreturn the volumes of the three objects respectively.Write a main program to declare the three object rl, 12, and 13 of room class. Two objectwill store the values through three argument constructor and third object will get the datafrom user by calling getdata function. Then all three objects should call the volumefunctions to calculate their volumes and store them in three variables of type integer. Finallythe system compare the three volumes values…arrow_forwardIn Chapter 10, the class clockType was designed to implement the time of day in a program. Certain applications, in addition to hours, minutes, and seconds, might require you to store the time zone. Derive the class extclockType from the class clockType by adding a member variable to store the time zone. Add the necessary member functions and constructors to make the class functional. Also, write the definitions of the member functions and the constructors. Finally, write a test program to test your class.arrow_forward
- Consider the definition of the class product Type as given in Exercise 8. Which function members are accessors and which are mutators? (4)arrow_forwardWhat is the difference between a friend function of a class and a member function of a class? (3)arrow_forwardConsider the definition of the following class: (1, 2, 3, 5, 7) a. Give the line number containing the constructor that is executed in each of the following declarations. b. Write the definition of the constructor in Line 4 so that the instance variables are initialized to " ", " ", " ", 0, 0.0, and 0.0, respectively. c Write the definition of the constructor in Line 5 so that the string instance variables are initialized to"", and the other instance variables are initialized according to the parameters. Instance variables quantitieslnStock, price, and discount must be nonnegative. d. Write the definition of the constructor in Line 6 so that the instance variables productName and manufacturer are initialized to the empty string, instance variable id is initialized according to the first parameter, and the remaining instance variables are initialized according to the last three parameters. Instance variables quantitieslnStock, price, and discount must be nonnegative. e. Write the definition of the constructor in Line 7 so that the instance variables are initialized according to the parameters. Instance variables quantitieslnStock, price, and discount must be nonnegative.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr