Ads 468x60px

Monday, 14 January 2013

Features of OOP

Let us look at the features, 
We will make an attempt to understand the above from a logical point of view. 

Encapsulation
The example of a TV set is often taken to illustrate objects and characteristics of OOP. The TV receiver is totally encapsulated. We cannot see the components inside or meddle with them. However, we can use the TV set easily. We can switch it on and select channels with the external interfaces provided in the receiver. This is the concept of encapsulation of objects in an OOP. 
Wrapping together data and functions creates the objects in OOP. They are bound together. This represents encapsulation in OOP. We can use the encapsulated objects through the designated interfaces only. Thus, the inner parts of the program are sealed or encapsulated to protect from accidental tampering. This feature is not available in the conventional procedure oriented programming languages where data can be corrupted since it is easily accessible. In C++, like other object oriented programming languages such as Java and C#, encapsulation is achieved through what is known as classes. 

A Class is a blueprint for making a particular kind of object, It defines the specifications for construction an object with data and function. It is generally specifies the private working of objects and their public interfaces. The data, known as data members, defines the state of the proposed object and function of its behavior. 

The class is used to declare two types of members:
1. Data 
2. Functions

Data are nothing but declaration of variables for holding data, Functions, called member functions, contain sequence of instructions that operate on the data. An object is nothing but a variable of type class. it is a self contained computing entity with its own data and functions. This means that an object will have its own copy of the variables. However, the functions being common to all the objects do not need to be kept in each object. 

Note carefully that a class can give rise to a number of objects, but is not an object on its own. It is only a structure or blueprint which helps in creating replicas with common structures, but different characteristics. This means, two objects of a class with different names will have same variable names but with different values i.e., they have the same data type but different data. In some special cases, two objects can also have same data. A class is a framework for proper encapsulation of objects. The data members of the objects can be accessed only through the interface available in public. 

Syntax for declaring a class
class class_name
{
   data's;
   functions;
};
Suppose we need to create a class for student the we will write
class student
{
  char name[20];
  int roll_no;
  char sec;
  
  public:
  void student_details()
  {
    cout<<"Enter name:\t";
    gets(name);
    cout<<"Enter Roll Number:\t";
    cin>>roll_no.;
    cout<<"Enter Section:\t";
    cin>>sec;
  }
};
This is a class name student which will store a student's name, roll number and section. Now the function is declared under public, because we need a main function for the execution of program and if the function is private then main function has not the permission to access the function so your program will give an error that function is inaccessible so we need to declare the function in public. Now for accessing anything under a class you need an object of that class and that is called encapsulation. When we create object of a class all the data of that class is encapsulated under a single object called encapsulation. 
class student
{
  char name[20];
  int roll_no;
  char sec;
  
  public:
  void student_details()
  {
    cout<<"Enter name:\t";
    gets(name);
    cout<<"Enter Roll Number:\t";
    cin>>roll_no.;
    cout<<"Enter Section:\t";
    cin>>sec;
  }
};

void main()
{
  student obj;
  obj.student_details():
}
The syntax for creating an object is
class_name object_name;
As we did above, and for accessing anything from class the syntax is
object_of_that_class.element_of_that_class
In object part we have to write the object name which we created for that class and after than we need to place a dot ( . ) and then have to write the element which we want to access, the element can be anything from that class e.g. functions and variables. The element will only be accessible when public. 

Abstraction
Data abstraction refers to, providing only essential information to the outside word and hiding their background details i.e. to represent the needed information in program without presenting the details.
For example, a database system hides certain details of how data is stored and created and maintained. Similar way, C++ classes provides different methods to the outside world without giving internal detail about those methods and data.

Data Hiding
Related to the idea of encapsulation is the concept of data hiding. Encapsulation can hide data from classes and functions in other classes. In the example of the class Transport, we can access the three data members through the member function set_values(). Although there may be many other attributes and data elements in the class Transport, these are all hidden from view. This makes programs more reliable since declaring a specific interface, such as public or private, to an object prevents inadvertent access to data in ways that it was not designed for. In C++, access to an object and its encapsulated data and functions is treated very carefully using the keywords private, protected and public. The programmer has the facility to decide the access specifications for data objects and functions as being private, protected and public while defining a class. Only when the declaration is public can other functions and objects access the object and its components without question on the other hand if the declaration is private there is no possibility of such access. When the declaration given is protected, access to data and functions in a class by others is not as free as when it is public, not as restricted as when it is private. You can declare one base class as being derived from another, which will be discussed shortly. 

Inheritance 
A software object does not exist by itself; it is always an instance of a class. A class gives a blueprint for building a software object and can inherit the features of another class and add its own modifications. Inheritance is similar to human beings. A child can inherit his/her father's property and add/acquire more properties; he/she can modify the inherited property; or dispose of a property. In a similar manner, a new class can inherit its properties from another existing class. 
A class can have a child, which means one class can be derived from another. The original or parent class is known as the base class and the child class is known as the derived class. 

