Ask Question
4 December, 00:00

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. 4 December, 00:18
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers