Ask Question
28 September, 21:35

Given: The following if statement uses an overloaded > operator to determine whether the price of a Car object is more than $5000. Car is a struct and myCar is an object of Car. Each Car object has two variables: id (int) and price (float). As you can see in the following code, the ID of myCar is 12345 and the price is $6,000.

Car myCar = {12345, 6000.};

float price = 5000;

if (myCar > price)

cout << "My car price is more than $5,000./n";

Which one of the following function prototypes is correct syntax to overload the > operator based on the if statement above.

a. void operator> (float price);

b. bool operator> (Car& car, float price);

c. bool operator > (float amt);

d. bool operator> (Car& yourCar);

e. none of the above

+5
Answers (1)
  1. 29 September, 01:35
    0
    Option (c) is the correct answer to the given question.

    Explanation:

    In the given question car is the structure and mycar is the instance or the object of the class also the object mycar holds two variables of type integer and the one float variable.

    Following are the syntax of operator overload in C+ + programming language

    return - type operator operator-symbol (datatype variable name)

    Now according to the question the option (c) follows the correct syntax of operator overload

    All the other option do not follow the correct prototype that's why these are incorrect option.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Given: The following if statement uses an overloaded > operator to determine whether the price of a Car object is more than $5000. Car is a ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers