Concept explainers
Assume there is a class named Animal, which 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, and 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 11 Solutions
STARTING OUT WITH C++ MPL
Additional Engineering Textbook Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
C++ How to Program (10th Edition)
Starting out with Visual C# (4th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Web Development and Design Foundations with HTML5 (8th Edition)
- When you derive a class from an existing class, you Group of answer choices can add both new data and new functions. can add new data, but cannot add new functions. can add new functions, but cannot add new data. must add both new data and new functions.arrow_forwardAssume that dog and cat are instances of the Pet class, which has overloaded the = operator. Rewrite the following statement so it appears in function call notation instead of operator notation: dog = cat;arrow_forwardWhen writing the definition of the function to overload the assignment operator for a class, why do you use the pointer this?arrow_forward
- Create 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_forwardSuppose in Islamabad International Airport the plans arrivals and departures are frequent and they are moving with a kinetic energy. Your task is to write a class to find the kinetic energy of an airplane coming from UK having the mass and the velocity known to pilots only. You are a pilot so your captain of the plane has given you the task to write a class to perform the calculation, the function must be defined outside the class. Your task is to provide the mass and velocity as arguments to the function and then display the kinetic energy without returning a value.arrow_forwarda. Instance of a class is called, functions have same name but different sets of parameters.arrow_forward
- Novice: How can i access a main class objects from outside the function? / Better Alternative? If i have 4 Student objects how can i print the information for the specific object given one parameter about the class, like the students Idnumber. What i came up with was making a checkId void function that takes the user input and runs an if else chain checking if the Id belongs to student 1-4 then printing the details of that classes object with the void function print. ideally i would want the if-else chain in the checkId function to call the print( student1-4) class object but im not sure how to properly do that. i dont think this is the best way to go about it, if you have any recommendations or alternatives please help me out.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_forwardDesign an Account class used to represent an individual’s declining balance gift card. It contains a string for the account number, and a float value for the balance. It should include the following 7 functions: a 2-argument constructor (it accepts an account number and initial balance). a set function, one for each attribute (2 total functions, setAccount and setBalance. Each assigns an argument value to the named member variable. a get function for each attribute (2 total functions, getAccount, and getBalance). Each returns the value stored in the named member variable. a function to display the account’s information to the screen. The account number and balance value should be labelled. a function withdraw that takes a float argument and subtracts it from the balance. Write the class declaration. Member variables should NOT be accessible outside the class! Member functions should be accessible outside the class! Write the member function definitions for only the following…arrow_forward
- Subject name is C++ Writea program that demonstrate the use of constructor with default arguments for the following problem. Define a class person with data member as name and age. Create three objects with no argument, one argument name and two argument name and age. You are not allowed to create more than one constructor.arrow_forwardC++ please help me answer this question I will give you a good rating Thank you! Choose the correct answer to the question. Which of these is not a property of a class? Member variables and member functions may be public, protected, or private. A class may not use another class as the type for a member variable. The name of a member function for a class may be overloaded just like the name of an ordinary function. A function may have formal parameters whose types are classes. A function may return an object of a class. Choose the correct answer to the question.The copy constructor is executed... When one object is assigned to another object at its creation When objects are passed to a function using call by value When the function returns an object reference.b, c only a, b onlyAll of the abovearrow_forwardcomputer programming (C++ language)arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning