0% found this document useful (0 votes)
20 views21 pages

Unit-1 CC

The document outlines the course content for a B.Com IT class focusing on Programming with C++. It covers the principles of Object-Oriented Programming (OOP), including its evolution, paradigms, and key concepts such as encapsulation, abstraction, polymorphism, and inheritance. The document emphasizes the advantages of OOP, such as reusability, data redundancy, code maintenance, security, and design benefits.

Uploaded by

PRIYADHARSHINI K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views21 pages

Unit-1 CC

The document outlines the course content for a B.Com IT class focusing on Programming with C++. It covers the principles of Object-Oriented Programming (OOP), including its evolution, paradigms, and key concepts such as encapsulation, abstraction, polymorphism, and inheritance. The document emphasizes the advantages of OOP, such as reusability, data redundancy, code maintenance, security, and design benefits.

Uploaded by

PRIYADHARSHINI K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

DEPARTMENT OF B.

COM IT

COURSE CONTENT

CLASS : II B.COM IT

SUBJECT: PROGRAMMING WITH C++

UNIT :1

Syllabus

Unit - I

Object oriented programming: Software Evolution – OOP paradigm – Concepts, benefits, Object

Oriented Languages and Applications.

UNIT-I

Object Oriented Programming

Object-oriented programming – As the name suggests uses objects in programming. Object-


oriented programming aims to implement real-world entities like inheritance, hiding,
polymorphism, etc in programming. The main aim of OOP is to bind together the data and the
functions that operate on them so that no other part of the code can access this data except
that function.

The Evaluation of programming concept:

• Programming languages have been passing through evolutionary generations

• Most of the programmers use only one language & one programming style
• The problem & difficult to choosing a style more appropriate to the problem

• Programming style is defined as a way of organizing the ideas on the basis of some
conceptual model of programming

• Using an appropriate language to write efficient programs

1. Paradigm

• Paradigm can also be termed as method to solve some problem or do some task.

• Programming paradigm is an approach to solve problem.Using some programming


language or also we can say it is a method to solve a problem using tools and techniques
that are available to us following some approach. There are lots for programming
language that are known .But all of them need to follow some strategy when they are
implemented and this methodology and strategy is paradigms.

• Apart from varieties of programming language there are lots of paradigms to fulfil each
and every demand

1.1 Types of PROGRAMMING PARADIGMS

The programming paradigm is categorized into the following

1. Monolithic programming

2. Procedural programming

3. Structured programming

4. Object oriented programming

1. MONOLITHIC PROGRAMMING

• Flat physical structure

• Consist of global data and sequential code

• Flow control of a Program is achieved by using jumping statements

• Program code is duplicated each time it is to be used

• No support of subroutine concept

• Suitable to developing small and simple applications


• No support for data abstraction & difficult to maintain and enhance

2. PROCEDURAL PROGRAMMING

• Program is intermediate between problem and computer.

• Software abstraction is achieved through this

Features

• Programs are organized in the form of subroutines and all data items are global

• Program controls are through jumps and calls to subroutines

• Subroutines are abstracted to avoid repetitions

• Suitable to design the medium sized software applications

• Difficult to maintain and enhance the program code

Example : FORTRAN & COBOL.

• STRUCTURED PROGRAMMING

• Used to address the growing issues of programming-in-the-large

• Large programming projects

• Program consist of multiple modules

Features

• Emphasis on algorithm rather than data

• divided into individual procedures & are independent of each other

• own local data and processing logic

• Parameter passing b/w procedure

• concept user defined data types & support for modular programming

• Co-ordination between multiple programmers is required changes made to mutually


shared data items
• It follows top-down approach

• Data is transfer from one form into another

Disadvantage:

• Maintenance of large software is tedious and costly

• Data move freely

Example: C and pascal program

• OBJECT ORIENTED PROGRAMMING

• Decomposition of problem into number entities called objects and builds data and
functions around these objects.

• It does not allow it to flow freely around the system.

• Emphasis is on data rather than procedure.

Software Evolution

Many programming approaches have been into play from the time of inventions
of the computer. These techniques include modular programming, top-down programming,
bottom-up programming and structured programming. The primary motivation in each case has
been the concern to handle the increasing complexity of programs that are reliable and
maintainable.

To build today’s complex software, it is just enough to put together a sequence


