You are on page 1of 31

Introduction to

Computer Programming 1

LECTURE 01
CCC101 - Computer Programming 1
Jennifer Joyce M. Montemayor

Department of Computer Science


College of Computer Studies
MSU - Iligan Institute of Technology
Objectives
‣ Identify the different components of a computer

‣ Know about programming languages and their


categories

‣ Understand syntax and semantics

‣ Understand Software Development Method and


apply it in problem solving

2 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01


Computer
‣ an electronic, programmable device that can store, retrieve, and
manipulate data

Major Components

1. Hardware

‣ tangible part of the computer

‣ composed of electronic and mechanical parts

2. Software

‣ intangible part of the computer

‣ consists data and computer programs

3 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01


1. Hardware
- Main Memory

- Secondary Memory

- Central Processing Unit

- Input Devices

- Output Devices

4 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01


Memory
‣ where data and instructions needed by the CPU to
perform are stored

Main Memory

‣ used to hold programs and data that the processor


is actively working on

Secondary Memory

‣ used to hold programs and data for long term use

5 Jennifer Joyce M. Montemayor / CSC101 / Lecture 01


Memory

6 Jennifer Joyce M. Montemayor / CSC100 / Lecture 01


Anatomy of Memory
Memory Cell

‣ an individual storage location in the


memory

Address of a memory cell

‣ the relative position of a memory cell in the


computer’s main memory

Contents of a memory cell

‣ the information stored in a memory cell,


either a program instruction or data

7 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01


How is data stored in the memory?
Bit

‣ short for Binary Digit

‣ either a 0 or a 1

‣ smallest element a computer can deal with

‣ by grouping them together large range of values can be


represented

8 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01


How is data stored in the memory?
Byte

‣ the amount of storage required to store a single character

‣ there are 8 bits to a byte

‣ capable of representing 28 = 256 different values

9 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01


Central Processing Unit (CPU)
‣ coordinate all computer operations

‣ perform arithmetic and logical operations on data

retrieve instruction from the main memory

fetch

execute decode
carry out the instruction determine what the instruction is

10 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01


Central Processing Unit (CPU)
3.6 GHz AMD A8-7670K Quad-Core Processor

‣ can execute approximately


3.6 billions of instructions
per second
4 GHz Intel® Core™ i7-6700K Quad-Core Processor
‣ able to produce complex
behavior at a speed
almost instantaneous to
human user

11 Jennifer Joyce M. Montemayor / CSC100 / Lecture 01


I/O Devices
‣ allows a computer system to interact with the outside world by
moving data in and out of the system

Input Device

‣ peripheral devices used to enter information for computation

e.g keyboard, mice, microphone

Output Device

‣ peripheral devices that receives data from the computer used for
observing the results of computation

e.g. monitor, printer, speaker

12 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01


2. Software
‣ programs used by a computer to operate

Program

‣ collection of instructions that makes a computer


perform a speci c task when executed

‣ list of instructions that tell a computer what to do

13 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01


fi
Software Categories
Applications Software

‣ programs that assist a computer user in accomplishing speci c tasks

e.g. Microsoft Word, Google Chrome, Steam

Systems Software

‣ programs that are needed to keep all the hardware and applications software running
together smoothly

‣ interface between the hardware and the user applications

e.g. Operating systems like Windows, Linux, MacOS

Compiler

‣ translates a high-level computer program into machine language

e.g. GNU Compiler Collection (GCC)

14 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01


fi
Computer Languages
Machine Language

‣ language directly understood by a computer

‣ collection of binary numbers understood by a speci c CPU

Programming Language

‣ standardized communication technique for expressing


instructions to a computer

‣ like human languages each has it’s own syntax and grammar

15 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01


fi
Programming Language Categories
Assembly Language

‣ mnemonic codes that correspond to machine language instructions

‣ computer operations are represented by mnemonic codes rather than


binary numbers and variables can be given names rather than binary
memory addresses

High-level Language

‣ used to write programs that are independent of the CPU on which they will
be executed

‣ combine algebraic expressions and English symbols

