23.8k views
5 votes
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 Cor 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. void operator> float price: O bool operator>(Car & car, float price): bool operator (float amt): bool operator> Car & your Car): None of the above

1 Answer

3 votes

Answer:

The correct syntax to overload is bool operator (float amt): so, the third statement is right.

Step-by-step explanation:

Solution

From the given question we have to find which statements is correct for the following function prototype.

Now,

Since the price of a Car object is above $5000, the car here is considered a struct and myCar is an object of Car

Both Car object consists of two variables which are id (int) and price (float)

Thus, from the given example the corresponding code says that the ID of myCar is represented as follows:

myCar - [12345, 6000);

The float price = 5000

Then,

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

Therefore the following statement bool operator (float amt): is the right syntax to overload.

User Fishman
by
5.2k points