01 - Unit 1. Introduction
01 - Unit 1. Introduction
Basic concepts
Programming computers
Imperative programming
2
BASIC CONCEPTS
3
BASIC CONCEPTS
Computer
A machine capable of receiving input data, carrying out logical and
arithmetic operations with them, and
through an output medium.
and under the control of an
previously stored in the computer.
5
BASIC CONCEPTS
COMPUTER
Computer
A capable of Auxiliary storage memory logical and
arithmetic with them, and Data
Instructions
through an output medium. All this
and underMain the control of an instruction program
memory
previously
Input stored in the computer. Output
Instructions Data (Data)
(Data + instructions)
6
BASIC CONCEPTS
HARDWARE: Physical components making up a computer system (mechanical, magnetic,
electronic and electrical devices).
CPU (Central Processing Unit): Electronic circuits (processor) capable of performing
information processing or input/output operations in accordance with the code stored in
memory. Composed of an Arithmetic Logic Unit and a Control Unit.
Memory: Device where data and instructions are stored:
Main memory:
RAM (Random access memory)
ROM (Read only memory)
Auxiliary (storage) memory: Hard disk, SSD, etc.
Input/output units: Devices and circuitry associated to them that link the computer to
the external environment.
Keyboard, screen, mouse, barcode reader, etc. :
7
BASIC CONCEPTS
8
BASIC CONCEPTS
Operating System
The software that allows a user to run other applications on a computing device.
No need to worry about specific hardware details.
Group of programs that facilitate and optimize the use of the computer and the
operation of other programs (application software).
It is the interface between the user and the hardware.
Sends messages to each application or interactive user about the status of operation and
any errors that may have occurred.
Manages resources: Memory, CPU, Input/Output, files, etc.
9
CONTENTS
Basic concepts
Programming computers
Imperative programming
10
PROGRAMMING COMPUTERS
What is programming?
Basically, it is just giving instructions to the computer in order to complete a
specific task.
https://youtu.be/zOjov-2OZ0E?t=117 11
PROGRAMMING COMPUTERS
What is programming?
A group of techniques, methods and rules to build legible, correct and
efficient computer programs.
The programs created must be:
: The code of the program must understandable.
: The program must perform the task for which it was created.
: The task must be done in the best way and in the shortest time possible.
12
PROGRAMMING COMPUTERS
What is programming?
Programming is a way to “instruct the computer to perform various tasks”.
“Instruct the computer”: Provide the computer with a set of instructions that
are written in a that the computer can understand.
“Perform various tasks”: Tasks could be simple (adding 2 numbers) or complex,
which may involve a sequence of multiple instructions.
13
PROGRAMMING COMPUTERS
14
PROGRAMMING COMPUTERS
15
PROGRAMMING COMPUTERS
16
PROGRAMMING COMPUTERS
17
PROGRAMMING COMPUTERS
Programming paradigms
A way of classify programming languages:
Imperative programming: Programming with an explicit sequence of commands.
Examples: Pascal, C, Java, Python, …
Object oriented programming: Programming by defining objects that send messages to each
other. Objects have their own internal (encapsulated) state and public interfaces.
Examples: Java, C++, C#,…
Declarative programming: Programming by specifying the result you want, not how to get it.
Logic programming: Prolog.
Functional programming: Lisp.
18
PROGRAMMING COMPUTERS
Identifies errors in the source program and informs the programmer as accurately
as possible.
Generates code (generally machine code).
The translation can be done in two different ways:
Interpretation
Compilation
19
PROGRAMMING COMPUTERS
Compiled languages
A compiler is a program that takes high-level source code as input and generates
an equivalent program called object program or object code.
Source code
Compiler
Object program
Data and/or executable program Result
20
PROGRAMMING COMPUTERS
Compiled languages
A compiler is a program that takes high-level source code as input and generates
an equivalent program called object program or object code.
The translation process using a compiler is performed only once, and it is optimized for the
target platform/hardware.
Modules (parts) of a program can be compiled and then linked with the rest to assemble a
more complex and bigger executable program.
If changes are made to the code after compilation, the new code will need to be compiled
again.
21
PROGRAMMING COMPUTERS
Interpreted languages
An interpreter is a program that takes as input the code written in source
language and then translates and executes instruction by instruction (one after the
other).
Source language + data
Interpreter
Results
22
PROGRAMMING COMPUTERS
Interpreted languages
An interpreter is a program that takes as input the code written in source
language and then translates and executes instruction by instruction (one after the
other).
The translation process is needed every time a program is executed:
Modifications are easier, they do not require extra processing.
Makes the execution of a program slower than a compiled program.
Examples: Python, Perl, JavaScript, etc.
23
CONTENTS
Basic concepts
Programming computers
Imperative programming
24
PROBLEM SOLVING
Problem solving
Programming resolution of a problem
Three main stages to solve problems:
Analysis of the problem
Design of the algorithm
Implementation
25
PROBLEM SOLVING
Basic concepts
Programming computers
Imperative programming
Introduction to the C Programming Language
28
IMPERATIVE PROGRAMMING
Imperative programming
Characteristics
Finite sequence of instructions.
They are executed one after the other.
Data stored in memory and referenced by variables.
Examples of imperative languages: Variable:
• A named location in memory that is used to hold a value
C, Pascal, Cobol, Fortran... that can be modified by the program.
• A value that can change, depending on conditions or on
information passed to the program.
Example of an imperative program (addition X + Y):
Read (X)
Read (Y)
result = X + Y 29
Return result
IMPERATIVE PROGRAMMING
Imperative programming
This category includes structured programming, modular programming, and
object-oriented programming.
Each of these extensions or evolutions has improved the maintainability and
quality of the imperative programs.
31
IMPERATIVE PROGRAMMING
Structured Programming
Programming paradigm aimed at providing structure to computer programs.
Improves the clarity, quality, and reduces the development time of a computer
program.
Meets the following objectives:
Program (name of the program) or
Easy to read and understand by just reading theFunction
code itself.
(name of the function)
{Short description}
Easy to debug. Begin
Data definition
Easy to maintain. Constants
Variables
Facilitates teamwork on the same program. Actions
…
…
End 32
IMPERATIVE PROGRAMMING
Structured Programming
Common approaches:
Divide and conquer: Functionality is divided into modules and functions that perform
specific tasks.
Break up a complex project into something that has manageable pieces which have clearly defined
parts.
Facilitates the development, modification and testing of programs.
Top-down design: Algorithms are refined. Developers map out the overall program
structure into separate subsections and then progressively descend to the implementation
of the most specific details.
All instructions are accessible: For each instruction, there is at least one path that goes
from the beginning to the end of the program and goes through that action.
d.
33
Pseudocode Program multiply_using_addition
{Multiplies two numbers using only addition.}
Return Result
End
34
CONTENTS
Basic concepts
Programming computers
Imperative programming
35
THE C PROGRAMMING LANGUAGE
The C language was created in the 1970s by Dennis Ritchie to serve as the
language for the development of the UNIX operating system.
Compiled and imperative.
Often defined as an intermediate level language because it includes both the
typical elements of high-level languages and some features of assembly
language.
Contains only 32 keywords and is case sensitive. Keywords are elements of
the language.
Initially considered a language for programming systems (operating systems,
interpreters, etc.), although it is now considered a general-purpose
language.
36
THE C PROGRAMMING LANGUAGE
37
THE C PROGRAMMING LANGUAGE
38
THE C PROGRAMMING LANGUAGE
#include <stdio.h> The main program will always be within the
Structure of// aglobal
C program
declarations
function “main”. We use { and } to delimit the
beginning and end of the code block.
int main() {
Example of a C program
/* Declaration of variables*/
int x, y, result;
int i;
/* Multiplying */
result = 0;
for (i = 1; i <= y; i++)
result = result + x;
/* Output of results */
printf(“The value of %d * %d es %d \n", x, y, result);
return(0);
}
40
#include <stdio.h>
THE C PROGRAMMING
int main() { LANGUAGE
int x, y, result;
printf("Introduce the value of X: ");
Example of a C program (II)
scanf("%d", &x);
printf("Introduce the value of Y: ");
scanf("%d", &y);
/* Function call */
result = multiply(x, y);
43
https://www.youtube.com/watch?v=TAAXwrgd1U8
END.