0% found this document useful (0 votes)
60 views

Programming Note - 101331

A computer program is a set of instructions that a computer can execute to perform a task. Programs are usually written in programming languages by programmers and compiled into machine-readable code. An algorithm is a step-by-step procedure to solve a problem, and good programs should have characteristics like portability, readability, efficiency, and flexibility. Writing algorithms involves defining unambiguous steps, inputs, outputs, and ensuring they terminate after a finite number of steps. Algorithms can be expressed in various ways including natural language, flowcharts, and pseudocode.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Programming Note - 101331

A computer program is a set of instructions that a computer can execute to perform a task. Programs are usually written in programming languages by programmers and compiled into machine-readable code. An algorithm is a step-by-step procedure to solve a problem, and good programs should have characteristics like portability, readability, efficiency, and flexibility. Writing algorithms involves defining unambiguous steps, inputs, outputs, and ensuring they terminate after a finite number of steps. Algorithms can be expressed in various ways including natural language, flowcharts, and pseudocode.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

INTRODUCTION TO PROGRAMMING

Computer Program

A computer program is a collection of instructions that performs a specific task when executed by a
computer. A computer requires programs to function, and typically executes the program's instructions in
a central processing unit.

A computer program is usually written by a computer programmer in a programming language. From


the program in its human-readable form or source code, a compiler can derive machine code—a form
consisting of instructions that the computer can directly execute. Alternatively, a computer program may
be executed with the aid of an interpreter.

A part of a computer program that performs a well-defined task is known as an algorithm. A collection of
computer programs, libraries and related data are referred to as software. Computer programs may be
categorized along functional lines, such as application software or system software.

Programming is the process of taking an algorithm and encoding it into a notation, a programming
language, so that it can be executed by a computer. Although many programming languages and many
different types of computers exist, the important first step is the need to have the solution. Without an
algorithm, there can be no program.

Algorithm is the step by step procedures of solving problems. Algorithms describe the solution to a
problem in terms of the data needed to represent the problem instance and the set of steps necessary to
produce the intended result.

A good computer program should have the following characteristics:

 Portability: Portability refers to the ability of an application to run on different platforms


(operating systems) with or without minimal changes. Due to rapid development in the hardware
and the software, nowadays platform change is a common phenomenon. Hence, if a program is
developed for a particular platform, then the life span of the program is severely affected.
 Readability: The program should be written in such a way that it makes other programmers or
users to follow the logic of the program without much effort. If a program is written structurally, it
helps the programmers to understand their own program in a better way. Even if some

1
computational efficiency needs to be sacrificed for better readability, it is advisable to use a more
user-friendly approach, unless the processing of an application is of utmost importance.
 Efficiency: Every program requires certain processing time and memory to process the
instructions and data. As the processing power and memory are the most precious resources of a
computer, a program should be laid out in such a manner that it utilizes the least amount of
memory and processing time.
 Structural: To develop a program, the task must be broken down into a number of subtasks.
These subtasks are developed independently, and each subtask is able to perform the assigned job
without the help of any other subtask. If a program is developed structurally, it becomes more
readable, and the testing and documentation process also gets easier.
 Flexibility: A program should be flexible enough to handle most of the changes without having to
rewrite the entire program. Most of the programs are developed for a certain period and they
require modifications from time to time. For example, in case of payroll management, as the time
progresses, some employees may leave the company while some others may join. Hence, the
payroll application should be flexible enough to incorporate all the changes without having to
reconstruct the entire application.
 Generality: Apart from flexibility, the program should also be general. Generality means that if a
program is developed for a particular task, then it should also be used for all similar tasks of the
same domain. For example, if a program is developed for a particular organization, then it should
suit all the other similar organizations.
 Documentation: Documentation is one of the most important components of an application
development. Even if a program is developed following the best programming practices, it will be
rendered useless if the end user is not able to fully utilize the functionality of the application. A
well-documented application is also useful for other programmers because even in the absence of
the author, they can understand it.
 Simplicity: A good programming language must be simple and easy to learn and use. It should
provide a programmer with a clear, simple and unified set of concepts, which can be easily
grasped. The overall simplicity of a programming language strongly affects the readability of the
programs written in that language, and programs, which are easier to read and understand, are also
easier to maintain. It is also easy to develop and implement a compiler or an interpreter for a
programming language, which is simple. However, the power needed for the language should not
be sacrificed for simplicity.

