Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Introduction to Programming: Algorithms, Flowcharts, and Programming Methodologies, Study notes of Programming Languages

This study material provides a comprehensive introduction to programming, covering fundamental concepts such as algorithms, flowcharts, and programming methodologies. It explores different types of programming languages, including machine level, assembly level, and high-level languages. The document also delves into object-oriented programming concepts like abstraction, encapsulation, inheritance, and polymorphism, comparing them to procedural programming. It further explains static and dynamic binding, classes, and objects in programming.

Typology: Study notes

2023/2024

Available from 12/11/2024

myraa
myraa 🇮🇳

6 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Page 1 of 10
The Bhopal School of Social Sciences
(Affiliated to Barkatullah University, Bhopal)
E-Content (Study Material)
for
UNIT I
Part-1
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Introduction to Programming: Algorithms, Flowcharts, and Programming Methodologies and more Study notes Programming Languages in PDF only on Docsity!

The Bhopal School of Social Sciences

(Affiliated to Barkatullah University, Bhopal)

E-Content (Study Material)

for

UNIT – I

Part- 1

1. Introduction to Programming

Programming is writing computer code to create a program, to solve a problem. Programs are created to implement algorithms. Algorithms can be represented as pseudocode or a flowchart, and programming is the translation of these into a computer program. To tell a computer to do something, a program must be written to tell it exactly what to do and how to do it. If an algorithm has been designed, the computer program will follow this algorithm, step-by- step, which will tell the computer exactly what it should do.

What is a programming language?

A programming language is an artificial language that a computer understands. The language is made up of series of statements that fit together to form instructions. These instructions tell a computer what to do.

2. Program Concept

A program is a set of instructions that a computer uses to perform a specific function. To use an analogy, a program is like a computer’s recipe. It contains a list of ingredients (called variables, which can represent numeric data, text, or images) and a list of directions (called statements) that tell the computer how to execute a specific task.

3. Characteristics of Programming

  • A programming language must be simple, easy to learn and use, have good readability, and be human recognizable.
  • Abstraction is a must-have characteristics for a programming language in which the ability to define the complex structure and then its degree of usability comes.
  • A portable programming language is always preferred.
  • Programming language’s efficiency must be high so that it can be easily converted into a machine code and executed consumes little space in memory.
  • A programming language should be well structured and documented so that it is suitable for application development.
  • Necessary tools for the development, debugging, testing, maintenance of a program must be provided by a programming language.
  • A programming language should provide a single environment known as Integrated Development Environment(IDE).
  • A programming language must be consistent in terms of syntax and semantics.

Sequential Algorithms:

  • These algorithms proceed step by step and reach the final statement in a sequential form. Example 1: Write an algorithm to find the area of a Square of side s units. Inputs to the algorithm: Side s of the Square. Expected output: Area of the Square Algorithm: Step1: Start Step2: Read the Side s of the Square Step3: Set Area as ss // calculation of area Step4: Print Area Step5: End Example 2: Write an algorithm to find the area of a Rectangle of length l and breadth b units. Inputs to the algorithm: Length l and Breadth b of the Rectangle. Expected output: Area of the Rectangle Algorithm: Step1: Start Step2: Read input the Length l and Breadth b of the Rectangle Step3: Set Area as lb // calculation of area Step4: Print Area Step5: End Example 3: Write an algorithm to read two numbers and find their product. Inputs to the algorithm: First number a. Second number b. Expected output: Sum of the two numbers a and b. Algorithm : Step1: Start Step2: Read the first number a. Step3: Read the second number b. Step4: Set Product as ab // calculation of product Step5: Print Product Step6: End Example 4: Write an algorithm to convert metres into centimetres Inputs to the algorithm: Metres m Expected output: Centimetres cm Algorithm: Step1: Start Step 2: Read m Step 3: Set cm to m //Conversion of metres to centimetres Step 4: Print cm Step5: End Decision Control Algorithms: These algorithms involve a branch which is a decision based on some condition. If the condition is true, one of the two branches is executed or else the other alternative is taken. This is usually represented by the ‘if-then’ construct in pseudo-codes and programs. This structure is also known as the selection structure. Example 5: Write algorithm to find the greater number among two numbers. Inputs to the algorithm: Two numbers a and b Expected output: Greater number c Algorithm: Step1: Start Step2: Read two numbers a and b Step3: If a > b then c=a else c=b

Step4: Print c Step5: End

6. Design of Flowcharts

