Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

ALIGARH MUSLIM UNIVERSITY

Department of Computer Science


Course: MCA CSM-1101: Problem Solving Using C++
Academic Session 2020-2021
Handout-1
Teacher: Dr. Rafiqul Zaman Khan, Professor
Homepage: https://www.drrafiq.org
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Objectives:
 To learn about problem solving methods.
 To learn about different programming paradigms
 To learn about need of object oriented programming
 To learn about procedural languages.
 To learn about object oriented approach
 To learn about characteristics of object oriented languages
 To learn about difference between C , C++ and Java.

Problem Solving Methods:

There three methods for solving any problem which are explained below:

a). Analytic Method:


Used in mathematics and physics, algebra. This is non computer related. It is very old
method for problem solving.
b). Algorithmic method:
Used by computer programmers.
c). Software Engineering:
Used for design and maintenance of large scale (bigger and complex) software which
require team work.

Each of the above methods has four basic components:

1) Problem : Specification of the problem to be solved


2) Reasoning : Comprehension of the problem (Analysis) .In this we define
inputs, output and process.
3) Solution : Specification of the solution (Design)
4) Test : Checking that the solution is correct

1). The analytic Approach:


It is the oldest method; it is what we use to solve algebra, chemistry and physics
…problems.
Example 1:
Problem : Find a formula to calculate the mean (the average) of five
numbers
Reasoning : calculating the sum of five numbers and then dividing by 5

1
Solution : sum=a +b + c +d +e
Average=sum/5
Test : (5+7+11+12+15)/5 =10

2). Algorithmic Method:


It is a description of steps to solve a problem that is unambiguous, executable, and
terminating. That is, the description leaves no room for interpretation, the steps can be
carried out in practice, and the result is guaranteed to be obtained after a finite amount of
time. In order to solve a problem by computer, you must know an algorithm for finding
the solution.

What is algorithm?:
Algorithm is a step by step method for solving any problem.

Properties of a good Algorithm:


 The execution of the algorithm must conclude after a finite number of steps.
 The description of the algorithm must be finite.
 Correctness
 Every algorithm must have at least one input and one output statement.
 All instructions in the algorithm must be clear.

What do you mean by programming paradigm?

Paradigm means an approach or a way of reasoning to solve a problem. Various


programming paradigms are discussed below:

Procedural Paradigm:
In procedure – oriented programming more emphasis is given on function not on data.

 In this data moves openly around the system from function to function
 In this large programs are divided into smaller programs known as procedures.
 Languages using this paradigm are called procedural or imperative languages.
FORTRAN, BASIC, Pascal, Ada and C, are all examples of these languages.

Object-oriented Paradigm (OOP):


The object-oriented paradigm treats data and functions that act on it as a single object or data
structure. Thus, OOP is based on data structure rather than the process or subprograms.

 The disadvantages of procedural approach are removed in object oriented approach.


 In this programs are divided into object.
 In this more emphases is given to data rather to function or procedure.
 In this data is hidden can not be accessed by any external function.
 Another important property of objects is inheritance -- an object can be inherited by
other objects, hence can be used by more than one program on a system (reusability of
code).
 The first OOP language, Smalltalk was developed in 1968 and is the model for the
OOP paradigm in use today. Smalltalk is simple and powerful. Its only drawback is
that it is inefficient.

2
 C++ is another object –oriented language that was developed in 1985. C++ is not a
“pure” object-oriented language as is Smalltalk, but it fits the paradigm in that its data
structures are objects. In fact C++ is actually a superset of C.
 Another object-oriented language that is gaining enormous popularity is JAVA. In
JAVA, objects in different computer systems can communicate through the
networking capability provided by the language.

Functional Programming Paradigm:


This approach involves the use of a set of basic functions (called primitives). Problems are
solved by using these basic functions to derive other functions. Some of the primitive
functions may work in parallel, thereby making the process efficient.
Example:

Consider evaluating the function

f(x) =2.3x2-7.4 sin x + cos (3.4x)

