OOP

I was just wondering before I actualy learnt C++ OOP, if there was anything that I could make after I learned OOP that I couldn't before? Or will OOP just make everything a heck of a lot easier?

Thanks

Arcadiu
OOP makes things easier and better (think about C strings and C++ strings)
hmm sorry I have no knowledge of C at all as I just jumped straight into C++ because 1, i heard C++ was better, for obvious reasons (OOP) and that I didnt want to get bogged down in all the C code and then move to C++ code as I thought it might be hard to get out of habits from C.

But anyway thankyou.
Hi Arcadiu!
Well, OOP has some advantages over procedural programing.The base of OOP programming are, as far as i know, classes. A class is basically a data type that you make yourself, like int or boll or char, but this time you make the data type.Of course you make that data type out of the existing data types in that programming language, in the case of C++ you make your data type out of int, bool, char, string, etc.For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
class Student
{
   string name;
   int average_grade;
   bool passed_exams;
   //etc.
}

Student Alex_Smith; /* just like you would create a normal variable, except Alex_Smith is a variable of type Student */

Alex_Smith.name="Alex Smith"; // change the value of the name
Alex_Smith.average_grade=9.4; // change the value of the average grade
Alex_Smith.passed_exams= TRUE; // the student passed the exams 


As you can see the data is grouped into one whole, it's not separated, name, average_grade and passed_exams are all grouped together.
The difference between C++ and C is that you can also put functions, not just variables inside classes.Of course, in C they are called structures.C++ has both, but there is only one difference between them.So you can do:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Student
{
   string name;
   int average_grade;
   bool passed_exams;
   //etc.
   
   change_grades(); //function that chaenges grades, just an example, it does not have parameters
   graduate(); function that "graduates" the student
}

Student Alex_Smith; /* just like you would create a normal variable, except Alex_Smith is a variable of type Student */

Alex_Smith.name="Alex Smith"; // change the value of the name
Alex_Smith.average_grade=9.4; // change the value of the average grade
Alex_Smith.passed_exams= TRUE; // the student passed the exams

Alex_Smith.graduate(); // now we've made the student graduate 


Anyway please read the tutorias from this site or from other sites if you do not have a book.
All i'm trying to say is that C++ offers both procedural programming and OOP programming.You chose how to combine them or you can even use just one.C only offers very limited, if not, any OPP an Java enforces only OPP programming.In C++ you have more freedom.
Ok and a struct is just a shortened way of saying structure? I know this might sound obvious but incase it actualy isn't the same thing.
Yes, struct is the C++ version of "structure"
Ok thanks :)
Object-oriented programming is geared towards making software development easier, by modelling the real world that we live in, and very importantly, to make major changes in a program possible.

Modelling real world:
Since OOP binds together data and operations that may be carried out on that data, it is easier to represent a real world situation when solving a problem. For example when writing a program, let's say, to store details of employees. With an OOP perspective you see that you could create an employee class, as each employee has 'data' like name,DOB,sex etc, but he also has 'methods', like CalculatePay(), DeductSalary() etc...

Making major changes to programs:
If a program were written using purely procedural techniques, such that the program consists of several functions calling each and passing data to solve the actual programming problem, then only a slight change to a function might mean that large parts of the program be modified. With OOP, since data is bound strictly to methods, if some changes were to be made to the data, then only that particularly class would need altering.

OOP has many other advantages, but personally i think these two are the main ones.
Topic archived. No new replies allowed.