of programming statements and set of procedures and modules but to incorporate sound
construction techniques and program structures that are easy to comprehend, implement and
modify. C, structured programming was a powerful tool that enabled programmers to write
moderately complex programs fairly easily. However, as the programs grew, even the
structured approach failed to show the desired results in terms of bug-free, easy-to-maintain
and reusable programs.
OOP is an approach to program organization and development that attempts to
eliminate some of the pitfalls of conventional programming methods by incorporating the best
of structured features with several powerful new concepts.

A Look at Procedure Oriented Programming

Conventional programming, using high level language such as COBOL, PASCAL and C is
commonly known as Procedure-Oriented Programming (POP). In the procedure Oriented
Approach, the problem is viewed as a sequence of thing to be done such as reading, calculating
and printing. A number of functions are written to accomplish these tasks. The focus is on
function

The technique of hierarchical decomposition has been used to specify the task to be completed
for solving a problem.

Some characteristics exhibited by procedure-oriented programming


 Emphasis is on doing thing (algorithms).
 Large programs are divided into smaller programs known as functions.
 Most of the functions share global data.
 Data move openly around the system from function to function.
 Functions transform data from one form to another.
 Employs top-down approach in program design.

Drawbacks of Procedure Oriented Programming

 It emphasis on doing things. Data is given a second class status even through the
data is the reason for the existence of the program.
 Since every function has complete access to the global variables, the new
programmer can corrupt the data accidentally by creating function. If new data is
to be added, all the function needed to be modified to access the data.

Difference between Procedure Oriented Programming and Object oriented Programming

OOP POP

OOP takes a bottom-up approach in


POP follows a top-down approach.
designing a program.

Program is divided into objects Program is divided into small chunks based on
depending on the problem. the functions.

Each object controls its own data. Each function contains different data.

Focuses on security of the data Follows a systematic approach to solve the


irrespective of the algorithm. problem.

The main priority is data rather than Functions are more important than data in a
functions in a program. program.
The functions of the objects are linked via Different parts of a program are
message passing. interconnected via parameter passing.

Data hiding is possible in OOP. No easy way for data hiding.

Inheritance is allowed in OOP. No such concept of inheritance in POP.

Operator overloading is allowed. Operator overloading is not allowed.

C++, Java. Pascal, Fortran.

Object Oriented Paradigm

The major motivating factor in the invention of object-oriented approch is to remove some
of the flaws encountered in the procedural approch. OOP treats data as a critical element in
the program development and does not allow it to flow freely around the systems. It ties
data more closely to the functions that operate on it, and protects it from accidental
modification from outside functions. OOP allows decomposition of a problem into a number
of entities called objects and then builds data and functions around these objects. The data
of an object can be accessed only by the function associated with that object. However,
functions of one object can access the functions of other objects.
Some of the features of object-oriented programming are

 Emphasis is on data rather than procedure.


 Programs are divided into what are known as objects.
 Data structures are designed such that they characterize the objects.
 Data is hidden and cannot be accessed by external functions.
 Objects may communicate with each other through functions.
 New data and functions can be easily added whenever necessary.
 Follows bottom-up approch in program design.

Evolution of C++

C++ is an object – oriented programming language and is considered to be an extension


of C. Bjarne Stroustrup at AT&T Bell Laboratories, Murray Hill, New Jersey (USA) developed it in
the early eighties of twentieth century. Stroustrup, a master of Simula67 and C, wanted to
combine the features of both the languages into a more powerful language that could support
object – oriented programming with features of C. Various ideas were derived from SIMULA 67
and ALGOL68. Stroustrup called the new language “C with classes”. However, in 1983, the name
was changed to C++. C++ is an extended version of C.
Basic Concepts of Object Oriented Programming

Object-oriented programming aims to implement real-world entities like inheritance, hiding,


polymorphism, etc in programming. The main aim of OOP is to bind together the data and the
functions that operate on them so that no other part of the code can access this data except
that function.

Characteristics of an Object Oriented Programming language

Class:
The building block of C++ that leads to Object-Oriented programming is a Class. It is a user-
defined data type, which holds its own data members and member functions, which can be
accessed and used by creating an instance of that class. A class is like a blueprint for an object.

For Example: Consider the Class of Cars. There may be many cars with different names and
brand but all of them will share some common properties like all of them will have 4 wheels,
Speed Limit, Mileage range etc. So here, Car is the class and wheels, speed limits, mileage are
their properties.

 A Class is a user-defined data-type which has data members and member functions.
 Data members are the data variables and member functions are the functions used to