Polymorphism
Polymorphism is a useful concept in OOP languages, In simple terms it means one name, many duties. It provides a common interface to carry out similar tasks. In other words, a common interface is created for accessing related objects. This facilitates the objects to become interchangeable black boxes. hence they can be used in other programs as well. Therefore, polymorphism enables reuse of objects built with a common interface. 

Overloading
The concept of overloading is also a branch of polymorphism. When the exiting operator or function is made to operate on new data type it is said to be overloaded.

Atif Aslam Promotional Songs Download

The Pakistani super star has sung a number of promotional songs for various products in India and Pakistan. Here we are uploading those songs in mp3 format. 

Promotional Songs by Atif Aslam(Click on the Song to Download)

1. Jee Lay Zindagi by Atif Aslam

2. Juru Gey to Jano Gey by Atif Aslam

3. Hum Mustafavi Hain by Atif Aslam and Dawood ali

Post will update soon...

Sunday, 13 January 2013

Atif Aslam and Slash: Wish You Were Here Mp3 Download


Atif Aslam performed "Wish you were here" by Pink Floyd live with the former members of the American hard rock band Guns N' Roses - Slash, Matt Sorum and Gilby Clarke as well as with Shaun Lenon and Lanny Cordola at the "Best Buy Theatre" in New York City.
Download the audio version of that live performance from the link given below. Click on the song to download. 

Object Oriented Programming Systems

Object Oriented Programming Systems (OOPS) are widely used in software development projects. C++ is one of the early OOPS. Using OOPS for program development reduces programming errors and improves their quality. Representing objects of the real world as software objects in OOPS is quite a natural way for program development. The introductory section brings out the characteristics of OOPs and, in particular the three basic characteristics, which are:
1. Encapsulation
2. Inheritance 
3. Polymorphism

Object Oriented Programming
The prime purpose of C++ programming was to add object orientation to the C programming language, which is in itself one of the most powerful programming languages.
The core of the pure object-oriented programming is to create an object, in code, that has certain properties and methods. While designing C++ modules, we try to see whole world in the form of objects. For example a car is an object which has certain properties such as color, number of doors, and the like. It also has certain methods such as accelerate, brake, and so on.

Advantages of OOP
Re-usability
It refers to the ability for multiple programmers to use existing written and debugged classes in their programs. This is a time saving and quality improvement mechanism that adds coding efficiency to a language. Moreover, the programmer can incorporate new features into an existing class, further developing the application and allowing users to achieve improved performance. This time saving feature optimizes code, helps to gain secured applications and facilitates easier maintenance of applications. Object oriented programs are designed for reuse. The features which facilitate ease of reuse, are encapsulation and inheritance. 

Maintainability
Since each class is self contained with data and functions and also the functions are grouped together, these programs are easily maintainable. Encapsulation enhances maintainability of programs. 

Natural
The software objects represent the real objects in the problem domain and hence the programming is quite natural to reality. They can be given real names such as transport, cycle, etc. thereby enhancing understand-ability of the code. 

Modular
Modularity is unique not only to OOP, but to function oriented programming as well. Modularity in OOP is facilitated through the division of a program into well defined and closely knit classes. Thus, any complex program can be divided or partitioned into modules, and the divide and conquer strategy can be used for program design through modularization of the code through classes. 

Extensibility
The inheritance mechanism of OOP facilitates easy extension of the features of classes. Thus, old and proven code can be extended easily through the inheritance property of OOP. 

Data Integrity
Avoiding global variables, goto statements and binding the data within the class ensures data integrity and restricted access - which is the very purpose of OOP. 

Improved Quality
One of the objectives of OOP is to improve the quality of programs. C++ constructs reduce the chances of programming errors with their inbuilt modularity and re-usability. 

String

More than one character is called as a string. Suppose we need to store a name on a variable, but we can only store a single character by declaring a char type variable so if we need to store a name then we have to use character array. 
char name[30];
Now we can store a name in it, but how can we take the input, cin will not accept space so we can't take input by cin for a sentence or some words, cin can be only used for a single word, we can use looping, we can also take input by using function gets or getline, this would be more easier. 
gets(name);
cin.getline(name,30)
In gets we have to pass the variable name as the parameter in gets function, this function is defined under the header file stdio.h, so if you are using it you must define the header file to avoid error. 

In getline the syntax is 
cin.getline(variable_name,size)

Every string is terminated with NULL ('\0') character, so if we are declaring a character array of size 30, we can store only 29 characters on it because the last space is reserved for NULL character. 

Lets Understand it with a program 
Write a program to find the length and reverse of a string. 
#include<iostream.h>
#include<stdio.h>
#include<conio.h>

void main()
{
 clrscr();
 char string[30];
 int i,l=0;

 cout<<"Enter a string:\t";
 gets(string);

 for(i=0;string[i]!=NULL;i++)
 {
  l++;
 }

 cout<<"The Length is "<<l<<endl;
 for(i=l;i>=0;i--)
 {
  cout<<string[i];
 }
 getch();
}
Explanation of the Program 
Variable declares are:
One character array of size 30, two integer variables i for loop and l for counting length. 

At first user gets a message that enter a string and we took input from the gets function by passing the variable name as the parameter. 

Suppose we entered 
belal haque khan

