Government College University Faisalabad

;

Thursday, November 30, 2017

OOP 1-Lec

OOP


Object oriented programming is a technique for developing software on the basis of object is called
object oriented programming.
OOP stands for Object Oriented programming first we understand its working and functionality then we discuss its advantages and some other theory about OOP.

Syntax of OOP

#include<"file.header">   //Header files//

class example{             //example is the class name that we created//

private:
char name;
int age;                        /*Public and private , These are the Access specifiers.
                                         Detail is given in the below page.*/

public:
int data()
{
definition of the function;
}
};



Some important questions must be known before starting the OOP.

What are the data members and member functions?

These are the data of a class.If we define or declare a variable in a class, that variable is known as data member of that class.Similarly if we define a function in a class, that function is known as member function of that class.

What are the Access specifiers?

      Access specifiers are commands used for setting the access level to the data members and member function of a class are known as access specifiers.By default the access specifier are “Private”.There are three types of access specifiers.·         Private
·         Public
·        
Protected

Private
Protected
Public
Private data can access only within that class in which it is defined.
Protected data can be access in that class in which it is defined as well as can be access “inhered” classes or child classes.
Public data can be accessed anywhere in the program or any class can be used that type of data.

What is a class?

A class is a collection of data members and member functions that are used for the definition of objects.
In simply a class contain the properties of the objects.

What is an object?

An object is a name that can access or explore the data of a class.
Suppose we make a class of Employees and ali can be the object of Employees class.
Declaring of objects for accessing member functions:
  • ClassName  ObjectName;
  • objectName.functionName

First write the class name then writes the object name for accessing a function oop use dot operator between the object and the function.
employees ali;
ali.dispSalary();
Here dispSalary() is the member function of class employees.

In program where we can define a class?

  1.       We can define a class in three places.
  2. ·         Before the main function.
  3. ·         After the main function.
  4. ·         In a separate file. (Then include that file with the header files)

In which ways we can define a function present in class?

We can define a function declare in the class at two places.

Within the class.

Declare the function and simultaneously define that function within that class.

Outside the class.

Declare a function and define it outside the class using Scope resolution operator (::) J
That function must be public in the class.

In which ways we can declare an object?

Generally we declare the object in the main function but we can declare it in two ways.
  1. In main function.
  2. After the ending of the class and before the semicolon.

class example{
data member;
member function();
} object ;

How we can use an object for accessing the member functions and Data members of a class?

ClassName objectName;objectName.functionName;In this way we can access a function define in the class. 

// program input a number and display that number//
#include<iostream>
#include<conio.h>
using namespace std;
class inputDispValues
{
      private:
      int num;
      public:
      int inputValue(){
          cout<<"Enter a number \n";
          cin>>num;
          }
          void outputValue()
{
               cout<<"You entered \n"<<num<<endl;
               }
               };
              
                   
               int main()
               {
          inputDispValues obj;
                   obj.inputValue();
                   obj.outputValue();
                   getch();
                   return 0;
                   }





OUTPUT 




Download this lecture by : Click Here

Or Click on the below Download button for download the lecture












0 comments:

Post a Comment

Please give your comment.....

 
- | ,