Docsity

Programming - Unit 1: Introduction to programming and computers (slides), Ejercicios de Programación Informática

Vista previa parcial del texto

¡Descarga Programming - Unit 1: Introduction to programming and computers (slides) y más Ejercicios en PDF de Programación Informática solo en Docsity!

U N I T 1.

I N T R O D U C T I O N T O

P R O G R A M M I N G

A N D C O M P U T E R S

P R O G R A M M I N G Y E A R 2 0 2 0 - 2 0 2 1

2

Unit 1. Introduction to computers and programming

CONTENTS

  1. Computers and Computer Science. Historic perspective
  2. Algorithms and programs. Tools for algorithm design
  3. Information representation in computers
  4. Hardware: Functional structure of a computer. Computer architecture.
  5. Software: Programs and Programming languages

Contents

9

Unit 1. Introduction to computers and programming

BASIC COMPONENTS OF A COMPUTER

  • Physical support: Hardware
    • Mechanical and electronic elements that physically compose the computer
      • memory modules, screen, keyboard, motherboard, etc.
  • Logical support: Software
    • Logic part that directs the actions of the physical support
    • Set of programs that make the computer perform useful tasks
      • text processor, image editor, video game, etc.

1.1. Computers and Computer Science

1. 2. B R I E F H I S T O R Y O F

C O M P U T E R S

( S E E A N N E X F O R M O R E I N F O R M AT I O N )

2. A L G O R I T H M S A N D

P R O G R A M S

ALGORITHMS AND PROGRAMS

  • An algorithm is a specific set of steps (sequence of instructions) to

solve a problem (in a finite time)

  • A program implements an algorithm using a specific programming

language

20

Unit 1. Introduction to computers and programming

FLOW CHART

20

start

Enter number

number==password

attempts<3? Number NOT equal to password?

wwelcome locked

end

attempts = attempts + 1

attempts = 0

Number is equal to wrong, password? re-enter

T

F F

Count

Initialize

T F

T

X

21

Unit 1. Introduction to computers and programming

FLOW CHART

21

start

Enter number

number==password

attempts<3? Number NOT equal to password?

welcome locked

end

attempts = attempts + 1

attempts = 0

Number is equal to wrong, password? re-enter

T

F F

Count

Initialize

T F

T

X

Single entry and exit point

26

Unit 1. Introduction to computers and programming

FLOW DIAGRAMS

  • Graphical representation of the flow of the program
  • Uses standard symbols
    • Squares for instruction blocks
    • Rhombus for decision points

Tools for algorithm design

Check condition

instruction block 1

True

instruction block 2

False (^) Check condition

instruction block

True (^) False

Decision depending on condition

If … else while

3. I N F O R M A T I O N

R E P R E S E N T A T I O N I N

C O M P U T E R S

BIT AND BYTE

  • Bit
    • Digits in binary notation are called bits (BIT = binary digit)
    • It’s the smallest unit of information (0 or 1)
  • Byte
    • Set of 8 bits
    • It is also called character – as single characters used to be

encoded with one byte

40

Unit 1. Introduction to computers and programming

REPRESENTING NUMBERS

  • Binary system
    • Numeral system with base two
    • Converting from base 2 to base 10: 11001 = 1 x 2^4 + 1 x 2^3 + 0 x 2^2 + 0 x 2^1 +1 x 2^0 = 16 + 8 + 1 = 25
  • An additional byte can be used to store the sign (0: positive; 1: negative)
  • Representation in two's complement
    • more appropriate for implementing fundamental arithmetic operations using electronic circuits 2. Information representation in computers

See annex II for more information on numeral systems

42

Unit 1. Introduction to computers and programming

REPRESENTING NUMBERS: FLOATING POINT NOTATION

  • The three components of the number in scientific notation are represented with different sets of bits - mantissa/significand (significant digits) - base/radix - exponent - Example 0.123 x 10- - Mantissa: 0.123, Base: 10, Exponent: -
  • A wide range of numbers can be represent with the same number of bits
  • Real numbers are infinite, computers are not -> loss of precision 2. Information representation in computers

43

Unit 1. Introduction to computers and programming

IEEE 754 STANDARD FOR FLOATING POINT REPRESENTATION

  • Most commonly used representation in current computers
    • 32 bits (or 64 extension for double precision encoding )
    • Base 2 (by default, not encoded so no additional bits are used)
    • Mantissa: 1 bit for the sign, 23 bits for the digits
    • Exponent: 8 bits
  • Be careful when comparing two numbers
    • They will only be considered equal by the computer if they are equal bit by bit 2. Information representation in computers