2
 Naturalness:- A good language should be natural for the application area, for which it has been
designed. That is, it should provide appropriate operators, data structures, control structures, and a
natural syntax to facilitate the users to code their problem easily and efficiently.

 Abstraction:- Abstraction means the ability to define and then use complicated structures or
operations in ways that allow many of the details to be ignored. The degree of abstraction allowed
by a programming language directly effects its writ ability. Object oriented language support high
degree of abstraction. Hence, writing programs in object oriented language is much easier. Object
oriented language also support re usability of program segments due to this features.

 Compactness:- In a good programming language, programmers should be able to express


intended operations concisely. A verbose language is generally not liked by programmers, because
they need to write too much.

 Locality:- A good programming language should be such that while writing a programmer
concentrate almost solely on the part of the program around the statement currently being worked
with.

Algorithm is a step by step procedure, which defines a set of instructions to be executed in certain order
to get the desired output.

Algorithms are generally created independent of underlying languages.

Note:
An algorithm can be implemented in more than one programming language.

From data structure point of view, following are some important categories of algorithms −

 Search − Algorithm to search an item in a data-structure.

 Sort − Algorithm to sort items in certain order

 Insert − Algorithm to insert item in a data-structure

 Update − Algorithm to update an existing item in a data-structure

 Delete − Algorithm to delete an existing item from a data-structure

3
Characteristic Features of an Algorithm

Not all procedures can be called an algorithm. An algorithm should have the below mentioned
characteristics −

 Unambiguous − Algorithm should be clear and unambiguous. Each of its steps (or phases), and their
input/outputs should be clear and must lead to only one meaning.

 Input − An algorithm should have 0 or more well defined inputs.

 Output − An algorithm should have 1 or more well defined outputs, and should match the desired
output.

 Finiteness − Algorithms must terminate after a finite number of steps.

 Feasibility − Should be feasible with the available resources.

 Independent − An algorithm should have step-by-step directions which should be independent of


any programming code.

How to write an algorithm

There are no well-defined standards for writing algorithms. Rather, it is problem and resource dependent.
Algorithms are never written to support a particular programming code.

As we know that all programming languages share basic code constructs like loops (do, for, while), flow-
control (if-else) etc. These common constructs can be used to write an algorithm.

We write algorithms in step by step manner, but it is not always the case. Algorithm writing is a process
and is executed after the problem domain is well-defined. That is, we should know the problem domain,
for which we are designing a solution.

Example:

Sum of Two Numbers:

step 1 − START ADD

step 2 − get values of a, b

step 3 − c ← a + b

4
step 4 − display c

step 5 − STOP

An algorithm may be expressed in a number of ways, including:


natural language: usually verbose and ambiguous
flow charts: avoid most (if not all) issues of ambiguity; difficult to modify with or without specialized
tools; largely standardized

pseudo-code: also avoids most issues of ambiguity; vaguely resembles common elements of programming
languages; no particular agreement on syntax programming language: tend to require expressing low-
level details that are not necessary for a high-level understanding

Data Flow Diagram


Data Flow Diagram (DFD) provides a visual representation of the flow of information (i.e. data) within a
system. By creating a Data Flow Diagram, you can tell the information provided by and delivered to
someone who takes part in system processes, the information needed in order to complete the processes
and the information needed to be stored and accessed. Data Flow Diagram is widely-used in software
engineering. While it's commonly used in modeling information systems. Example of Level 1 DFD:

5
Decision Table
Decision tables are used to model complicated programming logic. They can make it easy to see that all
possible combinations of conditions have been considered; when conditions are missed, it is easy to see
this. The tables are composed of 4 parts: conditions, actions, condition alternatives (each column is a
rule), and actions for the rules.
The process used to create a decision table is the following:
1. Identify conditions and their alternative values.
 There are 3 conditions: gender, city dweller, and age group. Put these into table as 3 rows
in upper left side.
 Gender’s alternative values are: F and M.
 City dweller’s alternative values are: Y and N
 Age group’s alternative values are: A, B, and C
2. Compute max. number of rules.
 Determine the product of number of alternative values for each condition.
 2 x 2 x 3 = 12.
 Fill table on upper right side with one column for each unique combination of these
