Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
- Consider the following code segment for a class named vehicle:
class vehicle {
private:
string type;
string model;
string color;
int numWheels;
public:
…
};
- Write the PROTOTYPE for a function that overloads the + (plus) operator to add two vehicle objects. This prototype would add the numWheels of the objects. Write as a member
- Write the PROTOTYPE for a function that overloads the << (insertion) operator to print a vehicle object.
Expert Solution
arrow_forward
Step 1: Definitions
Operator overloading:
Operator overloading is giving new meaning or new definition to the existing operator but we cannot change the operator priority.
- It is a compile time polymorphism in which operator is overloaded.
- It simply means to do more than one task at a time on any operator.
- Operators that cannot be overloaded are,
- Scope resolution operator(::)
- sizeof()
- Ternary operator(?:)
Function prototype:·
- The function prototype is used to declare a function.
- It does not include the body of the function and informs the compiler about the function's name and return type.
- The prototype specifies the list of arguments passed, if any, along with their data types.
- The compiler makes use of prototype information to ensure the presence of corresponding function definition and correctness of argument data types.
- In a function prototype, the name of the arguments is optional.
- It is always terminated with a semicolon, unlike function definition which does not have a semicolon at the end.
arrow_forward
Step 2: Answer for 1.
The prototype for a function that overloads the “+” operator is as follows,
vehicle operator + (vehicle const &v);
Step by stepSolved in 3 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Assume a class named Yen exists. Write the header for a member function that overloads the < operator for that class.arrow_forward(2) Your member functions will be: Make sure that the mutators for height and width only take positive numbers! Test your class with the driver program given below. //--- Test driver for class Rectangle #include using namespace std; setHeight (int h): mutator for height variable setWidth (int w): mutator for width variable setDimensions (int h, int w): sets both height and width getArea (): returns the area of the rectangle getPerimeter () returns the perimeter of the rectangle print (): prints a rectangle with your dimensions composed of asterisks (3) Create a default constructor that sets the default values of Rectangle class to 1. int main() { Rectangle rec rec2; recl.setHeight (10); recl.setWidth (20); Page rec2.setDimensions (5, 10); cout of 2 ZOOM +arrow_forwardUsing C++ Define the class called Student. The Student class has the following: Part 1) Private data members: name(string), age(int), units(int). The units represent the number of quarter units student is enrolled in. Define a default constructor as well as a constructor with parameters for the class Student. The class must have get and set functions for all private data members. The set function for the data member units must throw “out_of_range” exception if the number of units is not between 1 and 15. Include a function called tuition (double feePerUnit) that computes and returns the cost of registering for the number of units (in the private data member). The function receives the cost per unit as a parameter. Overload the operator (<<) to display student name and age. Test the class Student by writing a main program in which a Student object is created and displayed. Call the function tution(), you may pass any value as feePerUnit parameter to this function and display the…arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education