manipulate these variables and together these data members and member functions
define the properties and behaviour of the objects in a Class.
 In the above example of class Car, the data member will be speed limit, mileage etc and
member functions can apply brakes, increase speed etc.

Encapsulation:
In normal terms, Encapsulation is defined as wrapping up of data and information under a
single unit. In Object-Oriented Programming, Encapsulation is defined as binding together the
data and the functions that manipulate them.
Consider a real-life example of encapsulation, in a company, there are different sections like the
accounts section, finance section, sales section etc. The finance section handles all the financial
transactions and keeps records of all the data related to finance. Similarly, the sales section
handles all the sales-related activities and keeps records of all the sales. Now there may arise a
situation when for some reason an official from the finance section needs all the data about
sales in a particular month. In this case, he is not allowed to directly access the data of the sales
section. He will first have to contact some other officer in the sales section and then request
him to give the particular data. This is what encapsulation is. Here the data of the sales section
and the employees that can manipulate them are wrapped under a single name “sales section”.

Encapsulation also leads to data abstraction or hiding. As using encapsulation also hides the
data. In the above example, the data of any of the section like sales, finance or accounts are
hidden from any other section.

Abstraction:
Data abstraction is one of the most essential and important features of object-oriented
programming in C++. Abstraction means displaying only essential information and hiding the
details. Data abstraction refers to providing only essential information about the data to the
outside world, hiding the background details or implementation.

Consider a real-life example of a man driving a car. The man only knows that pressing the
accelerators will increase the speed of the car or applying brakes will stop the car but he does
not know about how on pressing accelerator the speed is actually increasing, he does not know
about the inner mechanism of the car or the implementation of accelerator, brakes etc in the
car. This is what abstraction is.

 Abstraction using Classes: We can implement Abstraction in C++ using classes. The class
helps us to group data members and member functions using available access specifiers. A
Class can decide which data member will be visible to the outside world and which is not.
 Abstraction in Header files: One more type of abstraction in C++ can be header files. For
example, consider the pow() method present in math.h header file. Whenever we need to
calculate the power of a number, we simply call the function pow() present in the math.h
header file and pass the numbers as arguments without knowing the underlying algorithm
according to which the function is actually calculating the power of numbers.

Polymorphism:
The word polymorphism means having many forms. In simple words, we can define
polymorphism as the ability of a message to be displayed in more than one form.

A person at the same time can have different characteristic. Like a man at the same time is a
father, a husband, an employee. So the same person posses different behaviour in different
situations. This is called polymorphism.

An operation may exhibit different behaviours in different instances. The behaviour depends
upon the types of data used in the operation.

C++ supports operator overloading and function overloading.

 Operator Overloading: The process of making an operator to exhibit different behaviours in


different instances is known as operator overloading.
 Function Overloading: Function overloading is using a single function name to perform
different types of tasks.Polymorphism is extensively used in implementing inheritance.

Example: Suppose we have to write a function to add some integers, sometimes there are 2
integers, some times there are 3 integers. We can write the Addition Method with the same
name having different parameters, the concerned method will be called according to
parameters.

Inheritance:

The capability of a class to derive properties and characteristics from another class is called
Inheritance. Inheritance is one of the most important features of Object-Oriented
Programming.
 Sub Class: The class that inherits properties from another class is called Sub class or Derived
Class.
 Super Class:The class whose properties are inherited by sub class is called Base Class or
Super class.
 Reusability: Inheritance supports the concept of “reusability”, i.e. when we want to create
a new class and there is already a class that includes some of the code that we want, we
can derive our new class from the existing class. By doing this, we are reusing the fields and
methods of the existing class.
Example: Dog, Cat, Cow can be Derived Class of Animal Base Class.

Dynamic Binding:
In dynamic binding, the code to be executed in response to function call is decided at runtime.
C++ has virtual functions to support this.

Message Passing:
Objects communicate with one another by sending and receiving information to each other. A
message for an object is a request for execution of a procedure and therefore will invoke a
function in the receiving object that generates the desired results. Message passing involves
specifying the name of the object, the name of the function and the information to be sent.

Benefits of OOP

Moving to the advantages of OOP, we would like to say that there are many as this is one of the
core development approaches which is widely accepted. Let’s see what are the advantages of
OOP.