A flowchart is a diagrammatic representation which visually represents the flow of control through processing systems. By seeing a flowchart one can know the operations performed and the sequence of these operations in a system. A flow chart can be used for representing an algorithm diagrammatically. A flowchart will describe the operations and their sequence required to solve a given problem. A flowchart can be viewed as a blueprint of a design for solving a problem. When a problem is to be solved using a computer it is a good practice to draw a flowchart before writing a computer program. A flowchart is drawn according to defined set of rules which are as follows:

  1. All boxes of the flowchart are connected with flow lines indicated by arrows.
  2. Flowchart symbols have a single entry point on the top of the symbol and exit point for all flowchart symbols is on the bottom of the symbol except for the Decision box.
  3. The Decision box can have two exit points which can be on both the sides or the bottom and one side.
  4. A flowchart will usually flow from top to bottom. An upward directed flow line can be used as long as it does not exceed 3 symbols.
  5. Connectors are used to connect breaks in the flowchart. Some examples where connectors could be used are:
    • From one page to another page.
    • From the bottom of the page to the top of the same page.
    • An upward flow of more than 3 symbols
  6. Subroutines and Interrupt programs have their own independent Flowcharts indicating their logic and control flow.
  7. All flow charts start with a Terminal or Predefined Process box (for interrupt programs or subroutines).
  8. All flowcharts end with a terminator. Flowcharting uses symbols to represent the type of operations and/or processes being performed. The standardised symbols provide a common method for people to visualise and draw the flowchart. o Symbols of flowchart Symbol Name Use Terminator Used to start and end the flowchart Input/Output box Used for any Input / Output (I/O) operation Process box Used for representing any type of operation inside the Processor or Memory Decision box Used to make a decision that can be in the format of Yes/No or True/False Predefined Process box Used to call a subroutine or an interrupt program Flow lines Used to indicate flow of control

Example 6: Draw a flowchart to find the largest value of any three numbers.

7. Types of Programming Methodologies

Machine Level Language: It is a programming language that uses 0s and 1s. It is directly executable by hardware and it requires high precision programming. It is very difficult to debug. Assembly Level Language: It is a programming language that uses mnemonics. It is comparatively easy to understand and debug. The code is machine dependent (non-portable) and it is not directly executable on the hardware. The code requires a translator called assembler that can translate assembly level code to machine level code. High Level Language: It is an English like general purpose programming language that is hardware independent. It is not directly executable on the hardware. The code requires a translator called compiler or interpreter that can translate high level code to machine level code. High level languages can be classified as:

  • Procedure Oriented
  • Object Oriented

8. Principles of OOP

i) Abstraction Abstraction is a process of defining the essential concepts while ignoring the inessential details. The various types of Abstraction are: ■ Data Abstraction Programming languages define constructs to simplify the way information is presented to the programmer. ■ Functional Abstraction Programming languages have constructs that ‘gift wrap’ very complex and low level instructions into instructions that are much more readable. ■ Object Abstraction OOP languages take the concept even further and abstract programming constructs as objects. ii) Encapsulation All C++ programs are composed of the following two fundamental elements − ■ Program statements (code) − This is the part of a program that performs actions and they are called functions. ■ Program data − The data is the information of the program which gets affected by the program functions. Encapsulation is an Object Oriented Programming concept that binds together the data and functions that manipulate the data, and that keeps both safe from outside interference and misuse. Data encapsulation led to the important OOP concept of data hiding. iii) Inheritance Inheritance is based on the concept of code reusability. It saves time of program development. The mechanism of deriving a new derived class (subclass) from an old base class is known as inheritance. In other words the capability of a class to derive properties and characteristics from another class is called Inheritance. Inheritance is one of the most important feature 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. Types of Inheritance:

BASIS FOR

COMPARISON

STATIC BINDING DYNAMIC BINDING

Event Occurrence Events that occur at compile time are "Static Binding". Events that occur at run time are "Dynamic Binding". Information All information needed to call a function is known at compile time. All information need to call a function come to know at run time. Advantage Efficiency. Flexibility. Time Fast execution Slow execution Alternate name Early Binding Late Binding Example Overloaded function call, overloaded operators. Virtual function in C++, overridden methods in Java.

Classes

Classes are similar to structures in C. They have fields corresponding to fields of a structure in C (similar to variables). They also have fields corresponding to functions in C (functions that can be applied to that structure). Some fields are accessible by everyone, some not (data hiding) and some fields shared by the entire class. Class can be viewed as a blueprint for creating instances of the same type called objects. For example: ‘Vehicle’ can be a class and ‘car’, ‘bus’, ‘bike’ can be objects of the ‘Vehicle’ class.

Objects

A class in C++ is a collection of objects. Variables created of a particular class are instances of that class known as objects. Variables have values for fields of the class. Class example: Student has name, id, gpa, etc. fields that store values has functions, changeGPA, addCredits, that can be applied to instances of that class Object examples: John Doe, Jane Doe each with their own values for the fields of the class

11. Advantages of OOP

  • Easy Troubleshooting
  • Code Reusability
  • Code Flexibility
  • Data Security
  • Lesser development time
  • Higher Productivity

12. Applications of OOP

  • Client-Server Systems
  • Object-Oriented Databases
  • Real-Time System Design
  • Simulation and Modelling System
  • Hypertext and Hypermedia
  • Neural Networking and Parallel Programming
  • Office Automation Systems
  • AI Expert Systems

13. Object Oriented Languages

High-level computer programming language that implements objects and their associated procedures within the programming context to create software programs are known as Object Oriented Languages. They use an object-oriented programming technique that binds related data and functions into an object and encourages reuse of these objects within the same and other programs. These languages support all the features of OOPs such as abstraction, encapsulation, inheritance and polymorphism. They also support built-in objects. C#, Java, VB. Net are the examples of Object Oriented languages.