Now for loop, i is initialized with 0, and then the conditions (string[i] != NULL) is checked which is true (string[0] = b and it is not equals to NULL), so because the condition is true control will come inside the loop and will increment l by 1, so the value of l was 0 and it will become 1, now the i will increment by 1 and will become 1, again the condition will checked which is true again and control will again come inside the loop and increment l by 1, this process will continue until the value of string[i] will not become NULL. 

Now the length is stored in l, we have printed the the length on the output screen now we need to print the reverse of the screen for this we have to start the array index from l (the length we calculated) and we have to print the each value from the back, for this we took the help of the loop. 

The loop is initialized with l (i = l) and l = 16 (calculated in the first loop), now the control will check the condition ( i >= 0 ) which is true (16 is greater than 0 ) the control will come inside the loop and print the value of string[i], the value of i is currently 16 so it will print the value of string[16]. Now the value of i is decremented by 1 and will became 15, again the control will check the condition which is true (15 is greater than 0) again control will come inside loop and will print the value of string[15], again the value of i will be decremented by 1 and again the control will checks the condition this process will repeat until the condition will not become false. 
Output of the Program

Double Dimension Array

A double dimension array is a matrix type in which we can store values in matrix form. 

Syntax
data_type array_name[row_size][column_size];
The array index starts from zero, same concept is applied here suppose we want to create a 3 x 3 matrix for storing value of name matrix then the syntax
int matrix[3][3];
The value it will store in the matrix form
a[00]     a[01] a[02]
a[10]     a[11] a[12]
a[20]     a[21] a[22] 

Lets understand it with a program
Write a program to print a matrix according to user's choice. 
#include<iostream.h>
#include<conio.h>

void main()
{
 clrscr();
 int i,j,r,c;
 int matrix[10][10];

 cout<<"Enter rows and cols:\t";
 cin>>r>>c;

 for(i=0;i<r;i++)
 {
  for(j=0;j<c;j++)
  {
   cout<<"Enter row "<<i+1<<" col "<<j+1<<":";
   cin>>matrix[i][j];
  }
 }

 cout<<endl<<"The matrix entered:\n";
 for(i=0;i<r;i++)
 {
  for(j=0;j<c;j++)
  {
   cout<<matrix[i][j];
   cout<<"\t";
  }
  cout<<endl;
 }
 getch();
}
Explanation of the program
The above program has one double dimension array variable of integer data type which can store matrix upto 10 x 10, and four integers variables i,j,r,c. 
int matrix[10][10]; //for matrix
int i, j; //for loops
int r,c; //for rows and columns 

At first we give the message to the user that enter the values of rows and columns and take the inputs and stored the values in variables r and c. 

Now the program has two phases one is input phase in which we take the values from the user and second is output phase in which we display the values to the output screen in matrix form. 

Suppose r = c = 2;

Input 
Nested looping is used for taking the values the outer loop is initialized with i = 0, this loop is for the rows. Now as the loop works i is initialized with 0 and now it will check the condition (i < r) which is true (0 is less than 2), the control will come inside the loop. 

Now the second inner loop j is initialized with 0 (j = 0), it will again checks for the condition (j < c) which is true (0 is less than 2) so the control will come inside the loop and will give the message to the user that 
enter row i + 1 (0 + 1) col j + 1  (0 + 1) :
i.e.
enter row 1 col 1: 

and will take a value and store it in the matrix[i][j]
The values are currently i = 0, j  = 0;
so the value will be stored in matrix[0][0]

Now the j in the inner loop will be incremented by 1 and become 1, again it will checks for the condition which is true (1 is less than 2)
again it will take a value and store it in the matrix [i][j]
the values are currently i = 0; j = 1;
so the value will be stored in matrix[0][1]


Now again the j in the inner loop will be incremented by 1 and become 2, again it will checks for the condition which is false (2 is not less than 2). 

Now the condition became false so it will again go to the outer loop.
The i will incremented by 1 and became 1, again the outer loop will checks for the condition which is true (1 is less than 2), the control again come inside loop and will come to the inner loop. 

Inner loop will again initialized with 0 and will checks for the condition which is true (0 is less than 2) the control will again come inside the inner loop and takes the value and store it in matrix[i][j]
the values are currently i = 1; j = 0;
so the value will be stored in matrix[1][0]


Now the j in the inner loop will be incremented by 1 and become 1, again it will checks for the condition which is true (1 is less than 2)
again it will take a value and store it in the matrix [i][j]
the values are currently i = 1; j = 1;
so the value will be stored in matrix[1][1]

Now again the j in the inner loop will be incremented by 1 and become 2, again it will checks for the condition which is false (2 is not less than 2). 

Now the condition became false so it will again go to the outer loop.
The i will incremented by 1 and became 2, again the outer loop will checks for the condition which is false (2 is not less than 2), now the first phase is completed input is over. 

Output
Output is almost same as input same nested looping will be used but just the place of input we have to place an output function (cout) and after printing we have to place a tab ("\t") and when one round of inner loop is completed we need to place a new line (endl) then it will be printed in the matrix format. 
Output of the Progam