1. Re-usability
It means reusing some facilities rather than building it again and again. This is done with the use
of a class. We can use it ‘n’ number of times as per our need.

2. Data Redundancy

This is a condition created at the place of data storage (you can say Databases)where the same
piece of data is held in two separate places. So the data redundancy is one of the greatest
advantages of OOP. If a user wants a similar functionality in multiple classes he/she can go
ahead by writing common class definitions for the similar functionalities and inherit them.

3. Code Maintenance

This feature is more of a necessity for any programming languages, it helps users from doing re-
work in many ways. It is always easy and time-saving to maintain and modify the existing codes
with incorporating new changes into it.

4. Security

With the use of data hiding and abstraction mechanism, we are filtering out limited data to
exposure which means we are maintaining security and providing necessary data to view.

5. Design Benefits

If you are practicing on OOPs the design benefit a user will get is in terms of designing and fixing
things easily and eliminating the risks (if any). Here the Object Oriented Programs forces the
designers to have a longer and extensive design phase, which results in better designs and
fewer flaws. After a time when the program has reached some critical limits, it is easier to
program all the non-OOP’s one separately.

6. Better productivity

with the above-mentioned facts of using the application definitely enhances its users overall
productivity. This leads to more work done, finish a better program, having more inbuilt
features and easier to read, write and maintain. An OOP programmer cans stitch new software
objects to make completely new programs. A good number of libraries with useful functions in
abundance make it possible.

7. Easy troubleshooting

lets witness some common issues or problems any developers face in their work.

 Is this the problem in the widget file?


 Is the problem is in the WhaleFlumper?
 Will I have to trudge through that ‘sewage.c’ file?
 Commenting on all these issues related to code.

So, many a time it happens that something has gone wrong which later becomes so
brainstorming for the developers to look where the error is. Relax! Working with OOP language
you will know where to look for. This is the advantage of using encapsulation in OOP; all the
objects are self-constrained. With this modality behavior, the IT teams get a lot of work benefits
as they are now capable to work on multiple projects simultaneously with an advantage that
there is no possibility of code duplicity.

8. Polymorphism Flexibility

Let’s see a scenario to better explain this behavior.

You behave in a different way if the place or surrounding gets change. A person will behave like
a customer if he is in a market, the same person will behave like a student if he is in a school
and as a son/daughter if put in a house. Here we can see that the same person showing
different behavior every time the surroundings are changed. This means polymorphism is
flexibility and helps developers in a number of ways.

 It’s simplicity
 Extensibility

9. Problems solving
Decomposing a complex problem into smaller chunks or discrete components is a good
practice. OOP is specialized in this behavior, as it breaks down your software code into bite-
sized – one object at a time. In doing this the broken components can be reused in solutions to
different other problems (both less and more complex) or either they can be replaced by the
future modules which relate to the same interface with implementations details.

A general relatable real-time scenario – at a high level a car can be decomposed into wheels,
engine, a chassis soon and each of those components can be further broken down into even
smaller atomic components like screws and bolts. The engine’s design doesn’t need to know
anything about the size of the tires in order to deliver a certain amount of power (as output)
has little to do with each other.

Object Oriented Programming Languages

Object-oriented programming concept is a famous programming approach which represents


the concept of objects and methods (member functions). Objects are the illustration of classes
which is used to interact with another module in the programming application• Major
programming languages support object-oriented concepts; object-oriented programming is
represented as OOPS (Object-Oriented Programming Structure).

In object-oriented programming, the concept of class is considered as an important feature. A


class is a collection of data members and member functions, which are used to represent the
overall structure of the project. The objects are created to access the variables and methods of
the class. Based on the class, the object will be created; hence, the class can be called as the
blueprint of an object. The objects are the representation of the real-world data; it provides
some object-oriented approach like data hiding or encapsulation.

Important features of object oriented Programming Languages are

• Objects and classes


• Inheritance
• Polymorphism
• Data hiding
• Overloading
• Encapsulation
• Reusability
Many languages are having object oriented Programming structure, and some of the languages
are
• C++
• C#
• Java
• COBOL
• Python

Applications of Object Oriented Programming

1. Client-Server Systems

Object-oriented Client-Server Systems provide the IT infrastructure, creating object-oriented


Client-Server Internet (OCSI) applications. Here, infrastructure refers to operating systems,
networks, and hardware. OSCI consist of three major technologies:

 The Client Server


 Object-Oriented Programming
 The Internet