The function f(x) is the algebraic sum of three other functions 2.3x2, 7.4 sin x and cos (3.4x).
Each of these is a function of other function. For example 2.3x2 is a function consisting of
the product of the square of x, a function, and the floating- point number 2.3
The following diagram represents this as a black box.

2.3 x2

f(x)
-7.4sin x add

Cos(3.4x)

 In this example, the primitive functions consists of the three floating-point constants
and the variables x.
 A set of primitive functions including arithmetic, logical operations and special
functions is described by these types of languages.
 Examples of functional programming languages are LISP, APL, HASKEL,
scheme etc.
 A principal property of functional languages is the prohibition of assignment
operation.
 They use mathematical-styled functions, conditional expressions and recursion.
 Extensive use of recursion makes looping structures such as while and for loops
unnecessary.

Declarative Languages (or Logic Paradigm):


 This approach involves declaring a set of facts and logical relationships connecting
those facts. Problems are then solved by making use of the facts and the

3
relationships. Declarative languages are concerned more with “what” to do as
opposed to “how” to do it. This mode of reasoning is called logic paradigm.
 The most popular declarative language is PROLOG (PROgramming LOGic). It has
wide appeal in artificial intelligence and expert systems.
 Another well-known declarative language is SNOBOL4 (StriNg Oriented symBOlic
Language), developed in 1960.
 Declarative languages are particularly suitable for database management system. SQL
(Structured Quary Language) is another example of declarative language.

Concept of Object Oriented Programming (OOP) Paradigm:


Paradigm means a very clear and typical example of something so that things become vivid
to us. In procedural approach the data and functions are treated as different things but in OOP
the data and functions are unified to a single entity helping to understand the topic clearly.
“Object oriented programming as an approach which provides a way of modularizing
program where data is very secure from any kind of threat”.
OOP is a new way (natural way) of solving problems with computer introducing various new
ideas like:
1. Objects
2. Classes
3. Data Abstraction
4. Encapsulation
5. Inheritance
6. Polymorphism
7. Dynamic Binding
8. Message Passing
Characteristics of OOPS:
1. Emphasis is on data rather than algorithm
2. Data abstraction is introduced in the place of procedural abstraction
3. Functions which are operated upon the data of an object are tightly bounded with the
data.
4. Data is hidden and not exposed to anybody outside
5. Objects may communicate with each other with the help of functions(message
passing)
6. New data and function can be easily added whenever required(inheritance)
7. Follows bottom-up approach in programme design.

4
Comparison between C, C++ and Java:

Feature C C++ Java


OOP, Generic
Procedural, OOP, Generic
Paradigms Procedural Programming (from Java
Programming
5)
Form of
Executable
Compiled Source Executable Native Code Java bytecode
Native Code
Code
Memory Managed, using a garbage
Manual Manual
management collector
Yes, very commonly used,
Yes, very No pointers; references
Pointers but some form of
commonly used. are used instead.
references available too.
Preprocessor Yes Yes No
String Type Character arrays Character arrays, objects Objects
Complex Data
Structures, unions Structures, unions, classes Classes
Types
Single class inheritance,
Inheritance N/A Multiple class inheritance multiple interface
implementation
Operator
N/A Yes No
Overloading
Yes, with
Automatic Yes, with warnings if loss Not at all if loss could
warnings if loss
coercions could occur occur; msut cast explicitly
could occur
Variadic
Yes Yes No
Parameters
Goto Statement Yes Yes No

Why do we use object oriented programming?


Inheritance provides the idea of reusability of code and each sub class defines only those
features that are unique to it. Object-Oriented Programming has the following advantages:
... OOP makes it easy to maintain and modify existing code as new objects can be created
with small differences to existing ones.

What are the benefits of object oriented programming?


Object Oriented Programming has great advantages over other programming styles:
Code Reuse and Recycling: Objects created for Object Oriented Programs can easily be
reused in other programs. Encapsulation: Once an Object is created, knowledge of its
implementation is not necessary for its use.

You might also like