alternative values. Label each column using increasing numbers 1-12 corresponding to the
12 rules. For example, the first column (rule 1) corresponds to F, Y, and A. Rule 2
corresponds to M, Y, and A. Rule 3 corresponds to F, N, and A. Rule 4 corresponds to M,
N, and A. Rule 5 corresponds to F, Y, and B. Rule 6 corresponds to M, Y, and B and so
on.
3. Identify possible actions
 Market product W, X, Y, or Z. Put these into table as 4 rows in lower left side.
4. Define each of the actions to take given each rule.
 For example, for rule 1 where it is F, Y, and A; we see from the above example scenario
that products W, X, and Z will appeal. Therefore, we put an ‘X’ into the table’s

6
intersection of column 1 and the rows that correspond to the actions: market product W,
market product X, and market product Z.
1 2 3 4 5 6 7 8 9 10 11 12
Gender F M F M F M F M F M F M
City Y Y N N Y Y N N Y Y N N
Age A A A A B B B B C C C C
MarketW X X X
MarketX X X
MarketY X
MarketZ X X X X X X X X X X

5. Verify that the actions given to each rule are correct.


6. Simplify the table.
 Determine if there are rules (columns) that represent impossible situations. If so, remove
those columns. There are no impossible situations in this example.
 Determine if there are rules (columns) that have the same actions. If so, determine if these
are rules that are identical except for one condition and for that one condition, all possible
values of this condition are present in the rules in these columns. In the example scenario,
columns 2, 4, 6, 7, 10, and 12 have the same action. Of these columns: 2, 6, and 10 are
identical except for one condition: age group. The gender is M and they are city dwellers.
The age group is A for rule 2, B for rule 6, and C for rule 10. Therefore, all possible values
of condition ‘age group’ are present. For rules 2, 6, and 10; the age group is a “don’t care”.
These 3 columns can be collapsed into one column and a hyphen is put into the age group
location to signify that we don’t care what the value of the age group is, we will treat all
male city dwellers the same: market product Z.
1 2 3 4 5 6 7 8 9 10
Gender F M F M F M F M F M
City Y Y N N Y N N Y N N
Age A A A B B B C C C
MarketW X X X
MarketX X X
MarketY X
MarketZ X X X X X X X X

7
PROGRAMMING LANGUAGE

A programming language is a formal computer language designed to communicate instructions to a


machine, particularly a computer. Programming languages can be used to create programs to control the
behavior of a machine or to express algorithms.

The description of a programming language is usually split into the two components of syntax (form) and
semantics (meaning).

Machine Language

Machine code or machine language is a set of instructions executed directly by a computer's central
processing unit (CPU). Each instruction performs a very specific task, such as a load, a jump, or an ALU
operation on a unit of data in a CPU register or memory. Every program directly executed by a CPU is
made up of a series of such instructions.

Machine code is the only language a computer can process directly without a previous transformation.
Currently, programmers almost never write programs directly in machine code, because it requires
attention to numerous details that a high-level language handles automatically. Furthermore, it requires
memorizing or looking up numerical codes for every instruction, and is extremely difficult to modify.

True machine code is a stream of raw, usually binary, data. A programmer coding in "machine code"
normally codes instructions and data in a more readable form such as decimal, octal, or hexadecimal
which is translated to internal format by a program called a loader or toggled into the computer's memory
from a front panel.

Low Level Language

A low-level programming language is a programming language that provides little or no abstraction from
a computer's instruction set architecture—commands or functions in the language map closely to
processor instructions. Generally this refers to either machine code or assembly language. The word "low"
refers to the small or nonexistent amount of abstraction between the language and machine language;
because of this, low-level languages are sometimes described as being "close to the hardware". Programs
written in low-level languages tend to be relatively non-portable, mainly because of the close relationship
between the language and the hardware architecture.

Low-level languages can convert to machine code without a compiler or interpreter— second-generation
programming languages use a simpler processor called an assembler— and the resulting code runs
directly on the processor. A program written in a low-level language can be made to run very quickly,
with a small memory footprint. An equivalent program in a high-level language can be less efficient and
use more memory. Low-level languages are simple, but considered difficult to use, due to numerous
technical details that the programmer must remember. By comparison, a high-level programming
language isolates execution semantics of a computer architecture from the specification of the program,
which simplifies development.

8
High Level Language

A high-level language is a programming language such as C, FORTRAN, Pascal, JAVA, Python… that
enables a programmer to write programs that are more or less independent of a particular type of
computer. Such languages are considered high-level because they are closer to human languages and
further from machine languages. In contrast, assembly languages are considered low-level because they
are very close to machine languages.