2. Object-Oriented Databases

They are also called Object Database Management Systems (ODBMS). These databases store
objects instead of data, such as real numbers and integers. Objects consist of the following:

Attributes: Attributes are data that defines the traits of an object. This data can be as simple as
integers and real numbers. It can also be a reference to a complex object.
Methods: They define the behavior and are also called functions or procedures.
3. Object Oriented Databases

These databases try to maintain a direct correspondence between the real-world and database
objects in order to let the object retain their identity and integrity. They can then be identified
and operated upon.

4. Real-Time System Design

Real time systems inherit complexities that makes difficult to build them. Object-oriented
techniques make it easier to handle those complexities. These techniques present ways of
dealing with these complexities by providing an integrated framework which includes
schedulability analysis and behavioral specifications.

5. Simulation And Modeling System

It’s difficult to model complex systems due to the varying specification of variables. These are
prevalent in medicine and in other areas of natural science, such as ecology, zoology, and
agronomic systems. Simulating complex systems requires modelling and understanding
interactions explicitly. Object-oriented Programming provides an alternative approach for
simplifying these complex modelling systems.

6. Hypertext And Hypermedia

OOP also helps in laying out a framework for Hypertext. Basically, hypertext is similar to regular
text as it can be stored, searched, and edited easily. The only difference is that hypertext is text
with pointers to other text as well.

Hypermedia, on the other hand, is a superset of hypertext. Documents having hypermedia, not
only contain links to other pieces of text and information, but also to numerous other forms of
media, ranging from images to sound.
7. Neural Networking And Parallel Programming

It addresses the problem of prediction and approximation of complex time-varying systems.


Firstly, the entire time-varying process is split into several time intervals or slots. Then, neural
networks are developed in a particular time interval to disperse the load of various networks.
OOP simplifies the entire process by simplifying the approximation and prediction ability of
networks.

8. Office Automation Systems

These include formal as well as informal electronic systems primarily concerned with
information sharing and communication to and from people inside as well as outside the
organization. Some examples are:

 Email
 Word processing
 Web calendars
 Desktop publishing

9. CIM/CAD/CAM Systems

OOP can also be used in manufacturing and design applications as it allows people to reduce
the effort involved. For instance, it can be used while designing blueprints, flowcharts, etc. OOP
makes it possible for the designers and engineers to produce these flowcharts and blueprints
accurately.

10. AI Expert Systems

These are computer applications which are developed to solve complex problems pertaining to
a specific domain, which is at a level far beyond the reach of a human brain.It has the following
characteristics:

 Reliable
 Highly responsive
 Understandable
 High-performance

Python is being chosen by beginners as a preferred programming language as it makes coding


faster and easier. If you are looking to learn object oriented programming, you should look into
our Object Oriented Programming Fundamentals with Python.

Expected University Questions


(From B.Sc Computer Science)
POSSIBLE 5 MARKS

1. What are the advantages of Object Oriented Programming[NOV 2016]


2. Loops in C++[NOV 2016], [APR 2017]
3. Key concepts of Object Oriented Programming[APR 2017]

POSSIBLE 8 MARKS

1. OOPs Concepts[NOV 2016]


2. Decision Making Statements[APR 2017]
3. Loops in C++[NOV 2016]
4. Function Overloading[APR 2017], [NOV 2016]

POSSIBLE 1 MARK

1. Which of the following best defines a class?


a) Parent of an object
b) Instance of an object
c) Blueprint of an object
d) Scope of an object
2. What is the additional feature in classes that was not in structures?
a) Data members
b) Member functions
c) Static data allowed
d) Public access specifier
3. Which is not feature of OOP in general definitions?
a) Code reusability
b) Modularity
c) Duplicate/Redundant data
d) Efficient Code
4. Which Feature of OOP illustrated the code reusability?
a) Polymorphism
b) Abstraction
c) Encapsulation
d) Inheritance
5. Which language does not support all 4 types of inheritance?
a) C++
b) Java
c) Kotlin
d) Small Talk

6. How many classes can be defined in a single program?


a) Only 1
b) Only 100
c) Only 999
d) As many as you want
7. Which of the two features match each other?
a) Inheritance and Encapsulation
b) Encapsulation and Polymorphism
c) Encapsulation and Abstraction
d) Abstraction and Polymorphism

You might also like