Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question
  1. Consider the following code segment for a class named   vehicle:

class vehicle {

  private:

    string type;

    string model;

    string color;

    int numWheels;

  public:

    …

};

  1. 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
  2. Write the PROTOTYPE for a function that overloads the << (insertion) operator to print a vehicle object.
Expert Solution
Check Mark
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.
Step 2: Answer for 1.
The prototype for a function that overloads the “+” operator is as follows,
vehicle operator + (vehicle const &v);
bartleby

Step by stepSolved in 3 steps

Blurred answer
Knowledge Booster
Background pattern image
Computer Science
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
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education