‣ is not directly understood by a computer

16 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01


Syntax and Semantics
Syntax

‣ rules of a speci c programming language

‣ it de nes how we can put together symbols, reserved words


and identi ers to make a valid program

Semantics

‣ refers to the meaning of a program statement and its purpose


and role in a program

17 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01


fi
fi
fi
Syntax and Semantics
Keep in mind,

✓ A program that is syntactically correct is NOT


necessarily semantically correct

✓ A program will always do what we tell it to do,


NOT what we meant to tell it to do

18 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01


Entering,
Translating
and Running
a High-level
Language
Program

19 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01


Software Development Method
‣ also referred to as the Program Development Lifecycle

‣ basic steps in trying to solve a problem on a computer

Steps,

1. Problem De nition

2. Problem Analysis

3. Algorithm Design and Representation

4. Coding and Debugging

20 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01


fi
1. Problem De nition
‣ a clearly de ned problem is already half the
solution

‣ computer programming requires us to de ne the


problem rst before we even try to create a solution

e.g

“Create a program that will determine the number of


times a name occurs in a list.”

21 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01


fi
fi
fi
fi
2. Problem Analysis
‣ involves breaking up the problem into smaller and simpler
sub-problems

‣ read the problem statement carefully to obtain a clear idea of


the problem and to determine the inputs and outputs

1. identify the data you have to work with - inputs

2. identify the desired results - outputs

3. develop a list of formulas to specify the relationships between


the inputs and outputs

22 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01


2. Problem Analysis
“Create a program that will determine the number of times a
name occurs in a list.”

1. Input to the program

‣ list of names

‣ name to look for

2. Output of the program

‣ the number of times the name occurs in a list

23 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01


3. Algorithm Design and Representation
Algorithm

‣ list of steps for solving a problem

‣ a clear unambiguous speci cation of the steps needed to solve a problem

‣ is a well-ordered collection of unambiguous and effectively computable


operations that, when executed, produces a result and halts in a nite amount of
time.

‣ it may be expressed using either of the following:

‣ Human Language (English, Tagalog, etc.)

‣ Graphical Representations ( owchart)

‣ Pseudocode which is a cross between human language and a programming


language
24 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01
fi
fl
fi
3. Algorithm Design and Representation
Algorithm using a Human Language:

1. Get the list of names, let's call this nameList


2. Get the name to look for, let's call this the keyName
3. Compare the keyName to each of the names in nameList
4. If the keyName is the same with a name in the list, add 1 to
the count
5. If all the names have been compared, output count

25 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01


3. Algorithm Design and Representation
Algorithm using a Graphical Representation:

26 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01


3. Algorithm Design and Representation
Algorithm using a Pseudocode:

Let nameList = List of Names


Let keyName = the name to be sought
Let Count = 0
For each name in NameList do the following
if name == keyName
Count = Count + 1
Display Count

27 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01


4. Coding and Debugging
‣ After constructing the algorithm, it is now possible
to create the source code. Using the algorithm as
basis, the source code can now be written using
the chosen programming language.

Debugging

‣ The process of xing errors (bugs) in your program

28 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01


fi
4. Coding and Debugging
Types of Errors

Syntax Error / Compile-time Error

‣ occur if there is syntax error in the code

‣ the compiler will detect the error and the program won’t compile

‣ the programmer won’t be able to form an executable program that a user can’t run until
the error is xed

Runtime Errors

‣ displayed during the execution of the program

‣ occurs when the program directs the computer to perform an illegal operation e.g
division by zero

Logic Error

‣ caused by following an incorrect/faulty algorithm

29 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01


fi
Warning!
‣ Learning how to program takes time

‣ It requires you to THINK

‣ It requires a lot of PRACTICE

‣ It requires a lot of PATIENCE

‣ One cannot learn to program just by reading a


textbook.

30 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01


The programmers of tomorrow are the wizards of the
future. You’re going to look like you have magic powers
compared to everybody else.

Gabe Newell
Founder and President, Valve

31 Jennifer Joyce M. Montemayor / CCC101 / Lecture 01

You might also like