[go: up one dir, main page]

0% found this document useful (0 votes)
12 views50 pages

Lec#1 - Intro Updated

Uploaded by

Maysam Oudah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views50 pages

Lec#1 - Intro Updated

Uploaded by

Maysam Oudah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 50

CS110D: PROGRAMMING

LANGUAGE I
Computer Lecture 1: Introduction to computers & problem
Science solving
Lecture Contents
2

 Course Info.
 Problem Solving Techniques
 Pseudocode
 Algorithm
 Flow charts
 Examples
 Elements of a Computer system.
 Evolution of programming languages
 The code Life Cycle
dr. Amal Khalifa,Fall14
Course info
3

 Books and references


 Course plan
 Assessment methods and grading
 Labs and practical assignments
 Practical exam
Books and references
4

[1] JavaTM Programming: From


[1]
Problem Analysis to Program
Design (Introduction to
Programming) 5th Edition
 https://www.amazon.com/JavaTM-
Programming-Problem-Analysis-
Introduction/dp/111153053X

[2] Deitel P.J., Deitel H.M. - Java. How


to Program, 9th Edition
[2]
 http://staff.cs.psu.ac.th/iew/cs344-481/Java
%20How%20to%20Program%209th
%20Edition.pdf
How People Solve Problems
5

 A Problem exists when what we have


(Data) is not the same as what we want
(information)
 People create a solution (called an
Algorithm) which manipulates Data into
Information
 People do this quickly and often in a
complex way

Dr. Amal Khalifa, 2014


How Computers Solve Problems
6

 Computers also use Algorithms to solve


problems, and change data into
information
 Computers can only perform one simple
step at a time
 Complex “Human” Algorithms must be
broken down into simple step-by-step
instructions BEFORE they can be
translated into computer code

Dr. Amal Khalifa, 2014


Algorithms
7

 Algorithm: A step-by-step problem-solving


process in which a solution is arrived at in a finite
amount of time
 Example: Accelerating in a car
1. Move right foot to gas pedal
2. Apply pressure to gas pedal with right foot
3. If speed is too high, apply less pressure.
4. If speed is too low, apply more pressure.

Dr. Amal Khalifa, 2014


Problem Solving
8

 Problem Solving is the ability to


understand what you have, what you
want, and creating a set of instructions to
change what you have into what you want
 Good Problem Solving Skills are based on
knowledge, experience and logic
 Good Programmers NEVER make
assumptions

Dr. Amal Khalifa, 2014


9 Dr. Amal Khalifa, 2014
Problem Solving Approach
10

 In the programming environment, the


problem-solving process involves the
following steps:
1. Analyze the problem and outline the problem
and its solution requirements.
2. Design an algorithm to solve the problem.
3. Implement the algorithm in a programming
language, such as Java.
4. Verify that the algorithm works.
5. Maintain the program by using and improving it,
and modifying it if the problem domain changes.
Dr. Amal Khalifa, 2014
Click icon to add picture

Problem analysis–coding–execution
11
cycle

Dr. Amal Khalifa, 2014


Expressing the Algorithms
12

 A “Standard” way of describing an


algorithm must exist if we expect our
solution to be understood by others
easily
 There are standards in programming:
 PSEUDOCODE
 FLOWCHARTS

Dr. Amal Khalifa, 2014


Pseudo Code
13

 “Pseudo” means “pretend” or “false”


 Pseudo Code is pretend or false
computer code; generic English-like
terms that are somewhat like
computer code
 Pseudo Code is not as standardized as
flowcharts, and does not facilitate the
breaking down of problems as well as
a flowchart does
Dr. Amal Khalifa, 2014
Pseudocode (wikipedia)
14

 Pseudocode (derived from pseudo and


code) is a compact and informal high-
level description of a computer
programming algorithm that uses the
structural conventions of programming
languages, but omits detailed
subroutines, variable declarations or
language-specific syntax. The
programming language is augmented
with natural language descriptions of the
details, where convenient. Dr. Amal Khalifa, 2014
Example
15

 Write an algorithm to find the area and


