Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS2301:Computer Programming 2

Similar presentations


Presentation on theme: "CS2301:Computer Programming 2"— Presentation transcript:

1 CS2301:Computer Programming 2

2 Programming Languages and
Introduction to Computers Programming Languages and Algorithms

3 OBJECTIVES In this Chapter we will learn: 1.1 Introduction 1.2 Computers: What is a Computer? 1.3 Computers: Hardware and Software? 1.4 Computer Organization 1.5 Classification of programming languages 1.6 Machine Languages, Assembly Languages and High-Level Languages 1.7 Programming Language, computer program and Computer Programmer 1.8 Program developing life cycle? 1.9 What do we mean by algorithm? 1.10 Examples of algorithms

4 1.2 Computers: What is a Computer?
Computer Is a device capable of performing computations and making logical decisions. Another definition: (often referred to as hardware) are controlled by software (i.e., the instructions you write to command the computer to perform actions and make decisions).

5 1.3 Computers: Hardware and Software (cont.)
Set of instructions that tells the computer to perform specific tasks. Computers process data under the control of sets of instructions called computer programs. These programs guide the computer through orderly sets of actions specified by people called computer programmers. Software may be divided into: Operating systems e.g. (Windows 7) Application programs e.g. (Microsoft word)

6 1.3 Computers: Hardware and Software?
Computer hardware is the collection of physical elements that constitutes a computer system and assist to the input, process, storage, output …. Various devices comprising computer Keyboard, screen, mouse, disks, memory, CD-ROM, processing units, etc.

7 1.4 Computer Organization
Five logical units of computer system Input unit (Mouse, keyboard) Output unit (Printer, monitor, audio speakers) Memory unit (Retains input and processed information) Central processing unit (CPU) which consists of: Control unit (Supervises operation of other devices) Arithmetic and logic unit (ALU):Performs arithmetic calculations and logic decisions. Secondary storage unit (Hard drives, floppy drives)

8 1.4 Computer Organization (Cont.) Hardware Components

9 1.4 Computer Organization (Cont.) Hardware Components

10 1.4 Computer Organization (Cont.) Hardware Components in Actions
Execution of an Instruction

11 1.5 The Internet and the World Wide Web
A collection of interconnected networks, all freely exchanging information. Or Global network of computers. Internet has become one of the world’s premier communication mechanisms. World Wide Web Also called the Web, WWW, or W3 Organizes Internet resources throughout the world into a series of menu pages, or screens, that appear on your computer.

12 1.6 Classification of programming languages

13 1.7 Programming Languages
Three types of computer languages 1- Machine language Language of Computer. Only language computer directly understands “Natural language” of computer Defined by hardware design Binary digit (bit): The digit 0 or 1 Binary code: A sequence of 0s and 1s Byte: A sequence of eight bits.

14 1.7 Programming Languages(cont)
Early computers were programmed in machine language. To calculate wages= rates * hours in machine language //load // multiply // store

15 1.7 Programming Languages(cont)
2- Assembly language English-like abbreviations representing elementary computer operations. Clearer to humans Incomprehensible to computers Example load basepay add overpay store grosspay Assembler: Translates a program written in assembly language in to machine language.

16 Example of instructions in Assembly Language and Machine Language
1.7 Programming Languages(cont) Example of instructions in Assembly Language and Machine Language Machine language Assembly Language 100100 LOAD 100010 STOR 100110 MULT 100101 ADD 100011 SUB

17 1.7 Programming Languages(cont)
3- High-level languages Include Basic, FORTRAN, COBOL, Pascal, C, C++, C# and Java Similar to everyday English Uses common mathematical notations The equation: wages = rate* hours can be written in java as: Wages = rate * hours; Another Example: grossPay = basePay + overTimePay Compiler: translates a program written in a high-level language in to machine language.

18 1.8 Programming Language, Computer Program, and Computer Programmer
Is a process of problem solving by using a programming language. Programming Language: A set of rules, symbols and special words used to write computer program. Computer program:  is a list of instructions, written to perform a specified task on a computer Syntax: Rules that specify which statements (instructions) are legal. Algorithm - Step–by–step problem solving processes using informal language.

19 1.8 Programming Language, Computer Program, and Computer Programmer
Examples of Programming Languages: Fortran COBOL Pascal Ada Basic C C++ Objective-C Visual Basic Visual C# PHP Python JavaScript Java

20 Computer Programmer A programmer, computer programmer, developer, coder, or software engineer: is a person who design, writes and maintains computer software.

21 1.9 What is program developing life cycle?

22 1.9 What is program developing life cycle?
step1: Analyze the problem. - Outline the problem and its requirements. - Design steps (algorithm) to solve the problem. Step 2: Implement the algorithm(coding). - Implement the algorithm code. - Verify that the algorithm works. Step 3: Maintenance (when errors occurs) - Use and Modify the program if the problem domain changes.

23 How Problem Analysis could be done
Understand the overall problem. Understand problem requirements. - Does program require user interaction? Example: When you calculate the area of ​​a rectangle What do we require from the user? Enter the length of the rectangle, width of the rectangle - Does program manipulate data? Example: Equation calculating the area of ​​a rectangle Area= length * Width - What is output? Note If the problem is complex, divide into sub problems. Analyze each sub problem as above.

