• No results found

CHAPTER 1INTRODUCTION

N/A
N/A
Protected

Academic year: 2020

Share "CHAPTER 1INTRODUCTION"

Copied!
26
0
0

Loading.... (view fulltext now)

Full text

(1)

CHAPTER 1

INTRODUCTION

1nd Semester 1437-1438 H

Shaqra University

College Of science and humanities CS 217

(2)

What Is a Computer?

◻ Computer

Executes statements (computations/logical decisions)

◻ Hardware :Physical devices of computer system

◻ Software: Programs that run on computers

(3)

Computer Organization

3

◻ Six logical units of computer system

Input unit

■ Mouse, keyboard

Output unit

■ Printer, monitor, audio speakers

Memory unit

■ Retains input and processed information

Arithmetic and logic unit (ALU)

■ Performs calculations

Control unit

■ Supervises operation of other devices

Secondary storage unit

(4)

What a computer program is?

4

◻ For a computer to be able to perform specific tasks (i.e. print what grade a student got on an exam), it must be given instructions to do the task.

◻ The set of instructions that tells the computer to

perform specific tasks is known as a computer program

◻ These programs guide the computer through orderly sets of actions specified by people called computer programmer

(5)

Machine Languages, Assembly Languages

and High-Level Languages

◻ Machine language

“Natural language” of computer component Machine dependent

◻ Assembly language

English-like abbreviations represent computer operations Translator programs convert to machine language

◻ High-level language

Allows for writing more “English-like” instructions ■ Contains commonly used mathematical operations

(6)

An Overview Of Computer

Languages

6

1-Machine language 2-Assembly language

3-High-level language

representation Collection of binary numbers

Symbolic form of machine language (I.e. symbolic names are used to represent

operations, registers

& memory locations)

combines algebraic expressions with symbols taken from English language(ex. C, Pascal, FORTRAN, …etc) examples 10100001 00000000 00000000 00000101 00000100 00000000 10100011 00000000 00000000 MOV AX,A MOV A , AX ADD AX, A=A+4 *c

how does the computer understand ? Directly understood by a computer Assembler convert to machine language Compiler or (interpter ) convert to machine language Easier to use More powerful

(7)

Levels of Program Development

7

Human thought

Pseudo-Natural Language (English, Arabic)

High Level Programming Language

(C, C++, Java, …)

(8)

The Programmer’s Algorithm

8

An algorithm is a finite sequence of instructions

that produces a solution to a problem.

The programmer’s algorithm:

Define the problem.

Plan the problem solution. Code the program.

Compile the program. Run the program.

(9)

9

1-Defining the Problem

◻ The problem must be defined in terms of:

Input: Data to be processed. Output: The expected result.

■ Look for nouns in the problem statement that suggest output and input.

and processing: The statements to achieve.

■ Look for verbs to suggest processing steps.

Keyboard Processing Screen

(10)

10

Input and Output

Inputs

Can come from many sources, such as users, files, and other programs

Can take on many forms, such as text, graphics, and sound

Outputs

Can also take on many forms, such as numbers, text, graphics, sounds, or commands to other programs

(11)

11

Example 1

Area and Perimeter of a rectangle

Input

Length width

Processing

Area = length*width

Perimeter = 2*( length + width)

Output

Area

(12)

Page 12

Example 2

Sum and Average of 5 numbers

Input five number x1, x2, x3, x4, x5 ◻ Processing Sum = x1+x2+x3+x4+x5 Average = Sum/5 ◻ Output Sum Average

(13)

Page 13

Example 3

Area and Perimeter of a circle

Input

Radius PI

Processing

Area = PI * Radius * Radius Perimeter = 2 * PI * Radius

Output

Area

(14)

2-Planning the Solution

14

◻ When planning, algorithms are used to outline the solution steps using English like statements, called

pseudocode.

● A flowchart is useful for the graphical representation

of an algorithm.

● They are drawn using rectangles, diamonds, ovals, and small circles.

(15)

Pseudocode

Pseudocode is a detailed description of what a

computer program must do, expressed in an

English like language rather than in a programming

language.

(16)

Pseudocode Example

16

Write a Program to Print the Sum of two integer Numbers

1. Start the program

2. Read the first number and save in the variable ( N1 ) 3. Read the second number and save in the variable (

N2 )

4. Sum the both numbers and save the result in the

variable ( Sum ) Sum = N1 + N2

