Object Oriented Programming using C++

Day 1 -

Introduction : 

OBJECT-ORIENTED PROGRAMMING PARADIGM
The first object-oriented language Simula was developed in 1960 by researchers at the
Norwegian Computing Center.
In 1970, Alan Kay and his research group created a personal computer named Dynabook
and the first pure object-oriented programming language (OOPL) - Smalltalk, for programming
the Dynabook.
In the 1980s, Ada. Object Oriented Programming language was developed.
In the 1990s, Coad incorporated behavioral ideas into object-oriented methods.

OBJECT ORIENTED ANALYSIS

Object–Oriented Analysis (OOA) is the procedure of identifying the requirements for the program
In the Object-oriented approach, requirements are organized around objects, which integrate both data
and functions. They are modeled after real-world objects that the system interacts with. In traditional
analysis methodologies, the two aspects - functions and data - are considered separately.
According to Grady Booch, “Object-oriented analysis is a method of analysis that examines
requirements from the perspective of the classes and objects found in the vocabulary of the problem
domain”.
The primary tasks in object-oriented analysis (OOA) are −

  • Identifying objects
  • Organizing the objects by creating an object model diagram
  • Defining the internals of the objects or object attributes
  • Defining the behavior of the objects, i.e., object actions
  • Describing how the objects interact

The common models used in OOA are use cases and object models.

OBJECT-ORIENTED DESIGN

Object–Oriented Design (OOD) involves the implementation of the conceptual model which is developed
during object-oriented analysis. In Object Oriented design, concepts in the analysis model, which are
technology−independent, are transformed into implementing classes, constraints are identified and
interfaces are designed, resulting in a model for the solution domain, i.e., a detailed description
of how the system is to be built on concrete technologies.
The implementation details generally include −
  • Structuring the class data
  • Implementation of methods/functions, i.e., internal data structures and algorithms,
  • Implementation of control, and
  • Implementation of associations.
Grady Booch has defined object-oriented design as “a method of design encompassing the process
of object-oriented decomposition and a notation for depicting both logical and physical as well as
static and dynamic models of the system under design”.

OBJECT ORIENTED PROGRAMMING

Object-oriented programming (OOP) is a programming paradigm based upon objects (having both
data and methods) that incorporates modularity and reusability advantages. Objects,
which are usually instances of classes, are used to interact with one another to design applications
and computer programs.
  • The important features of object-oriented programming are −
  • The bottom-up approach in program design
  • Programs organized around objects, grouped in classes
  • Focus on data with methods to operate upon the object’s data
  • Interaction between objects through functions
  • Reusability of design through the creation of new classes by adding features to existing classes
BASIC CONCEPT OF OOPS

Following are the basic concepts of Object Oriented Programming

Class: Class is an entity that is used to bind variables of different data types and
functions together. A class is a blueprint for any functional entity that defines its properties and functions. Like human beings having body parts and performing
various actions.

Objects: An object is a variable whose data type is some class. These are the basic
concepts of oops which is also called an instance of an object.
o Inheritance: Through inheritance, it is possible to process members of one class by
using an object of another class.

Abstraction: Abstraction means showcasing only the required things to the outside
world and hiding the important information. For example, parts of human beings like
eyes, nose, etc are visible to the outside world but the things which are present in the heart
are not visible to the outside world.

Encapsulation: Encapsulation means binding things together. In c++ objects
contains Data members as well as member functions.

Polymorphism: Polymorphism means using the same thing for different purposes. C++
supports Function Overloading and Operator Overloading under compile time
polymorphism and Virtual Function under Runtime Polymorphism.
o Exception Handling: Exception handling is a feature of OOP to handle unresolved
exceptions, also called errors produced at runtime. For example divisible by
zero error.

BENEFITS OF OOPS
  • Through Inheritance it is possible to provide communication between two objects. So itis possible to process members of one class by using object of another class.
  • The principle of data hinding through visibility modes it is possible for the programmerto to secure the data in the program.
  • It is possible to have multiple instances of an object. Once a class is declared you can process the class members using different objects.
  • As it is object oriented it can be easily transformed from small scale to large scale. For example, if a student class is written with name , rno and total as data members, you can process data of one student also and data of 100s of students also.
  • Message passing techniques for communication between objects make the interfaced descriptions with an external system much simpler.
STRUCTURE OF C++ PROGRAM

The syntax for writing C++ program

[Preprocessor directives / Standard Libraries section]

[Declaration of user-defined functions(if any in the program)

[ main() function section]

{

[Declaration of Member variables and / Or member functions];

}

Normally in C++ program classes are declared before the main function

Example of a C++ program

#include<iostream.h>
#include<conio.h>
void main()
{
cout << “This is my first C++ Program”;
}

SOME SIMPLE C++ PROGRAMS

o Program for four basic arithmetic operations on given two numbers

#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c,d,e;
float f;
clrscr();
cout<<”Enter two numbers :>>”;
cin>>a>>b;
c=a+b;
d=a-b;
e=a*b;
f=(float)a/b;
cout<<endl<<”Addition is :”<<c;
cout<<endl<<”Subtraction is :”<<d;
cout<<endl<<”Multiplication is :”<<e;
cout<<endl<<”Division is :”<<f;
getch();
}


Program to calculate the area of a circle

#include<iostream.h>
#include<conio.h>
#define pi 3.14
void main()
{
float area,radius;
clrscr();
cout<<”Enter radius of circle :>>”;
cin>>r;
area=pi*r*r;
cout<<endl<<”Area of circle is :”<<area;
getch();
}



Reference video of Day 1



Comments

Popular posts from this blog

INTRODUCTION TO LANGUAGES

DECISION MAKING STATEMENTS IN C