GENG106 Introduction to computers and programming Chapter1.pdf

abb3184 20 views 36 slides Sep 16, 2025
Slide 1
Slide 1 of 36
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36

About This Presentation

These slides explain the basic concepts of the computer and how it works


Slide Content

GENG 106:Computer Programming
Introduction to Computers
And Programming
Chapter 1

COMPUTER SYSTEMS: HARDWARE
AND SOFTWARE
GENG 106 Computer Programming 2

Introduction
Computers can be programmed
●Designed to do any job that a programtells them to
Program: set of instructions that a computer follows to
perform a task
●Commonly referred to as Software
Programmer: person who can design, create, and test
computer programs
●Also known as software developer
Computer: a programmable machine designed to follow
instructions (orders) in a program.
Why Program?
To solve problems (develop apps, games, website), speed up
calculations etc.
GENG 106 Computer Programming 3

Main Hardware Component Categories
GENG 106 Computer Programming 4
Hardware is the physical devices that make up a
computer. Computer is a system composed of several
components that all work together
Typical major components:

Central Processing Unit (CPU)
oThe part of the computer that actually runs programs
●Most important component
●Without it, cannot run software
CPU includes:
Control Unit
●Retrieves and decodes program instructions.
●Coordinates computer operations.
Arithmetic & Logic Unit (ALU)
●Performs mathematical operations.
●Performs logical operations (eg, comparisons).
GENG 106 Computer Programming 5

Main Memory
•Main memory: is where computer
stores a program while program is
running, and data used by the program
•Known as Random Access Memoryor
RAM
●CPUis able to quickly access data in RAM
●RAM is volatile memory: Memory used for
temporary storage while program is running
●Contents are erased when computer is off
GENG 106 Computer Programming 6

Main Memory Organization
Bit
●Smallest piece of memory
●Stands for binary digit
●Has values 0 (off) or 1 (on)
Byte
Is 8 consecutive bits
Kilobyte (KB)
Is 1024 bytes
Megabyte (MB)
Is 1024 kilobytes (i.e. 1024x1024 = 1,048,576 bytes)
Gigabyte (GB)
Is 1024 megabytes (i.e. 1024x1024x1024 = 1,073,741,824 bytes)
Terabyte (TB)
Is 1024 gigabytes (i.e. 1024x1024x1024x1024 = 1,099,511,627,776 bytes)
GENG 106 Computer Programming 7
0 1 1 0 0 1 1 1
8 bits
1 byte

Secondary Storage
Non-volatile-data retained when
program is not running or computer is
turned off.
●Programs normally stored here and loaded
to main memory when needed
Comes in a variety of media
●Magnetic: floppy or hard disk drive, internal
or external
●Optical: CD or DVD drive
●Flash: USB flash drive
●SecureDigital(SD): micro-SD card
GENG 106 Computer Programming 8

Input Devices
Input: data the computer collects from
people and other devices
Input device: component that collects the
data. Used to send data from outside to the
computer.
Examples:
●keyboard, mouse, scanner, camera, touchscreen
●Disk drives can be considered input devices
because they load programs into the main
memory
Lets identify Inputs in a modern smartphone.
GENG 106 Computer Programming 9

Output Devices
Output: data produced by the computer for
other people or devices
●Can be text, image, audio, or bit stream
Output device: formatsand presentsoutput
Many devices can be used for output. Examples:
●Computer screen, printer, speakers.
●Disk drives and USB drives can be considered output
devices because data is sent to them to be saved
What are the outputs of a smartphone?
GENG 106 Computer Programming 10

SOFTWARE
GENG 106 Computer Programming 11

Software
Everything the computer does is controlled by software
●General categories:
•Application software
•System software
Application software: programs that make the computer
useful for every day tasks
●Examples: word processing, email, games, and Web browsers
System software: programs that controland managebasic
operations of a computer
●Operating system: controls operations of hardware components
●Utility Program: performs specific task to enhance computer
operationor safeguard data
●Software development tools: used to create, modify, and test
software programs
GENG 106 Computer Programming 12

How a Program Works
Figure 1-16 The fetch-decode-execute cycle
13
GENG 106 Computer Programming

PROGRAMS AND PROGRAMMING
LANGUAGES
GENG 106 Computer Programming 14

From Machine Language to Assembly Language
•Impractical for people to write in machine language
•Assembly language: uses short words (mnemonics) for
instructions instead of binary numbers
●Easier for programmers to work with
•Assembler: translates assembly language to machine
language for execution by CPU
Sample Assembly language code:
GENG 106 Computer Programming 15

Programs and Programming Languages
Programming Language : a language used to write programs.
Low-level languages: close in nature to machine language (the only
language that the machine understands which is asequence of bits (1, or 0))
●Example: assembly language
●Difficult to write (and read).
High-level languages: closer to human language. Allows simple
creation of powerful and complex programs
●similar to everyday English (e.g., if, while, print, ...)
–No need to know how CPU works or write large number of instructions
–Single statements accomplish substantial tasks.
–easier to read (ex:if (a=b) then x=0 else x=1; ) and errors are easier to find.
–Programs are portable from one computer to another.
GENG 106 Computer Programming 16

How can we write programs in high-level languages, and
the computer can still understand them?