24 1.9.1 Defining the Problem Keyboard Screen Processing input data
The problem must be defined in terms of: Input: raw data to be processed. Output: production of useful information. processing: converting or transforming data into useful outputs. Keyboard Screen Processing input data output data

25 1.9.2 Input and Output Inputs Outputs
Can come from many sources, such as users, files, and other programs Can take on many forms, such as text, numbers, graphics, and sound Outputs Can also take on many forms, such as numbers, text, graphics, sounds, or commands to other programs

26 1.9.3 The Problem Analysis-Coding-Execution Cycle
Stages of programming

27 1.9.3 The Problem Analysis-Coding-Execution Cycle

28 Typical Java development environment.

29 representing algorithms
The Algorithm Methods for representing algorithms Pseudo code Flow Chart Note: Before use any two methods, you must specify the input, processing, and output

30 1.10.2 The Algorithm- Pseudo Code
An informal language similar to English Is not considered programming language. Helps programmers develop algorithms Does not run on computers Should contain input, output and calculation actions Can be easily converted for different programming languages ​​such as Pascal, Java, C++.

31 Example 1: Calculate Area = length*width
Using pseudo code ,write suitable algorithm that calculate the area and perimeter of rectangle and print them. Area=length * width Perimeter=2(length * width) Prompt the user Input Length and width Calculate Area = length*width Calculate Perimeter = 2*( length + width) Output Area Output Perimeter End

32 Calculate Average = Sum/5
Example 2: Using pseudo code write suitable algorithm that calculate and output Sum and Average of 5 numbers Input five number x1, x2, x3, x4, x5 Calculate Sum = x1+x2+x3+x4+x5 Calculate Average = Sum/5 Output Sum Output Average end

33 Using pseudo code ,write suitable algorithm:
Example 3: Using pseudo code ,write suitable algorithm: If the student's degree is greater than or equal 60, print “pass” else print “fail”. Input grade Check if (grade > 60) then Print "passed" Else Print "failed“ End

34 Example4: Using Pseudo code, Write suitable algorithm:
Calculate and print the average of temperature degrees for the following readings T1, T2, T3. Answer: Input T1, T2, T3 Calculate avg= (T1 + T2 + T3)/3 Output avg End

35 1.10.3 The Algorithm-Flow chart
Is a graphical way that explain the steps to solve problem and how they relate to each other (it is a symbolic representation of the algorithm).

36 Flow chart Start or Stop Program Input or Output
Process, Calculate, Storage Used to express logical operations or operations report (Condition) Arrows determine the direction of the program's progress Connection

37 Condition Branching No yes Compare

38 Condition Rotation

39 start Input : stop Sum = T1+T2+T3 Avg = sum/3 Example 5: claculation:
Using flow chart, Write suitable algorithm: Calculate and print the average of temperature degrees for the following readings T1, T2, T3. start Input T1, T2, T3 Input : T1, T2, T3 claculation: Sum = T1+T2+T3 Avg = sum/3 Output: Print Avg Sum = T1+T2+T3 Avg = sum/3 Print avg stop

40 Example 6: Using pseudo code and flow chart to write suitable algorithm: Calculate the average for temperature for the following readings T1, T2, T3. IF the average is greater than 15 print the average, else print the weather is cold. start input T1, T2, T3 Sum= T1+T2+T3 Start Input : T1,T2,T3 Process and output Sum = T1+T2+T3 Avg = sum/3 If avg > 15 then Print avg Else Print “cold” End if end Avg = sum/3 No Yes avg > 15 Print “cold” Print avg Stop

41 Flow chart Example7: End
Using flow chart to write an algorithm. Enter number (X) and find the value (F), as shown in the following equations: F= { x x >=0 x x< 0 start Input x Yes No X <= 0 F = x-1 F= x+1 Print F , x End

42 Note: (if X=0 enter value of X again) Pseudo code input: X process:
Example 8: Using pseudo code and flow chart to write an algorithm. Enter number (X) and then find and print the value (Y), as shown in the following equation: Y=(X-2)/X Note: (if X=0 enter value of X again) Pseudo code input: X process: if x=0 Re-enter the new value of x because you can not divide by 0 output: Y Flow Chart start Input X If X=0 yes No Y=(X-2)/X Print Y stop

43 Discuss Using pseudo code and flow chart to write an algorithm that :
Accept 3 readings of temperature degrees and find the average then check the average if avg less than 15 : print the “cool air” if avg between 15 and 25: Print “moderate air” And if the avg is not verify the previous conditions: print “hot air”

44 Home Work (1) Using pseudo code and flow chart to write an algorithm that calculate the area of ​​a rectangle print it. Note: area of ​​the rectangle = length × width. Using pseudo code and flow chart to write an algorithm that find the area of ​​a circle which its radius (R) and print it. Note: The area of ​​a circle is equal to π * R2, where π is a constant value of approximately 3.14. Using the methods (pseudo code and flow chart), we need to find and print the vicinity of the football stadium, and determine whether if vicinity is greater than or equal to 600 m then print (international stadium) , and if vicinity is less than 600 then print (local stadium ), Note: The perimeter of the rectangle is equal to (length + width)×2 .

45 End


Download ppt "CS2301:Computer Programming 2"

Similar presentations


Ads by Google