Professional Documents
Culture Documents
Computer Programming I: The Algorithm and The Programming Languages Year 2020-2021
Computer Programming I: The Algorithm and The Programming Languages Year 2020-2021
Lecture 1
The algorithm and the programming languages
Year 2020-2021
Objectives
1. Know a computer’s structure and operation
2. Learn what a program and a programming language are
3. Distinguish between source code, object module and
executable program
4. Differentiate the stages in the process of developing
programs
5. Express the solution for a simple problem by means of an
algorithm
6. Sketch basic flowcharts
7. Know the basic elements in a C program
Computer Programming I Lecture 1 2
Contents
1. A computer’s structure and operation
2. The process of developing programs
3. The Algorithm
4. Simple Programming Examples
5. Software engineering concepts
6. Exercises
Data
Primary Secondary
memory storage
Text editor
Source code
Source code program.c
Source code
Source code program.c
Object module
Object module program.o
Linker
Source code program.c
Object modules
Object module program.o
Load module
Load module program
Operating System
Program Program
user
Testing
program solution
Installation
Computer Programming I Lecture 1 17
The process of developing programs
• Programming = building a program
– Not just writing a code
– Analogy: building a house
• Not just laying bricks
• Careful preparation: intended use, draw plans, make calculations, …
• Goal: provide a high-quality program
– within given constraints of time and cost,
– that matches the client’s demands, and
– is reliable, well documented and easy to maintain
• A well structured approach is necessary => software engineering
– https://medium.com/edge-coders/software-engineering-is-different-from-
programming-b108c135af26
Computer Programming I Lecture 1 18
The process of developing programs
1. Requirements analysis and specification Waterfall model
– Determine what has to be done
– Outcome: requirements specification document:
• accepted by the customer and the developer
– Might include a preliminary user manual and test procedures
2. Design
– Determine how the program should meet the demands
– Parts, interconnection, algorithms, data structures, user interface, …
– Outcome: detailed system description
– And a user manual
3. Implementation
– Write the code and conduct partial tests
– Outcome: the program code
– And final test protocols
Task
Computer Programming I Lecture 1 22
Problem solving with computers
1. Specification: define the problem in a formal way
2. Programming: design an algorithm for solving the problem
– Top-down design of the algorithm
• Split the problem into smaller subproblems
• Solve the subproblems separately
• Split the subproblems into simpler subproblems
• Keep doing this until the subproblems are trivial
Specification:
Swap the letters in a word, leaving the first and the last
character unchanged Lines to No
A word is formed by all consecutive characters (both be read?
End
letters and digits) between spaces
INPUT: a text file (organized in lines) Yes
OUTPUT: write to the screen the words of the file with
their letters swapped (except for the first and the last)
Read a line
Process
Subroutine
Decision
Data input
Data output
• Purposes: Data de
Lectura
– Design
datos
input
– Communication
Data de
Procesado
• Among programmers
• With the final user Impresión
Results de
displaying
resultados
– Facilitate programming
Finnish
FIN
• Output:
Hello, World!
_
• Block: {
• Every statement (instruction) is terminated statement;
with a semicolon (‘;’) …
• Wherever we can write a single statement, statement;
we can write a block instead }
Computer Programming I Lecture 1 32
Decision statements
Enter the first integer number: 34
Enter the second integer number: 56
Incorrect if the
numbers are equal
Number Square
1 1
2 4
3 9
4 16
5 25
_
Code reuse?
* *
* *
*****
*
*
*
******
*
*
*****
*
*
******
*****
* *
* *
*****
*
*
*
******
*
*
*****
*
*
******
_
Functions
* *
* *
*****
*
*
*
******
*
*
*****
*
*
******
*****
* *
* *
*****
*
*
• What if we want
*
subprograms to do
******
*
*
different things for *****
*
different values? *
******
_
A lot of material for this lecture comes from a book on Ada language
(proving that programming != coding):
• Jan Skansholm, Ada from the Beginning, 1994, Adisson-Wesley.
Computer Programming I Lecture 1 52