0% found this document useful (0 votes)
28 views11 pages

Introduction to Structured Programming

This document introduces the basic principles of structured programming in a programming language. It explains that programs should be well organized into defined blocks and follow the principles of the structure theorem, including process boxes, binary decisions, and repetition mechanisms. It also describes the basic structure of a program in C, including functions, variables, and constants.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views11 pages

Introduction to Structured Programming

This document introduces the basic principles of structured programming in a programming language. It explains that programs should be well organized into defined blocks and follow the principles of the structure theorem, including process boxes, binary decisions, and repetition mechanisms. It also describes the basic structure of a program in C, including functions, variables, and constants.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

UNIT 3 INTRODUCTION TO LANGUAGE PROGRAMMING

STRUCTURED.
3.1 INTRODUCTION TO THE PROGRAMMING OF A LANGUAGE
STRUCTURED.
In 1995, Edger W. Dijkstra published the principles of structured programming in his
book 'Notes on Structured Programming', with these notes as the axis, C. Boehm and G.
Jacopini established in 1996 a programming language that would be used as a basis
for most of the development platforms known today,
C language.
The basic concept of structured programming consists of the basic formation of
programming text (programming statements) that when read, can explain the
operation of a program. A sequential program must comply with the following
characteristics:

It should be easy to read and understand by reading the code itself.


It should be easy to debug (locate program errors).
It should be easy to maintain (expand with new specifications or modify the
already existing).
Allow teamwork on the same program.

3.2 BASIC STRUCTURE OF A PROGRAM.


Structural programs should be built in small blocks that are well
defined in terms of their function, to the level of being perfect in brief and concise tasks.
Once the program is perfected, its capability as an atomic module will be tested, that is
to say, the line-by-line verification of statements of the type 'If-Then-Do, while, etc.'
One of the distinctive features of the C language is this modularity, due to the fact that the
programs are made up of functions, where the main function is known as
main function.
Structural programs must be well organized and defined by the following
principles:
Theorem structure.
This is defined by three basic blocks, which are known as:

Process box.
Binary decision.
Repeating mechanism.

Program.
Which states the actions to be taken to satisfy a need and must comply with
the following characteristics:

Top of the block with a unique entry.


Sequential reading from top to bottom
To have an output or result.

All functions contain instructions that are executed when the program does
an explicit call to the corresponding function. The functions contain statements
of the variables and definitions of the constants that are used within them.
The program begins by executing the first instruction of the main function.
which establishes its path or logical origin of execution. For this, in the body of the
The main function includes instructions and/or calls to the rest of the functions defined.
in the program.
For example, the general structure of a program written in C would be as follows
shape:
[Link] files.
They are files that include the declaration (association of a data type) of the
variables, constants, and other functions used in the program.
2. Global statements.
Declarations of variables and constants that can be used by all the
functions of the program.
3. Local declarations.
Variable and constant declarations that can only be used within
a determined function.
4. Type fi (list of parameters).
Type: It is the data type of the result that the function provides.
Fi: It is the name of the function i.
•Parameter list: It is the list of parameters or input variables used by the
function. It constitutes the declaration of one or several variables, which function as
local variables.
5. Instructions.
Instructions or statements that are part of the functions. The dot symbol and
a semicolon (;) at the end of a line identifies it as a statement or instruction
of the C language. To make the program easily intangible, it is advisable to write
each instruction on one line.
6. Main type (parameter list).
Definition of the main function of the program: The development tools
often include standard function libraries or
normalized, so that users do not have to program them.
The result would be as follows:
Hello world in C Language
#include <stdio.h> Header
void main() Main function
{
printf("Hello world"); Instructions
}
3.3 TYPES OF DATA.
There are two types of data to be used during a program, variables and constants. The
Variables are a type of data whose value can change over a
Program, constants are the data types that throughout the program remain.
I integrate its contained value.

The type of value that resides in the variable or constant is a way to represent
information for which a memory space is reserved, in accordance with its
Characteristics. The data that a computer processes is classified into simple and
Structured. The main characteristic of simple data types is that they occupy only
a memory cell. Within this group of data are mainly the
integers, real numbers, and characters. The use of memory depends on the correct
selection of the data type assigned to the variables of a program, because in some
In such cases, it usually does not have a high-capacity data or program memory.
In the C language, the five basic data types are defined:

