Ask Question
6 October, 14:31

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

+1
Answers (1)
  1. 6 October, 16:59
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers