Why do classes make it easier to write a program in C++ than to do the same in C?
Why do classes make it easier to write a program in C++ than to do the same in C?
Basically classes help you take all the properties and behaviors of an object in your program, and combine them into a single interface, then re-use that interface wherever you need that type of object in your program.
Take strings for example. In C, if you are working with strings, copying them, concatenating them, getting their length, finding substrings, etc, you have to do a lot of work to make sure you have the right amount of memory available, then copy or concatenate the strings, etc. In C++, all that work is put together inside a string class that works like a built-in type. You copy C++ strings with =, combine strings with + or +=, and do other operations with member functions like find(), substr() or length(). Once you have that string class written, you just re-use it over and over as a new type without having to worry about the implementation details.
it took me a while to ... get why they were useful. I think time will teach you better than anything else, though Daved gave the example I was going to give. Having functions and operators associated with a variable is very very handy. Saves you having to remember functions manipulate variables etc. I love them
For small programs, I wouldn't say object oriented programming is "easier". (It might be easier if you learned C++ / OOP as your first programming language..)
But for large complex projects, it's easier to design and maintain the program. And, it's easier to break into tasks so that several programmers can work in parallel.
OOP seems to work well with GUI applications, where the user interaction is less rigid than traditional text-based programs.
When it comes to C vs. C++, it's a bit of a paradox. Some things, like strings or vectors (dynamic arrays) are easier in C++. But overall, the C++ language is much more complex and harder to learn than C. For example, there are a couple of referece books that cover the entire C language, but you can't find a book that covers every function in the ANSI/ISO C++ standard libraries (except for the language standard itself).
Thinking in C++ by Bruce Eckel will teach you why OOP is good and how classes work their way into OOP. (OOP = Object Oriented Programming)