AU Chapter 1
AU Chapter 1
AU Chapter 1
1
Chapter one
Introduction
Computer Architecture Basics
Hardware and Software
Program Development
Algorithms and flow chart
2
What is a Computer?
• Computer
– Device capable of performing computations and making
logical decisions
• Hardware
– Various devices comprising computer Keyboard, screen,
mouse, disks, memory, CD-ROM, processing units, …
• Software
– Instructions to command computer to perform actions and
make decisions
• Computer programs
– Sets of instructions that control computer’s processing of data
– instructions that tells the computer what to do.
• Computer programming
– is the process of writing, testing, debugging/troubleshooting,
and maintaining the source code of computer programs. 3
Computer Architecture Basics
5
Programming language
• is an artificial language that can be used to control the behavior of
a machine, particularly a computer.
6
1. Machine language
• Only language computer directly understands
• “Natural language” of computer i.e computer easily understood
these programs
• Defined by hardware design
Machine-dependent
• Generally, consist of strings of numbers: Ultimately 0s and 1s
• Instruct computers to perform elementary operations One at a
time
• Cumbersome for humans
Example:
+1300042774
+1400593419
7
2. Assembly languages
• English-like abbreviations representing elementary computer
operations
• Clearer to humans
• Incomprehensible to computers i.e not able to be understood
by computers
• Translator programs (assemblers) Convert to machine
language
Example:
LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY
ADD A, B – adds two numbers in memory location A and B
8
3. High-level languages
• Similar to everyday English, use common mathematical
notations
• Single statements accomplish substantial tasks
• Assembly language requires many instructions to
accomplish simple tasks
• Translator programs (compilers)
• Convert to machine language
• Interpreter programs
• Directly execute high-level language programs
• Example:
grossPay = basePay + overTimePay
9
Programming languages: by programming paradigm (programmer's view of
code execution ) can be categorized into three most influential
paradigms(Chronological order)
• Procedural Programming Languages
• Structural Programming Languages
• Object-oriented Programming Languages
1. Procedural Programming Languages
• specifies a list of operations that the program must complete to reach the
desired state.
• Each program has a starting state, a list of operations to complete, and an
ending point.
• Procedures, also known as functions, subroutines, or methods, are small
sections of code that perform a particular function . 10
2. Structured Programming Languages
• Disciplined approach to writing programs
• Clear, easy to test and debug, and easy to modify
• is a special type of procedural programming.
• requires that programmers break program structure into small pieces
of code that are easily understood.
• One of the well-known features of structural programming is that it
does not allow the use of the GOTO statement.
• It is often associated with a "top-down" approach to design.
11
3. Object-Oriented Programming Languages
• is one the newest and most powerful paradigms
• the designer specifies both the data structures and the types of
operations that can be applied to those data structures.
• This pairing of a piece of data with the operations that can be
performed on it is known as an object.
• A program thus becomes a collection of cooperating objects, rather
than a list of instructions.
• Objects can store state information and interact with other objects, but
generally each object has a distinct, limited role.
• More understandable, better organized and easier to maintain
12
Problem solving Techniques
Example:
Original Program Specification:
Write a program that obtains two integer numbers from the user. It
will print out the sum of those numbers.
Pseudocode:
Prompt the user to enter the first integer
Prompt the user to enter a second integer
Compute the sum of the two user inputs
Display an output prompt that explains the answer as the sum
Display the result 14
Structured Charts
• Structured chart depicts the logical functions to the solution of the
problem using a chart.
• It provides an overview that confirms the solution to the problem
without excessive consideration to detail. It is high-level in nature.
Example: Write a program that asks the user to enter a temperature
reading in centigrade and then prints the equivalent Fahrenheit value.
Input Process Output
15
Flowchart
• is a schematic representation of an algorithm or a process.
• it doesn’t depend on any particular programming language, so that it
can use, to translate an algorithm to more than one programming
language.
• uses different symbols (geometrical shapes) to represent different
processes. The following table shows some of the common symbols.
16
Example 1: - Draw flow chart of an algorithm to add
•The flow chart is
two numbers and display their result.
Start
Algorithm description
Read A,B
• Read the rules of the two numbers (A and B)
• Add A and B C=A+B
• Assign the sum of A and B to C
• Print C
Display the result ( c)
17
End
Example 2: Write an algorithm description and draw a flow chart to
check a number is negative or not.
Algorithm description.
1/ Read a number x
2/ If x is less than zero write a message negative
else write a message not negative
Start
Read X
18
Stop
19
20