You are on page 1of 9

UNIT – I

Classification of Programming languages:


Since the invention of the computer, many programming approaches have been
developed.
These include techniques such as modular programming, top-down programming,
bottom up programming and structured programming, and
Object Oriented Programming.

Based on the programming approaches we can broadly classify Programming


languages into three categories:
Procedural Programming Languages, Structured Programming languages, and Object
oriented Languages.

Procedural, Structural and Object Oriented Programming languages

→A procedural programming language consists of a set of procedure calls and a set of


code for each procedure.

These procedures are also known as subroutines or functions.

Example: Pascal, FORTRAN, COBOL.

→A structural programming language emphasizes on separating a program’s data.

Structured programming includes methods such as:

1. Top down / Bottom up analysis 2. Individual modules:

Example: ALGOL, Pascal, C, Ada.

→On the other hand, object oriented languages are based on entities known as
Objects, their actions known as Methods and forms a group known as A Class.

An object can be defined as the pairing of a piece of data with the operations that can
be performed on it. It is one of the latest and powerful types.

Objects are capable of storing information and they can also interact with other
Example: C++, C#, java.

Explain about OOP. Write about basic principles of OOP.

→Object-Oriented Programming Paradigm:


The major motivating factor in the invention of object-oriented approach is to remove
some of the flaws encountered in the procedural approach.

OOP treats data as a critical element in the program development. 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.

Some of the striking features of object-oriented programming are:

➢ Emphasis is on data rather than proc


➢ edure.
➢ Programs are divided into what are known as objects.
➢ Functions that operate on the data of an object are tied together.
➢ 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.
We define "objects oriented programming as an approach which includes creating
objects that contain both data and functions.
Basic concepts of object oriented programming:
Before starting to learn C++ it is essential that one must have a basic knowledge of the
concepts of Object Oriented Programming.
Some of the important object oriented features are namely:
1. Objects 2.Classes 3.Data Abstraction and Data Encapsulation
4. Inheritance 5.Polymorphism 6.Dynamic Binding 7.Message Passing.

1. Objects: Objects are the basic run-time entities in an object-oriented system. They
may represent a person, a place, a bank account, a table of data or any item that the
program has to handle. Object = data + method.

2. Classes: A class is a collection of objects of similar type. For example, mango, apple
and orange are members of the class fruit.

Classes are user-defined data types and behave like the built-in types of a
programming language.

3. Data Abstraction and Encapsulation :

The wrapping up of data and functions into a single unit (called class) is known as
encapsulation. With Encapsulation, The data is not accessible to the outside world.
Only those functions which are wrapped in the class can access it.

Abstraction refers to the act of representing essential features without including the
background details or explanations.
4. Inheritance: In OOP, the concept of inheritance provides the idea of reusability.
Inheritance is the process defining a new class (sub) from Existing class (super).

It supports the concept of hierarchical classification. For example, the bird 'duck’,
‘cuckoo’ and ‘ostrich’ are part of the class ‘bird'.

5. Polymorphism:

Polymorphism, a Greek term, means the ability to


take more than one form.
An operation may exhibit different behaviours in different instances. The behaviour
depends upon the types of data used in the operation.
For example, consider an object shape. A shape may have many forms such as Line,
Triangle, Rectangle, and Circle...etc.

6. Dynamic Binding:
Binding refers to the linking of a procedure call to the code to be executed in response
to the call. Dynamic binding (also known as late binding) means that the code
associated with a given procedure call is not known until the time of the call at run-
time. It is associated with polymorphism and inheritance.

7. Message Passing: Objects communicate with one another by sending and receiving
information.

The concept of message passing makes it easier to talk about building systems that
directly model or simulate their real-world counterparts.
A message for an object is a request for execution of a procedure, and therefore will
invoke a function (procedure).

→ History of CPP:
The C programming language was devised in the early 1970s by Dennis M. Ritchie an
employee from Bell Labs (AT&T).
Many other programming languages are derived from the C language.
The languages Objective-C and C++ for instance are derived from the C language.
Both languages add the “object oriented” element to the language C. One of the most
recent languages, that used much of the C language, is Java.
The programming language C++ (originally named “C with Classes”) was devised by
Bjarne Stroustrup also an employee from Bell Labs (AT&T). Stroustrup started working
on C with Classes in 1979.

The idea of creating a new language originated from a wish, to do things that were not
possible with other languages. He had experience with the language Simula and BCPL.
Simula, short for "simulation language," was the first programming language in the
late 1960s.
So he chose to enhance the C language with Simula-like features, because the C
language was fast and portable. Stroustrup did not only use features from Simula but
also borrowed features from the languages Ada, CLU, ALGOL 68 and ML.
In 1983, the name of the language was changed from C with Classes to C++.
(The ++ indicates increment as in C language ).
The first commercial release of the C++ language was in October of 1985.
In 1989, version 2.0 was released of the C++ language.
In 1990, “The Annotated C++ Reference Manual” was published. This work became the
basis for the future standard.
In 1998, a joint ANSI-ISO committee standardized the C++ language.

A simple C+ + program:
// Simple C++ program to display "Hello World"
#include<iostream>
using namespace std;
int main()
{
cout<<"Hello World";
return 0;
}
Output:

Let us now understand every line and the terminologies of the above
program:

1. // Simple C++ program to display “Hello World” :

This line is a comment line. A comment is used to display additional


information about the program.

Any line beginning with ‘//’ without quotes OR in between /*…*/ in


C++ is comment.

2. #include<iostream> :

In C++, The #include directive tells the compiler to include a file


and #include<iostream> . It tells the compiler to include the standard
iostream file which contains declarations of all the standard
input/output library functions.

3. using namespace std:


This is used to import the entirety of the std namespace into the
current namespace of the program.
A namespace is a container for all C++library functions.

4. int main():

Execution of every C++ program begins with the main() function, no


matter where the function is located in the program. So, every C++
program must have a main() function.

5. { and }:

Everything between these two comprises the body of the main


function.

6. cout<<“Hello World”;:

This line tells the compiler to display the message “Hello World” on
the screen.

The std::cout is used to identify the standard character output device


which is usually the desktop screen.

7. return 0; :

This statement is used to return a value from a function.

8. Indentation:

As you can see the cout and the return statement have been indented
or moved to the right side. This is done to make the code more
readable.
Explain the basic structure of C++:
→Basic Structure of a C++ program:
The general structure of C++ program can be shown in following diagram.

➢ In C++ program, first section is the include section


➢ It contains pre-processor statements to include various header (library) files.
➢ After the include section there is class declaration section.
➢ In class declaration we are defining class, its member variable and declaration for the
member function.
➢ Class member function definition section contains the definition of various class member
functions.
➢ At last there is a main function, which starts the execution of program and create the
object of class.
➢ Generally in C++ program class declaration, class member function definition and main
program is written in three separate files.
➢ Class declaration file and class member function definition file is included into the main
program to link all of them.
➢ This structure is known as the client-server architecture.
➢ In client-server architecture we have client requests for service to server and server
provides service to client.
➢ One client can get service from more than one server and similarly one server can
provides the service to multiple clients.
➢ Same fundamental is used at here. Class is act as server and program acts as client.
➢ Main program (Client) can use more than one class
(Server) similarly one class (server) can be used for
more than one program (client).

You might also like