Professional Documents
Culture Documents
Introduction To Object Oriented Programming: UNIT-1
Introduction To Object Oriented Programming: UNIT-1
Programming
UNIT-1
Principles of Object Oriented
Programming
Software Crisis:-
Reasons -
• Dynamic nature of S/W tech.
• Look for new approaches to S/W design and
development.
• Increasing complexity; highly competitive
nature.
Issues to be addresses:-
• How to represent real-life entities of problems in
system design?
• How to design systems with open interfaces?
(heterogeneous entities)
• How to ensure reusability and extensibility of
modules?
• How to develop modules that are tolerant to any
changes in future?
• How to improve software productivity and decrease
cost?
• How to improve the quality of software?
• How to manage time schedules?
• How to industrialize the software development
process?
Maintenance costs:-
• Changes in data formats.
• Changes in user requirements
• Hardware changes
• Efficiency improvement
• Documentation
• Routine debugging
• Emergency fixes
Quality issues for critical evaluation:-
• Correctness
• Maintainability
• Reusability
• Openness and interoperability
• Portability
• Security
• Integrity / connectedness
• User friendliness
Software Evolution
-> Binary
-> Machine language
->Assembly language
-> Procedure – Oriented
-> Object - Oriented Programming
Procedure-Oriented Programming
• Problem is viewed as sequence of things.
• Primary focus is on functions. Fig. 1.4
• Limitations:-
– Very little attention is given to data; important
items are placed as Global.
– Does not model the real-world problems well.
• Top-Down approach in program design.
Object-Oriented Programming
Paradigm
• Treats data as Critical element.
• Does not allow it to flow freely. Data is hidden.
• Protects from accidental modifications.
• Allows decomposition of a problem into entities
called objects and build the functions for them.
• Various objects communicates through functions.
• Bottom-up approach.
• Fig. 1.6
Difference between OOPS and POP
Basis For comparison POP OOP
#include<iostream.h>
#include<conio.h>
int main()
{
int number;
clrscr();
cout<<“Enter number”;
cin>> number;
cout << “the number is” << number;
getch();
return 0;
}
Exercise
• Check whether a number is prime or not
• Check Whether Number is Even or Odd
• Create Pyramid and Pattern
• Find Quotient and Remainder
• Swap Two Numbers
• Check Whether a character is Vowel or
Consonant
• Find Largest Number Among Three Numbers
• Calculate Sum of Natural Numbers
• Check Leap Year
• Find Factorial
Points to Ponder
• Keywords
• Basic data types
• User-Defined data types (struct & union)
Reference Variables
• Provides an alias i.e. alternative name for already
defined variable.
• Both the names can be used interchangeably.
• Syntax:- data-type & reference-name = variable-name
(note:- & represents reference to that data type)
• Ex:- float total = 100;
float & sum = total; //reference variable sum is
initalized to value 100.
• cout<<total; cout<<sum; // same output.
• total = total +10; //changes both to 110.
• sum=0; // changes both to 0.
• It can also be created for user defined data types.
• More Examples:-
1) int n[10];
int &x = n[5]; //alias for n[5] value i.e. 6th value.
char &a=‘\n’; // holds next line char
cout<<x; //prints value of n[5]
cout<<a; //next line
2) int x;
int *p = &x;
int &m = *p; // i.e. int &m=x;
//m refers to x
Application of Reference Variable
• Passing arguments to function.
Call by reference:-