the perimeter of a rectangle

dr. Amal Khalifa,Fall14


Click icon to add picture

16 Pseudo Code Example


design an algorithm to find the perimeter and area of a rectangle

Dr. Amal Khalifa, 2014


17 That’s all for Today!!
Text book
[1] chapter 1 (pages 13-16)

Dr. Amal Khalifa, 2014


Flowcharts
18

 Graphical representations of algorithms


 Tool to translate algorithms into software
 A Flowchart uses easy-to-understand
symbols to represent actions on data
and the flow of data
 Flowcharts aid in breaking down a
problem into simple steps

Dr. Amal Khalifa, 2014


Flowchart Symbols
19
Name Symbol Use in Flowchart

Oval Denotes the beginning or end of the program

Parallelogram Denotes an input operation

Rectangle Denotes a process to be carried out


e.g. addition, subtraction, division etc.

Diamond Denotes a decision (or branch) to be made.


The program should continue along one of
two routes. (e.g. IF/THEN/ELSE)

Hybrid Denotes an output operation

Dr. Amal Khalifa, 2014


Flow line Denotes the direction of logic flow in the program
flowcharting
20

Dr. Amal Khalifa, 2014


Example
21

 Example 1: Write an algorithm and


draw a flowchart to convert the length in
feet to centimeter.

hint: I feet = 30 cm

Dr. Amal Khalifa, 2014


Pseudocode
22

 Input the length in feet (Lft)


 Calculate the length in cm (Lcm) by
multiplying LFT with 30
 Print length in cm (LCM)

Dr. Amal Khalifa, 2014


Algorithm
23

Flowchart
 Step 1: Input Lft START

 Step 2: Lcm  Lft x 30 Input


Lft
 Step 3: Print Lcm
Lcm  Lft x
30

Print
Lcm

STOP

Dr. Amal Khalifa, 2014


Example 2
24

Write an algorithm and draw a flowchart


that will read the radius of a circle and
calculate its area.

Dr. Amal Khalifa, 2014


Example 2
25

Pseudocode
 Input the radius (r) of a circle

 Calculate the area (A) :

A  Pi x r x r
 Print A

Dr. Amal Khalifa, 2014


Example 2
26

Algorithm START

 Step 1: Input r Input


 Step 2: A  Pi x r x r r

 Step 3: Print A
A  Pi x r x r

Print
A

STOP

Dr. Amal Khalifa, 2014


Example 3
27

 Write an algorithm and draw a flowchart


that will calculate the roots of a
quadratic equation
ax 2  bx  c 0

Hint: the roots are:


x1 = (–b + d)/2a and
x2 = (–b
b 2  –4ac
d)/2a
where, d = sqrt ( )

Dr. Amal Khalifa, 2014


Example 3
START
28

 Algorithm: Input
a, b, c

Step 1: Input the coefficients (a, b, d  sqrt(b x b – 4 x a x


c) of the quadratic equation c)

Step 2: d  sqrtb 
( b  4 a c ) x1 (–b + d) / (2 x a)
Step 3: x1  (–b + d) / (2 x a)
X2  (–b – d) / (2 x a)
Step 4: x2  (–b – d) / (2 x a)
Step 5: Print x1, x2 Print
x1 ,x2

STOP
Elements of a Computer
29
System

Hardware

Computer

Software

dr. Amal Khalifa,Fall14


Hardware
30

dr. Amal Khalifa,Fall14


Memory Unit
31

 Ordered sequence of cells or locations


Bi t s &
 Stores instructions and data in binaryBytes
 Types of memory
 Read-Only Memory (ROM)
 Random Access Memory (RAM)

dr. Amal Khalifa,Fall14


Click icon to add picture

32 Binary Data
Bit: A binary digit 0 or 1.
A sequence of eight bits is called a byte.
dr. Amal Khalifa,Fall14
ASCII Code
33

