using namespace std is considered bad practice
lines 24 and 25 can initialize:
double fuel{}; //0.0
which eliminates the need for your basic () constructor.
what you have is more typical and usually necessary, but in this specific case, you can default parameter to save making so many ctors:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
class foo
{
int x{};
int y{};
public:
foo(int a = 0, int b = 0)
: x{a}, y{b}
{}
void print() {cout << x << " " << y << endl;}
};
int main()
{
foo f;
f.print();
foo g (42);
g.print();
foo h (88,123);
h.print();
}
|
you do not need to write the destructor if it does nothing.
if you use different names, you can get rid of extra this-> syntax
consider:
1 2 3 4
|
void Fuel::set_distance (double distance_in)
{
distance = distance_in;
}
|
what you have looks good. The above changes save you typing, but the result is identical.
I strongly suggest you finish this program, and ask for help here if you get stuck (post the new code please). You have a good start but its mostly empty print statements. If you can finish this one, you will be able to do the next one much faster and easier than if you put this aside and get a new assignment. The next one will expect you to know everything you did here AND something new.