NEED help with this code, i need to put the code in place of(??????)

The code is suppose to enter the car's information and it compares which car has best finance mileage and cost of car.

#include<iostream>
using namespace std;
#include<string>
#define INT_MAX 100000
#define INT_MIN 0
using namespace std;


class Automobile
{
public:
    Automobile();
    void read();

    bool is_cheaper_than(??????) const;
    bool better_mileage_than(???????) const;
    bool better_finanace_than(??????) const;

    void print() const;
private:
    string name;
    float price;
    float mileage;
    float finance;


};

Automobile::Automobile()
{
name=" ";
price=INT_MAX;
mileage=INT_MIN;
finance=INT_MAX;

}

void Automobile::read()
{

cout<<"Model name:";
cin>>name;
cout<<"price";
cin>>price;
cout<<"miles per gallon:";
cin>>mileage;
cout<<"percent financing:";
cin>>finance;

}

bool Automobile::is_cheaper_than(?????) const
{
???????????

}
bool Automobile::better_mileage_than(?????) const

{

????????
}

bool Automobile::better_finance_than(?????) const
{
???????

}

void Automobile::print() const
{
cout<<"Model:" << name<<"\n"
    <<"price:" << price<<"\n"
    <<"Miles Per Gallon:" << finance<<"\n"
    <<"Financing:"<<"\n";
}




int main()

{
    Automobile best_in_price;
    Automobile best_in_mileage;Automobile best_in_fiance;   
    bool done = false;

while(!done)
{

    Automobile next;
next.read();

???????????????

    string answer;
cout<<"More Y/N";
cin>>answer;

if((answer) != "Y")
    done=true;
}


cout<<"\n\nnBest price:\n";
best_in_price.print();
cout<<"\n\nnBest mileage:\n";
best_in_mileage.print();
cout<<"\n\nnBest finanace:\n";
best_in_fiance.print();



}

Dani AI

Generated

Short answer: make the three comparison methods take the other Automobile by const reference and compare the appropriate member(s). That follows ’s object-oriented suggestion and keeps calls simple and efficient. Also fix the small naming/printing bugs in the original (mileage/finance swapped in the print, and inconsistent “finance/fiance/finanace” spellings).

Replace the "????" signatures with these and add these implementations:

bool Automobile::is_cheaper_than(const Automobile &other) const {
    return price < other.price;
}

bool Automobile::better_mileage_than(const Automobile &other) const {
    return mileage > other.mileage;   // higher mpg is better
}

bool Automobile::better_finance_than(const Automobile &other) const {
    return finance < other.finance;   // lower percent financing is better
}

In the input loop, after next.read(); update the three “best” objects like this:

if (next.is_cheaper_than(best_in_price))     best_in_price = next;
if (next.better_mileage_than(best_in_mileage)) best_in_mileage = next;
if (next.better_finance_than(best_in_fiance))  best_in_fiance = next;

Other quick fixes/tips:

  • Correct print() so it prints mileage under "Miles Per Gallon" and finance under "Financing".
  • Use std::getline(cin, name); (or read and discard the leftover newline) if model names contain spaces.
  • Prefer <limits> and std::numeric_limits<float>::max()/lowest() instead of custom INT_MAX/INT_MIN macros.
  • Make the "More Y/N" check case-insensitive (check first char with toupper) and fix the spelling inconsistencies (finance vs fiance).

These changes will make comparisons clear and the main loop work as intended for .

You have a couple of options:
You can pass it a float or a double
bool is_cheaper_than(float flt) const;

and fix your function to compare it's current value to the one passed in to the method...

Or you can pass it another Automobile class (reference or pointer)
and compare the internal value of the passed object to the current object's float value.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.