so i figured out how to make a class and object of that class, but when i try to make a version of my own...all i think is that it seems easier to just use regular functions (global functions) to get the same job done.
Why use classes if it just takes so much time to make it all when it seems so much faster to just make a function branch of main???
FOR EXAMPLE...this code i could make so much less code and easier to understand by getting rid of the class and using global functions
Your running into an issue of "I don't need this right now, so it can't be useful".
I happen to think wichita.setSpeed(0); can't get anymore clear. I also notice you are using std::cout, which is a class. It is handling everything in the background from buffers to error checking, and that is the strength of class. Once you define the class properly, you can elegantly use it anywhere, and it will do exactly what it needs to do. And, just as important, when your code becomes giant, if you need to make any changes to the way a class functions, you only need to change that single class, and everywhere it is used will also be updated.
Is Tricycle::setSpeed() good from an o-o point of view? I'm a but suspicious of that particular method...
If you're modelling a bike, I don't think you'd have a setSpeed(). You would have a getSpeed, but you only get to a speed by pedalling. Or maybe by coasting down hill??
I suppose when the bike hits a wall, it sets its own speed to 0, or while at a stand still, get's hit by a car, would set it's speed to some high number.
I use to think the same but when I make a the class I get a feeling of clarity and my code seems so much easier to understand. But for me to get to that AH-HA moment I had to make a useful project. Try making a class that you will use. I made a class did a lot of annoying parts of code for me. Try making something like and you get the AH-HA moment. Hope this helps :)
First of all I am also new so I might not be the right person to ask so if I make a mistake please tell me about it.
Now to the problem:
Try making a class that handles allocation and de-allocation.
Or make a class that generates a number from 1 to a User Picked Number For Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <cstdlib>
class Generator
{
int Max; //Maximum value a random number can reach
public:
Generator (int M) //When class objects are initialized they have to have a limit value
{
Max = M;
}
int Generate () //Generates the number
{
int Random = 0;
Random = rand () % Max + 1;
return Random;
}
};
Try something making something fun or useful.
I am sorry I could not explain any further I suck at explanations sorry.
But most importantly Have fun :)