5. Print the variable ( Sum ) 6. End the program

(17)

Write a Program to Print the Sum of two

integer Numbers

1. Start the program

2. Read the first number and save in

the variable ( N1 )

3. Read the second number and save in

the variable ( N2 )

4. Sum the both numbers and save the

result in the variable ( Sum ) Sum = N1 + N2

5. Print the variable ( Sum )

6. End the program

17 start Read N1 Read N2 Sum = N1 + N2 Print Sum End

(18)

3-Coding the Program

18

◻ Coding is writing the program in a formal language called Programming Language.

Programming Language : A set of rules, symbols and special words used

to write statements.

◻ The program is written by translating the algorithm steps

into a programming language statements.

◻ The written program is called Source code and it is saved in a file with “.cpp” extension.

Program Coding Algorithm Pseudocode Source Code (The “.cpp”) Translating

(19)

Why Coding in Programming Languages

19

◻ We write computer programs (i.e. a set of

instructions) in programming languages such as C, C++, and Java.

◻ We use these programming languages because

they are easily understood by humans

◻ But then how does the computer understand the

(20)

4-Compiling Computer Programs

20

Computers do not understand programs written in programming languages such as C, C++ and Java

Programs must first be converted into machine code that the computer can run

◻ A Software that translates a programming language statements into machine code is called a compiler

In C , Preprocessor program, execute automatically

before the compiler translation phase begin

Preprocessor indicate that certain manipulations are to be performed on the program before compilation.

Machine code

Program Source code

Machine Code

Translating Compiling

(21)

Programming Language Compiler

21

A compiler is a software that:

Checks the correctness of the source code according to the language rules.

Syntax errors are raised if some rules were violated.

Translates the source code into a machine code if no errors were found.

(22)

5-Running The Program

22

◻ Before running..

links the object code with the code for the missing functions to produce an executable image (with no missing pieces) , this is called link phase .

If the program compiles and links correctly, a file called a.out is produced.

Before a program can be executed, the program must first be placed in memory this called load phase .

the computer, under the control of its CPU,

executes the program one instruction at a time

(23)

6-Testing and Debugging the Program

23

Testing

Be sure that the output of the program conforms with the input.

There are two types of errors:

Logical Errors: The program run but provides wrong output.

Runtime errors: The program stop running suddenly when asking

the OS executing a non accepted statement (divide by zero, etc).

Debugging

(24)

24

Basics of a Typical C++ Environment

Phases of C++ Programs: 1. Edit 2. Preprocess 3. Compile 4. Link 5. Load 6. Execute Loader Primary Memory Program is created in the editor and stored on disk.

Preprocessor program processes the code.

Loader puts program in memory.

CPU takes each instruction and executes it, possibly storing new data values as the program executes.

Compiler

Compiler creates object code and stores it on disk.

Linker links the object code with the libraries, creates a.out and stores it on disk Editor Preprocessor Linker CPU Primary Memory . . . . . . . . . . . . Disk Disk Disk Disk Disk

(25)

Object-–oriented design (OOD)

Basic object technology concept:

Objects people, animals, planes, buildings, computers

and so on.

Attributes (e.g., size, shape, colour and weight)

Behaviors (e.g., a ball rolls, inflates and deflates,

sleeps)

Different objects can have similar attributes and

can exhibit similar behaviors.

(26)

The end of class

Reference

Textbook: C++ how to program – fifth edition –

Chapter 1

Next lecture will we learn

Introduction to C++, Data Types & Variables &

Constant

References

Related documents

-A notation of a algorithm and data structures are called a programming language..

With a good research experience, she has presented research papers in IIM conferences and published several papers in various national and international journals some of

(The default value is the same as the Extension General Use field on the Site Details: Automatic Design Definition window at the time that the NE is created. Choices displayed will

“In the plan of care for the Medicare payment episode for which this assessment will define a case-mix group, what is the indicated need for therapy visits (total of reasonable

The ordinal regression method was used to evaluate the relationship between ICT performance of the overall production procedures in Greek SMEs (enhancement of

This document describes how to insert a popup window of the TimeTrade appointment widget while keeping your own web page shaded in the background.. Using this popup widget

 Every structure in programming language has a precise form, called its syntax.  Every structure in programming language has a precise meaning,

[11, Theorem II.2.1] to deduce that 23 uniquely determines the measure mN and so every limit measure l must equal mN : & We remark that for convex domains G; results concerning