OBJECT ORIENTED PROGRAMMING, classes public and private access modifiers (syntax)

/**************OBJECT ORIENTED PROGRAMMING (oops)************ */
/*why oops???

#c++ language was designed with the main intention of adding object oriented
features to C language
#as the size of program increases readability, maintaibility and bug free nature of
the program decreases.
#this was tha main problem with langage C
#as a result the possiblity of not addressing the problem in an effective way increases
#also, as data was almost neglected, data security was easily compromised
#using classes solves this problem by modelling program as a real world scenario

PROCEDURE ORIENTED PROGRAMMING (POP) (jo abi tak kr rahe the)

#consists of writing a sequence of instructions for the computer to follow
#main focus is one functions and not on the flow of data
#functions can either use local or global data
#data moves openly from function to function

OBJECT ORIENTED PROGRAMMING

#Works on the basis of CLASSES and OBJECTS
#A class is a template to create objects
#treats data as a critical element (private and public)
#Decomposes the problem in objects and builds data and functions around the objects

BASIC CONCEPTS IN OBJECT ORIENTED PROGRAMMING

#CLASSES:basic template for creating objects (objects ke bare m info hoti h isme)
(classes bnaenge to unki memory or uske variables ki memory nhi li jaegi, objects bnaenge tab
memory allocate hogi)
#OBJECTS: basic run time entities
#DATA ABSTRACTION AND ENCAPSULATION: wrapping data and functions into single unit
(encapsulation mtlb capsule m daldo data ko, abstraction mtlb ek processor hai uske and
ek layer of abstraction m jayein to chip hoga)
#INHERITANCE: properties of one class can be inherited into others
(mtlb jese hum mummi papa ki properties inherit krlete hai, inhertance ek
method hai template ko edit krne ka jo ek dusre ki class ko represnt krti hai)
ek template ka use krke dusra template bana skte
#POLYMORPHISM: ability to take more than one forms (function overloading)
#DYNAMIC BINDING:code which will execute is not known until the program is run
#MESSAGE PASSING: object.function(information) call format

BENEFITS OF OBJECT ORIENTED PROGRAMMIG:

#Better code reusability using objects and inheritance
#principle of data hiding helps built secure systems
#multiple objects can co exist without any interference
 #software complexity can be easily managed
*/
#include<iostream>
using namespace std;

class Employee
    {
        private:
        int a, b, c;
        public:
        int d, e;
        void setData(int a1, int b1, int c1); //declaration only
        void getData()
        {
            cout<<"the value of a is "<<a<<endl;
            cout<<"the value of b is "<<b<<endl;
            cout<<"the value of c is "<<c<<endl;
            cout<<"the value of d is "<<d<<endl;
            cout<<"the value of e is "<<e<<endl;
        }


    };

    void Employee :: setData(int a1, int b1, int c1)
    {
        a=a1;
        b=b1;
        c=c1;
    }

int main(){
    //syntax for classes and objects

    Employee harry;
    //harry.a=57;  --> this will throw an error as a is private.
    harry.d=5;
    harry.e=7;
    harry.setData(1,2,3);
    harry.getData();

    return 0;
}

Comments

Popular posts from this blog

Function Overloading in C++

oops recall, basic operations and nesting of member functions