Archive

Posts Tagged ‘object-oriented programming’

10 Major Differences Between C And C++

August 14th, 2009 Rishabh Dev 2 comments

C++, as the name suggests is a superset of C. As a matter of fact, C++ can run most of C code while C cannot run C++ code. Here are the 10 major differences between C++ & C…

1. C follows the procedural programming paradigm while C++ is a multi-paradigm language(procedural as well as object oriented)

In case of C, importance is given to the steps or procedure of the program while C++ focuses on the data rather than the process.
Also, it is easier to implement/edit the code in case of C++ for the same reason.

2. In case of C, the data is not secured while the data is secured(hidden) in C++

This difference is due to specific OOP features like Data Hiding which are not present in C.

3. C is a low-level language while C++ is a middle-level language

C is regarded as a low-level language(difficult interpretation & less user friendly) while C++ has features of both low-level(concentration on whats going on in the machine hardware) & high-level languages(concentration on the program itself) & hence is regarded as a middle-level language.

4. C uses the top-down approach while C++ uses the bottom-up approach

In case of C, the program is formulated step by step, each step is processed into detail while in C++, the base elements are first formulated which then are linked together to give rise to larger systems.

5. C is function-driven while C++ is object-driven

Functions are the building blocks of a C program while objects are building blocks of a C++ program.




Your Ad Here

6. C++ supports function overloading while C does not

Overloading means two functions having the same name in the same program. This can be done only in C++ with the help of Polymorphism(an OOP feature)

7. We can use functions inside structures in C++ but not in C.

In case of C++, functions can be used inside a structure while structures cannot contain functions in C.

8. The NAMESPACE feature in C++ is absent in case of C

C++ uses NAMESPACE which avoid name collisions. For instance, two students enrolled in the same university cannot have the same roll number while two students in different universities might have the same roll number. The universities are two different namespace & hence contain the same roll number(identifier) but the same university(one namespace) cannot have two students with the same roll number(identifier)

9. The standard input & output functions differ in the two languages

C uses scanf & printf while C++ uses cin>> & cout<< as their respective input & output functions

10. C++ allows the use of reference variables while C does not

Reference variables allow two variable names to point to the same memory location. We cannot use these variables in C programming.

51 people like this post.

Popularity: 100% [?]

The Basics Of Object Oriented Programming

August 11th, 2009 Rishabh Dev 3 comments

As I pointed out in my previous post, we use classes in Object Oriented Programming(OOP) which are a blueprint of objects that share common properties. This use of classes & more precisely, of objects makes the process of programming easy & efficient.

That was exactly the reason why the Object Oriented Programming Paradigm was introduced. Now, there are certain fundamental features that you would find in every object oriented programming language.

Lets now take a look at each of them individually,
Lets take up CLASSES first. They consists of entities called objects-or they are blueprints of objects.

For example, a car would be a class & a van would be an object that belongs to the class called cars. Now, once we know the behavior of this object, we can use it anywhere we need in the program without having to define the behavior/properties again & again, which is the basic aim of OOP.

The objects here act as building blocks of the program. Though the objects can differ in terms of specific attributes(like a van could be red or blue), the classes would only depict the common behavior of all objects(like each car would have 4 wheels, turn left, right & so on…)

Now, the basic features of OOP…

A) Polymorphism – It simply implies “something having various forms”.
In the OOP world, this is evident with variables & functions.(and hence, with objects as well)

For instance, A variable called MEMBERID could take a name or a number & the program would recognize & accept both.

Another example is the “+” sign which can denote the mathematical operation, or strings or lists.

B) Inheritance – It is simply forming new classes(derived classes) from previously existing ones(base classes). In the process, the derived classes inherit certain properties of the base classes.

The concept is similar to how children inherit certain features from their parents, hence, the base classes are also sometimes refereed to as ancestor classes.

In terms of relationships, we call the relation between the base & derived class the as-is relationship. Consider the base class “car” & the derived class “bmw”. Then we can say “bmw” is-a “car” which is generalized to “derived class” is-a “base class”.

Encapsulation, Data Abstraction & Information hiding are very similar concepts & people often confuse them to be the same.

In one single statement, Abstraction is a technique that lets us know what information should be visible, and what information should be hidden. Encapsulation is the technique to display the information in a way as to hide what should be hidden, and show what’s needed.
Then, Information Hiding is the process of hiding all the inessential details of an object.

11 people like this post.

Popularity: 8% [?]

C++ Tutorial 2 – Multi-Paradigm Programming

August 7th, 2009 Rishabh Dev 1 comment

Whenever the programmers feel the need to change the basic layout of setting up a program, a new paradigm is introduced. Computer languages can then be classified based on the respective paradigm.

A programming paradigm is nothing but a style of programming. In one paradigm we may concentrate on the logic, in another, we may stress on the structure or procedure of our program.

C++ is a programming language that uses three such paradigms & hence, is said to be a Multi-Paradigm programming language.

A) Generic – We generalize concepts as templates & reuse them in the source code.

B) Imperative – We work with a sequence of commands so as to change the state of the program.

(Procedural Programming is the most common way this can be done. Structural Programming is a subset of Procedural programming)

C) Object-Oriented – We use classes which are blueprints of objects that share common behavior & properties.

(The focus here is on the data & instructions rather than the process).

[Go to Tutorial 3]

6 people like this post.

Popularity: 5% [?]

Content Protected Using Blog Protector By: PcDrome.