Quick code question

I just have a quick question about classes: What is the point of a class exactly? What can I do with a class that I can't just as easily do with setting up functions? Are the only point of classes to help organize code or what? The programming language that I am learning is C++ by the way, if that modifies the answer.

Form what I know about implementations of classes in Java is to keep one function separated from the other. Say if an "OK" button is to be integrated with a window, that's the UI part, in another words, they're already within their own class together. The function of the button would have to be defined in its own class. This is to avoid possible overlapping with another code from the other class and for ease of debugging purposes.

Of course you can have classes in an hierarchical tree, but that's from what I know in Java, again. C++ could have the same principle but I'm not too sure about that.

So with Java, there is one class for the UI of the button and then another one that controls the functionality of said button?

That's what I have been taught and learnt in my programming class. This goes the same for other purposes. Classes are just to separate one piece of code with mostly of its own function from another (if they have a hierarchical formation)  for the purpose of ease of debugging for later and documentation.

Classes in programming are generally used to modularize code. Classes may not be "essential" to every program but classes can be very helpful depending on the task.  Classes are there so you don't write redundant code in your program.

Imagine if you're writing a program of a car lot and every car in the car lot needed it's functionality written independently. It would be a lot easier to write a car class. Where it takes input for its size,type,color,maker etc etc. For the functionality of the car, you would write "Methods" for the car.  Methods are what the car has the ability to do. So move forwards and backwards, honk the horn , open doors etc etc.  Now every "new car" has the ability to move and honk their horns but can look very different based on the input into the class. That is where the beauty of classes truly shines.

So by defining what a "Car" is to the program and what it can do, you efficiently save time in coding instead of writing each car separately and your code will probably a lot more manageable at the same time. Again classes are not essential in every program but they can be very helpful in certain programs as where functions are just inefficient.

There are a lot of uses for classes. Honestly, classes are one of the easiest ways to make your code simpler. I say that...I suppose it's a bit more complicated to write, but a lot easier to modify and use in the long run. I'm working on a project right now that serves as a pretty good example. Let's say you want to make a solar system. Rather than writing a function to make every single planet, you would create a planet class. This means that every single planet in the solar system would be its own object. Each planet would be an instant of the class. This means that each planet has its own separate methods and data.

To put it more simply, let's just use 3 planets. Well, each of these planets, even after creation, can be easily edited with mutator functions that are defined in the class. Assuming that each of the planets were created to be the same, you could change them very VERY easily even after their creation. If you used a function, going in to change the planets would be a hassle, and generally very difficult. This, in most cases, would require simply deleting the planet and remaking it as you see fit. With a class, you could call a mutator function defined in the class like planet:setSize( 30 ) to set the planet's size to 30, as opposed to whatever the default is. that would change that planet's size to 30 without changing the size of the other planets. For the second planet, you could do something like planet2:setType( terrestrial ) to change the planet to a terrestrial type (from one that would otherwise be uninhabitable). This is kind of a basic example, but classes basically serve as building blocks for the rest of your project. They are easily modifiable, and serve to break your code up into chunks, or objects. Basically, by breaking up your code into object, you can more easily debug runtime errors, and modify things in the code itself. 

It's just a way to make coding a lot easier. There's a lot more that goes into creating classes, and a lot of other reasons to use classes, but this is one fairly easy way to understand them. Just use them like building blocks. It allows you to work with a collection of data much more easily than you would normally be able to in a function. Every class can have its own separate functions and data. You can even alter a class to the extent that the plus sign would do something entirely different than normal. You could make a string class where typing 'concat = string1 + string2;' where the + symbol would concatenate the two strings together. Classes just grant you greater flexibility. They are extremely useful in more complex development projects. If you can start understanding them and implementing them in your code early on, you will benefit in the long run. Once you understand how useful classes are, you will be surprised how you've gone without them for so long.