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

01 - Unit 1. Introduction

Uploaded by

antogf1986
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)
8 views

01 - Unit 1. Introduction

Uploaded by

antogf1986
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
You are on page 1/ 44

UNIT 1 – INTRODUCTION TO COMPUTER

SCIENCE AND PROGRAMMING


ARTURO S. GARCÍA PROGRAMMING FUNDAMENTALS 1
UNIVERSITY OF CASTILLA-LA MANCHA
DEGREE IN COMPUTER SCIENCE AND ENGINEERING. ESII
2022-2023 ALBACETE
CONTENTS

Basic concepts

Programming computers

Problem solving using programming

Imperative programming

Introduction to the C Programming Language

2
BASIC CONCEPTS

WHAT IS COMPUTER SCIENCE?

3
BASIC CONCEPTS

 Easier to define it in Spanish…


 Informática (Información automática)
 Definición R.A.E. : La informática es el conjunto de conocimientos científicos y
técnicas que hacen posible el tratamiento automático de la información por
medio de ordenadores.

 Informatics – Information Science


 The science of processing data for storage and retrieval.
 The study or use of systems (especially computers and telecommunications) for
storing, retrieving, and sending information.
 The study of the nature, collection, and management of information and of its uses,
especially involving computer storage and retrievals.
4
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)

Control Unit Arithmetic


Logic Unit
Processor (CPU)

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

 SOFTWARE: Programs used to direct the operation of a computer.


 Application software: Used by the user to perform specific tasks.
 Spreadsheets, accounting software, internet browsers, office software, surveillance
systems, etc.
 System software: Used for operating the computer hardware. It is the
software that makes the application software work.
 Operating systems, drivers, etc.

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

Problem solving using programming

Imperative programming

Introduction to the C Programming Language

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

 What is a Programming Language?


 A programming language is a language used to build computer programs.
 Programming languages are defined by:
 The set of usable symbols and keywords.
 The grammatical rules for constructing syntactically and semantically correct
sentences.

14
PROGRAMMING COMPUTERS

 Historical development of programming languages


 Early history (Machine language):
 It is the language directly understood by the machine
 Very difficult to write and understand by humans.
 The modification and correction of errors is very difficult.
 It depends on the specific hardware.
 Reduced instruction set.
 Example:

15
PROGRAMMING COMPUTERS

 Historical development of programming languages


 Low-level languages (Assembly language):
 Instructions are represented using mnemonic and data is referenced by a name.
 Comments are allowed.
 They are very close to the machine and, therefore, the programmer must know the
architecture of the processor used.
 Example:

16
PROGRAMMING COMPUTERS

 Historical development of programming languages


 High-level languages:
 Independent of the specific machine.
 Structure close to natural human languages.
 Extensive set of instructions.
 Powerful instructions.
 Quick and easy coding.
 Readable programs and, therefore, easier to maintain and verify.
 Example:

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

 The translation process


 A translator is a program that takes a program written in a source language as an
input and transforms it into a program written in an object language.
Source code Translator Object code

 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

Problem solving using programming

Imperative programming

Introduction to the C Programming Language

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

Analysis and design Implementation


COMPUTER
PROBLEM ALGORITHM
PROGRAM

25
PROBLEM SOLVING

 Analysis of the problem


 The problem must be well defined (or correctly understood) if a satisfactory solution is
to be reached.
 The specifications of the inputs and outputs of the problem must be described in detail.
 What data is needed to solve the problem?
 What information should the solution provide?
 What are the restrictions?
 Example: Multiply two numbers, X and Y, using only addition.
 Input: Two natural numbers, X and Y.
 Output: X * Y
 Restrictions: Use only +
26
PROBLEM SOLVING

 Design of the algorithm


 Once the problem is clearly defined, the next step is to define HOW the program
will perform its task:
 How will the output data be obtained from the input data?

 Algorithm: A set of rules that create a sequence of operations to solve a problem.


Systematic method for producing a specified result.
It is characterized by its:
 Finiteness
 Definiteness
 Generality
 Effectiveness
27
CONTENTS

Basic concepts

Programming computers

Problem solving using programming

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

 Basic structure of imperative programs


 They consist of a set of actions that are described in each line.
 These actions change the state of the computer.
 An imperative program tells the computer “how” to accomplish the objective of
the program.
start:
 The basic types of actions are: numPeople = length(people)
if i >= numPeople goto finished
 Assignment p = people[i]
nameLength = length(p.name)
 Read / Write if nameLength <= 5 goto nextOne
upperName = toUpper(p.name)
 Alternative addToList(result, upperName)
 Repetition nextOne:
i = i + 1
goto start
finished: 30
return sort(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.}

 It is used to define algorithms Begin


independently of the programming
/* Data declaration */
language. X: Integer.
Y: Integer.
 Its structure is similar to actual code Result: Integer.
but uses natural language instead.
/* Actions */
Result = 0
Repeat Y times:
Result = Result + X

Return Result

End

34
CONTENTS

Basic concepts

Programming computers

Problem solving using programming

Imperative programming

Introduction to the C Programming Language

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

 The rapid expansion of C over various types of computers led to


many variations - similar but incompatible.
 In the 1980s, the ANSI (American National Standards Institute)
standard was established to define the language and provide an
unambiguous and machine-independent definition of the language.
 C programming language evolved from C89/C90/C95, C99, C11 and
C18 (latest to date).
 We will mainly use ANSI C, but we will talk a bit about C99.

37
THE C PROGRAMMING LANGUAGE

 The History of Programming


 https://www.youtube.com/watch?v=Tr9E_vzKRVo

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.

return_type main(list of parameters)


{
// sequence of sentences of the main program
}
Functions that implement other actions may
(or may not) exist in the program.
(This will be explained later).
return_type function1(list of parameters)
{
// sequence of sentences
}

return_type function_N(list of parameters)


{
// sequence of sentences
39
}
THE C PROGRAMMING
#include <stdio.h>LANGUAGE

int main() {
 Example of a C program
/* Declaration of variables*/
int x, y, result;
int i;

/* Reading input data */


printf("Introduce the value of X: ");
scanf("%d", &x);
printf("Introduce the value of Y: ");
scanf("%d", &y);

/* 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);

printf(“The value of %d * %d es %d \n", x, y, result);


return(0);
}

/* Definition of the function */


int multiply(int x, int y) {
int result = 0;
int i;
for (i = 1; i <= y; i++)
result = result + x;
return result;
} 41
GLOSSARY
 Source code: Text written by a programmer with the instructions to be executed in the
program. It is the compiler input.
 Object Code: Result of the translation of the source code by the compiler. It is the entry
of the linker.
 Executable code: Code obtained by the linker from one or more object code files.
 Compiler: Program in charge of translating the source code into object code.
 Linker: Program that gathers several object code files that have been compiled separately to
obtain an executable program.
 Compilation time: The period of time in which a program is compiled. The time in which
the program is written is sometimes included as well.
 Execution time: Time in which the program is running.
 Trace: Manual execution of a program to check that its behaviour is correct.
 Debug: Process of identifying and removing errors in a computer program.
42
WHY IS CODING SO HARD?

43
https://www.youtube.com/watch?v=TAAXwrgd1U8
END.

You might also like