Compiler
translates high-level language program into separate
machine language program. Whole program is translated.
Machine language program can be executed at any time –no
more compilation.
GENG 106 Computer Programming 17
0000000000010010
0010111011111101
0000000000010000
0010111010110101
0000000000010010
0010111011111101
x = 10; y=2;
z = x + y;
a=(z+5)/(x-y); Compiler
Program written in High Level
Language such as C++
Machine language statements

Interpreter
Translatesand executesinstructions in high-level language
program
●Used by Pythonlanguage.
●Interprets one instruction at a time.
●No separate machine language program.
Source code: statements written by programmer
●Syntax error: prevents code from being translated
GENG 106 Computer Programming 18

Discussion & Questions
o
GENG 106 Computer Programming 19
When a program runs on a computer, the part of the computer
that carries out the instructions is called the:…………………….


A bit is:
oan alternative term for byte.
oan electronic device used in computers.
oa binary digit, like 0 or 1.
A compiler:
omaintains a collection of programs.
otests a program's logic.
otranslates source code into executable code.
otranslates executable code to machine code

WHAT IS A PROGRAM MADE OF?
GENG 106 Computer Programming 20

Statements
an instructionto the computer to perform an action.
may contain keywords, operators, programmer-defined
identifiers, and punctuation.
Statements may occupy multiple lines.
GENG 106 Computer Programming 21
x = 2 #assignment statement
x = x + 2 #assignment with expression
print(x) #print statement
Variable Operator Constant Function

Keywords
Also calledreserved words
Have a specific meaning.
Cannot be used for another purpose.
Written in lowercase letters.
Examples: break, continue, if, while, else, …etc.
GENG 106 Computer Programming 22

Programmer-Defined Identifiers
Names given by the programmer to identify parts of a program
Not part of the Python language.
Used to represent various things, such as variables (memory
locations).
GENG 106 Computer Programming 23

Operators
Used to perform operations on data
Many types of operators
●Arithmetic: +, -, *, /
●Assignment: =
GENG 106 Computer Programming 24

Variables
A variable is a namedlocationin computer memory (in RAM).
holds a piece of data that has a value.
GENG 106 Computer Programming 25
12
17
5
#71
sum
#73
#72
num2
num1
#77
addresses/
locations
variable
names
values

INTRODUCTION TO PROBLEM
SOLVING
GENG 106 Computer Programming 26

Problem Solving
GENG 106 Computer Programming 27
Algorithm: is a set of well-defined
logical steps that must be taken to
perform a task
oThis is a general definition, however
our concern here is to write algorithms
to solve computational problems
oWe want to specify the steps that
should be followed by the computer to
perform a specific task, and write them
using a human language like English –
see the example algorithm →
An algorithm can also be represented
graphically (using a flowchart)
An Algorithm example
1.Start
2.Print “Enter first number”
3.Read A.
4.Print “Enter second number”
5.Read B.
6.Print “Enter third number”
7.Read C.
8.S=A+B+C
9.X=S/3
10.Print X.
11.End.

Program Structure
GENG 106 Computer Programming 28
Whether written as text or represented in a flowchart, an
algorithm is made of the following control structures:
●By control structure we mean the logical design that controls
the order in which a set of statements execute
Sequence structure: set of statements that execute in the
order they appear (See the algorithm on the previous slide)
Decision structure: specific action(s) performed only if a
condition exists appear (See the flowchart on the next slide)
●Also known as selection structure
Repetition structure: set of statements that execute
repeatedly a specific number of times or based on a
condition.
●Also known as loop structure

Introduction to Flowcharts
GENG 106 Computer Programming 29
●It is a formal diagram that is used to represent an algorithm,
process, or workflow.
●It uses the following symbols:

GENG 106 Computer Programming 30

USING PYTHON
GENG 106 Computer Programming 31

Using Python
GENG 106 Computer Programming 32
Python must be installed and configured prior to use
●One of the items installed is the Python interpreter.
Python interpreter can be used in two modes:
●Interactive mode: enter statements on keyboard.
●Script mode: save statements in Python script.

Interactive Mode
GENG 106 Computer Programming 33
When you start Python in interactive mode, you will see a
prompt.
•Indicates the interpreter is waiting for a Python statement to be typed.
•Prompt reappears after previous statement is executed.
•Error message displayed If you incorrectly type a statement.
Good way to learn new parts of Python –suitable for programs of
3-4 lines long.

Writing Python Programs and Running
Them in Script Mode
GENG 106 Computer Programming 34
Statements entered in interactive mode are not saved as
a program.
To have a program use script mode.
●Save a set of Python statements in a file.
●The filename should have the .pyextension.
●To run the file, or script, type (python filename)at the
operating system command line. Or use the Run menu.

The IDLEProgramming Environment
GENG 106 Computer Programming 35
IDLE(Integrated Development and Learning Environment):
a single program that provides tools to write, executeand
testa program.
•Automatically installed when Python language is installed.
•Runs in interactive mode.
•Has built-in text editor with features designed to help write
Python programs (scripts).
Other good development environments
•Visual Studio Code
•Pycharm
•PyDev
•..more

Discussion & Questions
o
GENG 106 Computer Programming 36
True or False:
1.A programmer writes a high-level program.
2.The programmer runs a compiler, which
converts the high-level program into an
executable program.
3.Users can run the executable.