Concept explainers
Assume the definition of class houseType as given in Exercise 11. Answer the following questions. (1, 2, 3, 5, 7)
Write the definition of the member function set so that private members are set according to the parameters.
Write the definition of the member function print that prints the values of the data members.
Write the definition of the constructor of the class houseType so that the private member variables are initialized to according to the parameters.
Write a C++ statement that prints the value of the object newHouse.
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.
Which function members are accessors and which are mutators?
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 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.arrow_forwardC++ : Defining class Person, class Student, class Teacher and class Graduate. Note that class Student and class Teacher inherits from Person, and class Graduate inherits from Student. Defining two constructors (including a default constructor) for each class. Defining virtual function print() for three classes (person, teacher and graduate), where each has different function body. Writing a main function to test the above definition and run each print function.arrow_forwardWrite a C++ program in which base class has one data member of integer type and it also contains two member functions as follows: Input ( ) functionis private and this function will receive one argument to initialize the data member. Factorial ( ) function is protected and finds the factorial of that number and it will return the result. The derive classhas one member function, which is used to call the base class factorial function and display the result.arrow_forward
- Write a C++ program in which you are required to define a class named Citizen. The class must include the following two data members. Name Nationality Your Program should define three constructors for the class Citizen a constructor with no parameter a copy constructor All of these constructors are meant to initialize their respective objects. In case of copy constructor, you are required to assign a separate space for the data members of the new object while copying the values of previously existed object. Declare two objects (1 for each type of constructor) in main. Write a function in class Citizen to display the initialized data members for each object. Also write destructor for the class Citizen. Display a message that says “destructor called” in the destructor body.arrow_forwardWrite a C++ program which will perform the following operations: • Define a class with name Point and has single data member Value (private member). • Define a constructor method (public) which will initialize the data member at the time of object creation. • Use the operator overloading concept and re-define the functionality of following arithmetic operators ( + , - , * , / ) for your class Point. • Create the two objects of class and use these four operators on them.arrow_forwardWrite a program in c++ that has a class containing constructors and in the class create 5 functions two functions should be get data and print data functions while rest of the 3 could be of programmers choice depending on the type of class is being created *c++ coding *create a class(any class of choice such as book car animal etc) *the class should contain constructors *In class create get data and print data functions for storing and printing data *Then create / include three (3) more functions of any type (other than get data and print data) *In total there will be 5 functions in class . get data . Print data . And three 3 more of programmers choice depending on whatever the class requires * keep the program simple and basic as possible for a beginner level student in c ++arrow_forward
- Mark the following statements as true or false. The member variables of a class must be of the same type. (1) The member functions of a class must be public. (2) A class can have more than one constructor. (5) A class can have more than one destructor. (5) Both constructors and destructors can have parameters. (5)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 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_forward
- Consider 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_forwardUsing C++ Using your own creativity, make a set of class templates that have these features: For this class template, put everything in one place--do not declare the member functions and have separate definition of the member functions elsewhere. Keep them in one place. Include a private variable. Include a constructor that loads the private variable when constructed. Include a destructor that clears the private variable to zero. Include set and get functions to set and get the private variable. For this class template, use declarations for variables and functions, like you do in header file (which you may use if you want). Then, separately put the full function definitions for each class member function on their own, like you do in a separate implementation file (which you may use if you want). Include at least 2 private variables. Include a constructor that loads the private variables when constructed. Include a destructor that clears the private variables to zero. Include the…arrow_forwardQUESTION PROVIDED BELOW KINDLY SEE. PROVIDE OUTPUT AS IT IS SHOWN IN QUESTION. AND FOLLOW TEMPLATES PROVIDED AT END OF QUESTION CHECK THIS BEFORE MAKING SOLUTION ( main.cpp , BikeService.cpp ) Write a C++ program to display the packages and the service cost.Strictly adhere to the Object-Oriented specifications given in the problem statement. All class names, member variable names, and function names should be the same as specified in the problem statement.Note: Use function overloading concept.Consider a class BikeService with the following private member variables. Datatype Variable string model string packageType Include the following methods in the class BikeService Method Description void bikeService(string packagetype) This method displays the available service based on the type of the package(either regular or additional).Note: If the package type is 1, display all the services corresponding to the regular package.If the package type is 2, display all the…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