3.4 IDENTIFIERS.
Identifiers (IDs) are lexical symbols that name entities. The concept is
analogous to "information processing names". Naming the entities makes
It may refer to the same, which is essential for any type of processing.
symbolic.
In programming languages, identifiers are textual elements (also
called symbols) that name entities of the language. Some of the entities that
an identifier can denote variables, constants, data types,
labels, subroutines (procedures and functions), and packages.
In many languages, some sequences have the lexical form of an identifier but
they are known as keywords (or reserved words). It is common that if a
the identifier corresponds to a keyword or reserved word, it can no longer
used to refer to other types of entities such as variables or constants (in some
in a few languages, like PL/1, this distinction is not entirely clear.
Programming languages typically impose restrictions on what characters can be used.
appear in an identifier. For example, in the early versions of C and C++, the
identifiers are restricted to be a sequence of one or more letters
ASCII, numeric digits (which should never appear as the first character) and
underscores. Later versions of these languages, as well as many others
modern languages support almost all Unicode characters in an identifier. A
a common restriction is that the use of whitespace or operators is not allowed
of the language.

In compiled programming languages, identifiers are generally


entities at compile time, that is, at runtime the program
the compiled contains references to memory addresses and offsets more than
textual identifiers (these memory addresses or offsets have been assigned by
the compiler for each identifier.
In interpreted languages, identifiers are often at runtime
execution, sometimes even as first-class objects that can be manipulated and
evaluated freely. In Lisp, these are called symbols.
Compilers and interpreters typically do not assign any semantic meaning to
an identifier based on the current character sequence. However, there are
exceptions. For example:
In Perl, a variable is indicated using a prefix called a sigil, which specifies
aspects of how the variable is interpreted in the expressions.
In Ruby, a variable is automatically considered immutable if its
identifier starts with an uppercase letter.
In Fortran, the first letter of a variable indicates whether it is created by default.
as an integer or as a float.

3.5 STORAGE, ADDRESSING AND REPRESENTATION OF


MEMORY.
Storage

The computer has a certain amount of internal storage called


main memory, RAM memory, or volatile memory. This memory is activated when turned on.
the computer and it deactivates when turned off. For a program to run, it must
load into main memory, as well as the necessary data. Since it is more expensive,
it is a scarce resource where only the data that is immediately needed is stored,
and the others are relegated to external storage devices, where the capacity
the storage capacity is greater, but so is the recovery time. On the other hand, the
the cost of external storage is lower.
Addressing

The main memory of the computer is divided into small units of size
uniform denominated words what they have one address unique.
Each of these words is capable of storing a unit of information (such as,
for example, numerical results), and determines the largest and smallest number
what it can store.
The size of the word depends on the computer, but it is always specified in
multiples of 8 bits. Thus, there are computers with word sizes of 8, 16, 32, and 64
bits. Each word in the main memory has a fixed address that ranges from zero to the
total number of words - 1. Memory addresses are used to identify each
word individually, in such a way that the data contained in it can be accessed. To A
in order to simplify its understanding, memories are considered as a row of
words.

Memory representation

The representation in memory of characters is not particularly complicated, due to


that the codes used, such as ASCII (American Standard Code for Information
(Interchange), they assign positive integer values to them.

In the case of numerical data, it is necessary to consider the distinction between numbers.
negatives and positives, and the difference between floating point numbers and integers. The signs
they are normally managed by the most significant bit of the word (the one located at the
extreme left), and it is called the sign bit. When the sign bit stores a
zero, the number is considered positive; when it stores a one the number is negative.

This is why, if the word size is m bits, there are m-1 bits left to represent.
the magnitude of the stored number. Floating point numbers are handled in
logarithmic format, with a fixed number of bits for the base and another for the mantissa. The
The standard for floating-point numbers is set by IEEE. Due to the logarithmic format,
The calculations made with floating point types are not as accurate as those that are
they are done with integer types.

Secure Digital (SD).

They are based on the Multimedia Card (MMC) format. The cards
marked as HC (High Capacity) operate at high speed and have
very high data transfer rates; some cameras
digitals require this type of cards to be able to record video with
fluency or to capture multiple photographs in rapid succession.
Starmedia.

Also known as (Solid State Floppy Disk Card).


They are durable and their physical appearance is similar to that of a floppy disk, but
with a size approximately that of a postage stamp. Its shape prevents
insert them into their slot in the opposite direction.

Memory Stick.

Digital cards with flash memory designed with the company


Sony. In addition to being suitable for digital cameras of this brand,
Memory Sticks can be used in a wide variety of
digital devices. These cards are used to store images,
music, data, texts and graphics Offer a high speed of
they do not need any device for playback, as
they have a diskette adapter.
Minini SD FLASH MEMORY.

Due to its small size, this card format is used


especially on mobile phones. It combines great capacity of
storage, high data transfer rate, reliability
security and low power consumption. It is also used in
audio players, digital cameras (by means of a
adapter) and personal digital assistants (PDA).
Micro SD CARD.

This card format only measures 10.9mm x 14.9mm x 1mm and


it can store several GB of information. Like the MINI SD,
is my using on mobile phones.

3.6 ASSIGNMENT PROPOSAL.


A proposition of assignment is a letter or a phrase to which two can be assigned.
values: it is either true or false, but not both. The form of a
the assignment proposition is: a=b, where b is an allowed expression, and a is the value
where the resulting value of evaluating b will be left.

The equal sign, "=", in a=b means assigning to the variable a the value that results from
evaluate the allowed expression b. That is, a=b has the meaning a b, which is not the same.
definition used in mathematics for '='.
The same as in other programming languages, in C there are operators.
most common arithmetic (+ addition, - subtraction, * multiplication, / division and % modulo).

The assignment operator is =, for example: i=4; ch='y'; Increment ++ and decrement --
unary. Which are more efficient than the respective assignments.
For example: x++ is faster than x=x+1. The ++ and -- operators can be prefix or
postfix. When they are prefixes, the value is calculated before the expression is
evaluated, and when it is postfix the value is calculated after the expression is
evaluated.
In the following example, ++z is prefix and -- is postfix:
int x,y,z;
main()
{
x=( ( ++z ) - ( y-- ) ) % 100;
}
What is equivalent to:
int x,y,z;
main()
{
z++;
x = ( z - y ) % 100;
y--;
}
The operator % (modulus or remainder) only works with integers, although there is a
function for floats (15.1 mod () ) from the math library.
The division operator / is for integer and floating-point division. Therefore, one must be careful.
careful. The result of x = 3 / 2; is one, even if x is declared as float. The rule is: if
both arguments in a division are integers, then the result is an integer. If you
wants to obtain the division with the fraction, then write it as: x = 3.0 / 2; or x = 3 /
2.0 and even better x = 3.0 / 2.0.

On the other hand, there is a shorter way to express calculations in C. For example, if you
they have expressions like: i = i + 3; or x = x * (y + 2);

So we can rewrite the previous expressions as: i += 3; and x *= y + 2;


respectively.

3.7 OPERATORS, OPERANDS, AND EXPRESSIONS.


The operators specify the type of calculation that is desired to be performed with the elements of
a formula. Microsoft Excel includes four different types of calculation operators:
arithmetic, comparison, and reference.
Arithmetic operators
To perform basic mathematical operations such as addition, subtraction, or multiplication,
combine numbers and generate numerical results, use the following operators
arithmetic.
Comparison operators
Two values can be compared using the following operators. When comparing
of values using these operators, the result is a logical value: TRUE or
FALSE.
Reference operators
They combine ranges of cells for calculations.
OPERAND: In mathematics, an operand is one of the inputs (arguments) of a
operator.

3.8 OPERATOR PRIORITY, EVALUATION OF EXPRESSIONS.


Determine the order in which operations are to be performed in an expression.
determined. To obtain the priority, the following rules must be known:
The operations that are enclosed in parentheses are evaluated first. If they exist
different nested parentheses (one inside the other), the innermost expressions are
they evaluate first. In case several operators of equal priority coincide in a
expression or sub-expression enclosed in parentheses, the order of priority in this case
it's from left to right.
When you want to carry out a low-priority operation in advance, you must
group the involved operands. Parentheses have priority over the rest of
the operations. Determine the order in which the operations are to be carried out in a
determined expression.
To obtain the priority, the following rules must be known:
The operations that are enclosed in parentheses are evaluated first. If there are
different nested parentheses (one inside the other), the innermost expressions are
they evaluate first.

In case several operators of equal priority coincide in an expression or sub-


expression enclosed in parentheses, the order of priority in this case is from left to
right.
When a low-priority operation is desired to be performed in advance, it must
group together the involved operands.
Below is a small table illustrating the order of priority:
3.9 DEVELOPMENT OF PROGRAMS.
A file can be created that contains the complete program, as in the examples.
that are available later on. Any ordinary text editor can be used with which
you are familiar. An editor available on most UNIX systems is vi, and in
Linux can use pico. By convention, the filename must end with ''.c''.
For example: My program C Pro. Test. C
The content of the file must follow C syntax.

Program execution.
The next step is to run the executable program. To run an executable in UNIX,
simply write the name of the file that contains it, in this case program (or
[Link]). With the above, the program is executed, displaying some result on the screen.
In this state, there could be run-time errors, such as
division by zero, or they could become evident when seeing that the program does not produce the
correct output. If the above happens, then the file should be edited again.
program, recompile it, and run it again. However, some information is provided
basic for some C programs. The preprocessor accepts the source code as
entry and is responsible for:
Remove the comments.
• Interpret the preprocessor directives that begin with #.
For example:
#include -- includes the content of the named file. These are usually called
header files.
For example:
#include <math.h> -- Standard library file for mathematics.
#include <stdio.h> -- Standard Input/Output library file.
#define -- defines a symbolic name or constant. Macro substitution.
#define MAX_ARRAY_SIZE 100
C compiler
The C compiler translates the source code into assembly code. The source code
is received from the preprocessor.

Assembler.
The assembler creates the source code or object files. On UNIX systems, it
You will be able to see the files with the suffix .o.

Linker
If any source file references functions from a library or from functions that
are defined in other source files, the Linker combines these functions (with main
() to create an executable file.

Bibliography
The provided URL does not contain text to translate..
Unable to access external links..
[Link]
[Link].
Unable to access the specified URL..
Unable to access external content..

INDEX

3.1 INTRODUCTION TO STRUCTURED LANGUAGE PROGRAMMING.

3.2 BASIC STRUCTURE OF A PROGRAM.

3.3 DATA TYPES.

3.4 IDENTIFIERS.

3.5 STORAGE, ADDRESSING, AND REPRESENTATION OF MEMORY.

3.6 ASSIGNMENT PROPOSAL.

3.7 OPERATORS, OPERANDS AND EXPRESSIONS.

3.8 OPERATOR PRIORITY, EVALUATION OF EXPRESSIONS.


3.9 PROGRAM DEVELOPMENT.

You might also like