Structured programming:
Structured programming is a programming paradigm aimed at improving the
clarity, quality, and development time of a computer program by making
extensive use of the structured control flow constructs of selection (if/then/else)
and repetition (while and for), block structures, and subroutines.
One of the most important concepts of programming is the ability to control a
program so that different lines of code are executed or that some lines of code are
executed many times. The mechanisms that allow us to control the flow of
execution are called control structures. Flowcharting is a method of
documenting (charting) the flow (or paths) that a program would execute. There
are three main categories of control structures:
Sequence – Very boring. Simply do one instruction then the next and the next.
Just do them in a given sequence or in the order listed. Most lines of code are this.
Selection – This is where you select or choose between two or more flows. The
choice is decided by asking some sort of question. The answer determines the
path (or which lines of code) will be executed.
Iteration – Also known as repetition, it allows some code (one to many lines) to
be executed (or repeated) several times. The code might not be executed at all
(repeat it zero times), executed a fixed number of times or executed indefinitely
until some condition has been met. Also known as looping because the
flowcharting shows the flow looping back to repeat the task.
Structured programming states how the program shall be coded.
It uses three main concepts.
1. Top-down Analysis
2. Modular Programming
3. Structured Coding
Objectives of structured programming
The primary objectives of structured programming are:
1. It encourages top-down implementation, which improves both readability
and maintainability of code.
2. It promotes code reuse, since even internal modules can be extracted and
made independent, residents in libraries, described in directories and
referenced by many other applications.
3. It's widely agreed that development time and code quality are improved
through structured programming.
The structured approach uses a top-down method of problem solving. You
start with a big problem (sometimes a very big problem) and break it down
into smaller and smaller problems. This process is referred to as problem
decomposition and it is a classic ‘divide and conquer’ technique for solving
large, complex problems.
Advantages of Structured Programming Approach:
1. Easier to read and understand
2. User Friendly
3. Easier to Maintain
4. Mainly problem based instead of being machine based
5. Development is easier as it requires less effort and time
6. Easier to Debug
7. Machine-Independent, mostly.
A program is a set of i n t e r - r e l a t e d instructions/statements given to a
computer to perform a specific operations. Computer is a computational device which
is used to process the data under the control of a computer program. While executing
the program, raw data is processed into a desired output format.
We have different languages like C, C++, C#, Java, python, etc to communicate with the
computers. The computer only understands binary language (the language of 0’s and
1’s) also called machine understandable language or low- level language but the
programs we are going to write are in a high level language which is almost similar to
human language.
The piece of code given below performs a basic task of printing “Welcome to C
Programming” on the console screen. We must know that keyboard; scanner, mouse,
microphone, etc are various examples of input devices and monitor (console screen),
printer, speaker, etc are the examples of output devices.
Example Program:
/* First Program using C language */
#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
printf(“\n Welcome to C Programming”);
getch( );
}
The main( ) is a standard function that we will always
include in any program
Note that the execution of the program starts from the main() function.
The clrscr( ) function is used to see only the current output
on the screen by clearing the cache memory that is
temporary buffer
while the printf ( ) function helps us to display the desired
output on the screen.
getch( ) is a function that accepts any character input from the
keyboard.
Basics of a Computer Program:
Computer Programming is a set of inter related instructions that helps the developer
to perform certain tasks that return the desired output for the valid inputs. A
computer is a machine that processes information and this information can be any
data that is provided by the user through devices such as keyboards, mouse,
scanners, digital cameras, joysticks, and microphones.
These devices are called Input Devices and the information provided is called
input. The computer requires storage to store this information and the storage is
called Memory. Operations done on this information (input data) is called
Processing. The Processing of input is done in the Central Processing Unit which is
popularly known as CPU.
The designing of a new program:
1. Find out what the problem is.
2. Find out who the stakeholders are.
3. Think about what resources and skills you have available.
4. Research which interventions are effective.
5. Choose your goal and how to measure it.
6. Identify which activities are likely to lead to the goal.
7. Create the documentation.
8. Be flexible.