Every letter,
number, or
special symbol
(such as * or {)
on your
keyboard is
encoded as a
sequence of
bits, each
having a
unique
representation.

The most
commonly
used American
Standard Code
for Information
Interchange
(ASCII).

dr. Amal Khalifa,Fall14


Central Processing Unit
34
(CPU)
 Executes stored instructions
 Arithmetic/Logic Unit (ALU)
 Performs arithmetic and logical
operations
 Control Unit
 Controls the other components
 Guarantees instructions are
executed in sequence

dr. Amal Khalifa,Fall14


Input and Output Devices
35

 Interaction with humans


 Gathers data (Input)
 Displays results (Output)

dr. Amal Khalifa,Fall14


Software
36

System programs Application programs

loads first when you turn on


perform specific


your PC
 Also called the operating tasks
system.
 The operating system monitors  Examples :
the overall activity of the
computer and provides Word processors

services, such as memory  spreadsheets,
management, input/output
activities, and storage and
management.
 games
Both operating systems and application
programs are written in programming
languages. dr. Amal Khalifa,Fall14
Are Computers Intelligent?
37

 Do we really need to be involved in


programming computers?
 They have beaten world chess champions.
 They help predict weather patterns.
 They can perform arithmetic quickly.
 So, a computer has an IQ of _____.

dr. Amal Khalifa,Fall14


What is Computer
38
Programming?
 Planning or scheduling a sequence of
steps for a computer to follow to perform
a task.
 Basically, telling a computer what to do
and how to do it.
 A program:
 A sequence of steps to be performed by a
computer.
 Expressed in a computer language.

dr. Amal Khalifa,Fall14


Computer Languages
39

 A set of
 Symbols (punctuation),
 Special words or keywords (vocabulary),
 And rules (grammar)
used to construct a program.

dr. Amal Khalifa,Fall14


Evolution of Programming Languages
40

 Languages differ in
 Size (or complexity)
 Readability
 Expressivity (or writability)
 "Level"
 closeness to instructions for the CPU

dr. Amal Khalifa,Fall14


Machine Language
41

 Binary-coded instructions
Address Contents
 Used directly by the CPU
2034 10010110
 Lowest level language
2035 11101010
 Every program step is ultimately
2036 00010010
a machine language instruction2037 10101010
2038 10010110
2039 11101010
2040 11111111
2041 01010101
2042 10101101

dr. Amal Khalifa,Fall14


Assembly Language
42

 Each CPU instruction is labeled with a mnemonic.


 Very-low level language
 Almost 1 to 1 correspondence with machine language
 Assembler: A program that translates a program
written in assembly language into an equivalent
program in machine language.
Sample Program

MUL X,10
ADD X,Y
Mnemonic Instruction STO Z,20
ADD 10010011 SUB X,Z

dr. Amal Khalifa,Fall14


Click icon to add picture

Examples of Instructions in Assembly Language and


43 Machine Language

dr. Amal Khalifa,Fall14


High-Level Languages
44

 Closer to natural language


 Each step maps to several
machine language
instructions
 Easier to state and solve
problems
 Compiler: A program that
translates a program
written in a high-level
language into the
equivalent machine
language.
dr. Amal Khalifa,Fall14
Examples of High-Level
45
Languages
Language Primary Uses
Pascal Learning to program
C++ General purpose
FORTRAN Scientific programming
PERL Web programming, text processing
Java Web programming, application
programming
COBOL Business

dr. Amal Khalifa,Fall14


The java Language
46

source
program.

Saved in
File
ClassName
.java

dr. Amal Khalifa,Fall14


The Code life Cycle!!
47

Edit  compile  run

dr. Amal Khalifa,Fall14


Click icon to add picture

48 Processing a java program

dr. Amal Khalifa,Fall14


IDE
49

 The programs that you write in Java are


typically developed using an integrated
development environment (IDE).

dr. Amal Khalifa,Fall14


50 That’s all for Today!!
Text book
[1] chapter 1 (pages 1-13)

dr. Amal Khalifa,Fall14

You might also like