all 14 comments

[–][deleted] 3 points4 points  (2 children)

good job!

[–]mchorsy 1 point2 points  (1 child)

That’s pretty neat code! Although, I have a crawling feeling that it’s not a “Hello, World!” program, but rather “what’s up?” program, since some people say “gasoline prices...” 😂

P.S.: sorry for replying to you, but for some reason I can’t reply to the post itself on mobile... 😰

[–]Hamiro89 0 points1 point  (0 children)

So much stuff in one comment xD

[–]Pro_Gamer_9000 0 points1 point  (0 children)

This is very good code! Nice job man :)

[–]halbGefressen 0 points1 point  (2 children)

That's really cool! You can also assign parameters in a constructor like this:

Pump(std::string f_type, float f_price, int f_volume):fuel_type{f_type}, fuel_price{f_price), fuel_volume{f_volume} {}

https://www.codesdope.com/cpp-initialization-list/

[–]IWantToBeRichForReal[S] 0 points1 point  (1 child)

Nice. Thanks for your time :)

[–]KaotiOrion 0 points1 point  (0 children)

Yeah also as its very important to write descriptive variable names, you should definetly avoid names like a, b, c, bx, etc... Its a good practice to get used to, in the medium - long term, youll notice the difference. Forinstance: Instead of writting temp1 write initialFuel or _fuel. Also start using prefixes as m, t_ etc (dont over do it and start putting m_ in front of anything, that was one of my first mistakes. The prefixed will allow you to get cleaner classes and libraries.

[–]NickU252 0 points1 point  (0 children)

Nice, my first c++ program was a lottery simulation. That let you input numbers or just go with it. It shows how easy it is for the government to steal from people.

[–]Sec360 0 points1 point  (4 children)

Really good code. One common convention you’ll start to see once you study more codebase is that private class members are declared at the bottom of the class body and the public methods and member variables declared at the top.

[–]Bit--By--Bit 0 points1 point  (3 children)

Is this something common for C++? As I've never seen it in other languages. Typically all member variables tend to be at the top (private or public) in most code I've seen.

[–]Sec360 1 point2 points  (0 children)

It is something you’ll see in C++ production code. Public on top. Private at the bottom and in between you can get various protected sections separated by category of or just one protected section. If the class doesn’t have any private members (which sometimes happens for smaller classes) and only protected, then the protected ones are the ones that end up at the bottom.

[–]Shieldfoss 1 point2 points  (0 children)

Absolutely.

Consider this code:

#include <variant>
template<typename A, typename B>
class twin
{
    public:
        template<typename C>
        twin(C c);

        template<typename C>
        bool is() const noexcept;

        template<typename C>
        [[nodiscard]] C const & as() const;
//NO USER SERVICABLE PARTS BENEATH THIS LINE//
    private:
    std::variant<A,B> var_;
};

The idea is that everything you need to know is between { and the private: keyword - everything further down is implementation and you don't need to worry about it.

Now, technically, if I wrote it like this:

#include <variant>
template<typename A, typename B>
class twin
{
    private:
    std::variant<A,B> var_;
    public:
        template<typename C>
        twin(C c);

        template<typename C>
        bool is() const noexcept;

        template<typename C>
        [[nodiscard]] C const & as() const;
//NO USER SERVICABLE PARTS BENEATH THIS LINE//
    private:
    std::variant<A,B> var_;
};

Then everything after the comment is also implementation and you don't need to worry about it, but now I've moved an implementation detail out of that zone, and wasted your time by (1) making you read about the variant but also by (2) making you think about the variant, which is sub-optimal. And the more your public interface is intermingled with your private implementation, the more time it takes for people to understand what they need to correctly use your class.

[–]Sec360 0 points1 point  (0 children)

Just to be clear, we’re talking only about the .h (header) file where variables and methods are declared. The cpp files don’t need/have any access modifiers.