The main advantage of high-level languages over low-level languages is that they are easier to read, write,
and maintain. Ultimately, programs written in a high-level language must be translated into machine
language by a compiler or interpreter.

The first high-level programming languages were designed in the 1950s. Now there are dozens of
different languages, including Ada, Algol, BASIC, COBOL, C, C++, FORTRAN, LISP, Pascal, and
Prolog.

OBJECT ORIENTED PROGRAMMING (OOP)

Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects",


which may contain data, in the form of fields, often known as attributes; and code, in the form of
procedures, often known as methods. A feature of objects is that an object's procedures can access and
often modify the data fields of the object with which they are associated (objects have a notion of "this" or
"self"). In OOP, computer programs are designed by making them out of objects that interact with one
another. There is significant diversity of OOP languages, but the most popular ones are class-based,
meaning that objects are instances of classes, which typically also determine their type.

Many of the most widely used programming languages (such as C++, Delphi, Java, Python etc.) are multi-
paradigm programming languages that support object-oriented programming to a greater or lesser degree,
typically in combination with imperative, procedural programming. Significant object-oriented languages
include Java, C++, C#, Python, PHP, Ruby, Perl, Object Pascal, Objective-C, Dart, Swift, Scala, Common
Lisp, and Smalltalk.

Object-oriented Programming uses objects, but not all of the associated techniques and structures are
supported directly in languages that claim to support OOP. The features listed below are, however,
common among languages considered strongly class- and object-oriented (or multi-paradigm with OOP
support), with notable exceptions mentioned.

OOP TERMINOLOGIES

Objects and classes

Languages that support object-oriented programming typically use inheritance for code reuse and
extensibility in the form of either classes or prototypes. Those that use classes support two main concepts:

9
Classes – the definitions for the data format and available procedures for a given type or class of object;
may also contain data and procedures (known as class methods) themselves, i.e. classes contains the data
members and member functions

Objects – instances of classes

Objects sometimes correspond to things found in the real world. For example, a graphics program may
have objects such as "circle", "square", "menu". An online shopping system might have objects such as
"shopping cart", "customer", and "product". Sometimes objects represent more abstract entities, like an
object that represents an open file, or an object that provides the service of translating measurements from
U.S. customary to metric.

Encapsulation

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.Data encapsulation is a mechanism of bundling the data, and
the functions that use them.

Data abstraction is a mechanism of exposing only the interfaces and hiding the implementation details
from the user.

Composition, inheritance, and delegation


Objects can contain other objects in their instance variables; this is known as object composition. For
example, an object in the Employee class might contain (point to) an object in the Address class, in
addition to its own instance variables like "first_name" and "position". Object composition is used to
represent "has-a" relationships: every employee has an address, so every Employee object has a place to
store an Address object.

Languages that support classes almost always support inheritance. This allows classes to be arranged in a
hierarchy that represents "is-a-type-of" relationships. For example, class Employee might inherit from
class Person. All the data and methods available to the parent class also appear in the child class with the
same names. For example, class Person might define variables "first_name" and "last_name" with method
"make_full_name()". These will also be available in class Employee, which might add the variables
"position" and "salary". This technique allows easy re-use of the same procedures and data definitions, in
addition to potentially mirroring real-world relationships in an intuitive way. Rather than utilizing
database tables and programming subroutines, the developer utilizes objects the user may be more
familiar with: objects from their application domain.

Delegation is another language feature that can be used as an alternative to inheritance. It refers generally
to one entity passing something to another entity, and narrowly to various specific forms of relationships.

Polymorphism
The ability to appear in many forms. In object-oriented programming, polymorphism refers to a
programming language's ability to process objects differently depending on their data type or class. More
specifically, it is the ability to redefine methods for derived classes. For example, given a base class
shape, polymorphism enables the programmer to define different area methods for any number of derived

10
classes, such as circles, rectangles and triangles. No matter what shape an object is, applying the area
method to it will return the correct results.

Hierarchical

Fruit

Apple Orange lemon Grape

References/Further Reading
https://classes.soe.ucsc.edu/cmps115/Spring05/supplements/DecisionTables.htm
https://en.wikipedia.org/wiki/Computer_program
https://www.lynda.com/Programming-Foundations...programming/.../90430-4.html
whatis.techtarget.com › Topics › AppDev › Programming
https://www.smartdraw.com/data-flow-diagram/
searchsoftwarequality.techtarget.com › Mobile Testing › Programming

11

You might also like