Concept explainers
Assume there is a class named Animal that overloads the = and + operators. In the following statement, assume cat, tiger, and wildcat are all instances of the Animal class:
wildcat = cat + tiger;
Of the three objects, wildcat, cat, or tiger, which is calling the operator + function? Which object is passed as an argument into the function?
Want to see the full answer?
Check out a sample textbook solutionChapter 14 Solutions
Starting Out With C++ From Control Structures To Objects Plus Mylab Programming With Pearson Etext -- Access Card Package (8th Edition)
Additional Engineering Textbook Solutions
Artificial Intelligence: A Modern Approach
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Software Engineering (10th Edition)
Starting Out With Visual Basic (7th Edition)
Starting Out with Java: Early Objects (6th Edition)
Starting Out with Java: From Control Structures through Objects (6th Edition)
- In 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_forwardWhat is the difference between a friend function of a class and a member function of a class? (3)arrow_forwardAssume 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_forward
- (Program) a. Complete the following class by including functions corresponding to the two prototypes listed in the declaration section: classElevatorprivate:intelNum;//elevatornumberintcurrentFloor;//currentfloorinthighestFloor;//highestfloorpublic:Elevator( int=1,int=1,int=15);//constructorvoidrequest( int);; In this definition, the data member elNum is used to store the elevator’s number, the data member currentFloor is used to store the elevator’s current floor position, and the data member highestFloor is used to store the highest floor the elevator can reach.The constructor should allow initialization of an object’s three data members with the data passed to the constructor when an Elevator object is instantiated. The request function should code the following algorithm: If a request is made for a nonexistent floor, a floor higher than the topmost floor, or the current floor Do nothing ElseIf the request is for a floor above the current floor Display the current floor number While not at the designated floor Increment the floor number Display the new floor number EndWhile Display the ending floor number Else // the request must be for a floor below the current floor Display the current floor number While not at the designated floor Decrement the floor number Display the new floor number EndWhile Display the ending floor number EndIf b. Include the class written for Exercise 3a in a complete program, and verify that all member functions work correctly.arrow_forwardUsing classes and arrays, the team will develop a set of functions for an online shopping system. The system is represented by the following structure:1- Class Item having the following private attributes: (ID, name, quantity, price) and the following public methods:- Constructors (default, parameterized, and copy)- Setters & Getters- Operator overloading for the ==, +=,-=, >> and << operators Note that the ID member variable is not entered or read from the user. It is automatically set by the class as a serial ID starting with the first item of ID 1 and incrementing with every new object.2- Class Seller having the following private attributes: (name, email, items,maxItems), where items is a dynamic array of objects of type Item with the size maxItems. The class has the following public methods:- Constructor (parameterized)- Operator overloading for the >> and << operators- Add An Item.- This will take an Item object as a parameter:- If the item already…arrow_forwardcreate two classes named mammals and marine animals. create another class named blue whale which inherits both the above classes.now, create a function in each of these classes which prints "I am mammal", "I am marine animal" and "I belong to both the categories: mammals as well as marine animals "respectively. now, create an object for each of the above class and try calling function of a mammal by the object of mammal function of blue whale by the object of blue whale function of each of its parent by the object of blue whale function of marine animal by the object of marine animalarrow_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