Computer Programming Skills Lecture Notes PDF
Document Details
Uploaded by Deleted User
Umm Al-Qura University
Tags
Summary
These lecture notes cover computer programming skills, specifically focusing on introductory material related to computer programming paradigms. The document includes details on numbering systems, problem-solving techniques like flowcharts and pseudocode, as well as coding and implementation.
Full Transcript
COMPUTER PROGRAMMING SKILLS (48021503-3 ) CHAPTER 1: INTRODUCTION TO COMPUTER PROGRAMMING PARADIGM Second Term (1437-1438) Department of Computer Science Foundation Year Program Umm Al Qura University, Makkah Table of Contents – Objectives & Outline Objectives 1. Use...
COMPUTER PROGRAMMING SKILLS (48021503-3 ) CHAPTER 1: INTRODUCTION TO COMPUTER PROGRAMMING PARADIGM Second Term (1437-1438) Department of Computer Science Foundation Year Program Umm Al Qura University, Makkah Table of Contents – Objectives & Outline Objectives 1. Use and convert between numbering systems 2. Define and analysis problems 3. Express simple solutions by algorithms 4. Use flowchart to represent algorithms 5. Use pseudcode to represent algorithms Umm al-Qura University Chapter 1 (Scientific) 1/43 Table of Contents – Objectives & Outline Outline 1. Numbering systems ◦ Decimal numbers ◦ Binary numbers ◦ Hexadecimal numbers ◦ Other bases ◦ Conversion between decimal, binary and hexadecimal bases 2. Problem solving and programming ◦ Introduction to problems solving ◦ Defining and specifying the problem ◦ Analyse the problem ◦ Algorithm development : Flowchart and Pseudocode ◦ Coding and implementing ◦ Testing and debugging Umm al-Qura University Chapter 1 (Scientific) 2/43 Numbering systems – Overview Introduction # Humans use decimal numbers, or base-10. # Computers machine use binary numbers, or base-2 numbering system. # The binary system is suggested to take advantage of the physical characteristics of electronic circuitry, by dealing with the electronic states of ON and OFF. # Computers operate in binary and communicate to us in decimal. # A special program translates decimal into binary on input, and binary into decimal on output. Umm al-Qura University Chapter 1 (Scientific) 3/43 Numbering systems – Overview Base 10 (Decimal numbers) # 10 elements in this set : {0,1,2,3,4,5,6,7,8,9}. # (229)10 is derived from base 10 and contains 2 elements: 2 (repeated 2 times) and 9. Base 2 (Binary numbers) # 2 elements in this set : {0,1}. # (10011)2 is derived from base 2 and contains 2 elements: 1 (used 3 times) and 0 (used 2 times). Umm al-Qura University Chapter 1 (Scientific) 4/43 Numbering systems – Overview Other bases # Programmers, computer engineers and computer specialist use Octal (base-8) and hexadecimal (base-16), by takes a snapshot of the contents of RAM and secondary storage at a given moment in time. # To reduce the confusion of seeing only 1 and 0 on the output, the hexadecimal (base-16) and octal (base-8) numbering system is used as shorthand to display the binary contents. Umm al-Qura University Chapter 1 (Scientific) 5/43 Numbering systems – Overview Base 8 (Octal numbers) # 8 elements in this set : {0,1,2,3,4,5,6,7} # (107)8 is derived from base 8 and contains 3 elements: 1,0 and 7. Base 16 (Hexadecimal numbers) # 16 elements in this set: {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F} where A=10, B=11, C=12, D=13, E= 14, F=15. # We use A as 10 to avoid confusion with 1 and 0. # (10A)16 is derived from base 16 and contains 3 elements: 1, 0 and A. Umm al-Qura University Chapter 1 (Scientific) 6/43 Numbering systems – Overview Decimal Binary Hexadecimal 0 0 0 1 1 1 2 10 2 3 11 3 4 100 4 5 101 5 6 110 6 7 111 7 8 1000 8 9 1001 9 10 1010 A 11 1011 B 12 1100 C 13 1101 D 14 1110 E 15 1111 F Umm al-Qura University Chapter 1 (Scientific) 7/43 Numbering systems – Conversion Among Bases Convert Decimal to Binary 1. Divide by 2, keep track of the remainder until last possible dividing. 2. Rotate the remainders: 2.1 First remainder is the first bit. 2.2 Last remainder is the last bit. Figure 1: Convert (29)10 to (11101)2 TO DO Exercice 1 in Homework 1 Umm al-Qura University Chapter 1 (Scientific) 8/43 Numbering systems – Conversion Among Bases Convert Decimal to Hexadecimal 1. Divide by 16, keep track of the remainder until last possible dividing. 2. Rotate the remainders: 2.1 First remainder is the first bit. 2.2 Last remainder is the last bit. Figure 2: Convert (1234)10 to (4D2)16 TO DO Exercice 2 in Homework 1 Umm al-Qura University Chapter 1 (Scientific) 9/43 Numbering systems – Conversion Among Bases Convert Binary to Decimal 1. Multiply each bit by 2n , where n is the weight1 of the bit. 2. Add all results. Figure 3: Convert (10 1011)2 to (43)10 TO DO Exercice 3 in Homework 1 1The weight is the position of the digit, starting from 0 on the right to left Umm al-Qura University Chapter 1 (Scientific) 10/43 Numbering systems – Conversion Among Bases Convert Binary to Hexadecimal 1. Group each four digits, starting from right, 2. Convert to its equivalent value in decimal, 3. The final result is the Hexadecimal number. Figure 4: Convert (10 1011 1011)2 to (2BB)16 TO DO Exercice 4 in Homework 1 Umm al-Qura University Chapter 1 (Scientific) 11/43 Numbering systems – Conversion Among Bases Convert Hexadecimal to Decimal 1. Multiply each digit by 16n , where n is the weight of the digit. 2. Add the results. Figure 5: Convert (ABC)16 to (2748)10 TO DO Exercice 5 in Homework 1 Umm al-Qura University Chapter 1 (Scientific) 12/43 Numbering systems – Conversion Among Bases Convert Hexadecimal to Binary Convert each hexadecimal digit to a 4-bit equivalent binary representation Figure 6: Convert (10AF)16 to (1 0000 1010 1111)2 TO DO Exercice 6 in Homework 1 Umm al-Qura University Chapter 1 (Scientific) 13/43 Numbering systems – Arithmetic in binary Overview # We do binary arithmetic, as well as that of other numbering systems, in the same way that we do decimal arithmetic. The only difference is that we have fewer (binary) digits to use. # The following figure presents an example of Binary calculations. Figure 7: Binary Arithmetic example Umm al-Qura University Chapter 1 (Scientific) 14/43 Problem solving and programming – Introduction to problem solving Definition # A problem is a task that requires the learner to reason through a situation that will be challenging but not impossible. # Problem solving means engaging in a task for which the solution method is not known in advance, # It encompasses exploring, reasoning, strategic, estimating, conjecturing, testing, explaining, and proving. # There is many types of problems, but in computer sciences problems can be divided into two categories: ◦ Problems that can be solve with a series of actions. ◦ Problems that can be solve with knowledge and experience, and a process of trial and error. Umm al-Qura University Chapter 1 (Scientific) 15/43 Problem solving and programming – Introduction to problem solving How do you solve problems? 1. Defining and specifying the problem 2. Analyse the problem 3. Algorithm development 4. Coding and implementing 5. Testing and debugging Umm al-Qura University Chapter 1 (Scientific) 16/43 Problem solving and programming – Defining and specifying the problem In order to define and specify the problem, we have to answer these questions: 1. What the computer program do ? 2. What tasks will it perform ? 3. What kind of data will it use, and where will get its data from ? 4. What will be the output of the program ? 5. How will the program interact with the computer user ? Umm al-Qura University Chapter 1 (Scientific) 17/43 Problem solving and programming – Defining and specifying the problem Definition Specifying the problem requirements forces you to state the problem clearly and unambiguously and to gain a clear understanding of what is required for its solution. Figure 8: Specifying the problem in Oneshot Umm al-Qura University Chapter 1 (Scientific) 18/43 Problem solving and programming – Defining and specifying the problem EXAMPLE Retrieving 500 riyals from bank ATM, 1. What the computer program do ?.............................................................................................. 2. What tasks will it perform ?.............................................................................................. 3. What kind of data will it use, and where will get its data from ?.............................................................................................. 4. What will be the output of the program ?.............................................................................................. 5. How will the program interact with the computer user ?.............................................................................................. Umm al-Qura University Chapter 1 (Scientific) 19/43 Problem solving and programming – Analyse the problem Identify the problem # Inputs: the data you have to work with; # Processing: Any operation that generates the output from the input; # Outputs: the desired results; Figure 9: Analyse the problem Umm al-Qura University Chapter 1 (Scientific) 20/43 Problem solving and programming – Analyse the problem EXAMPLE Calculate the area of a rectangle: # Input : Length, Width # Processing: AreaRec=Length*Width # Output: AreaRec Figure 10: Area of a rectangle Umm al-Qura University Chapter 1 (Scientific) 21/43 Problem solving and programming – Algorithm development Definition # An Algorithm is a finite set of instructions that specify a sequence of operations to be carried out in order to solve a specific problem or class of problems, # An algorithm can be expressed in many different notations, including flowchart, and pseudocode. Umm al-Qura University Chapter 1 (Scientific) 22/43 Problem solving and programming – Algorithm development How developing an algorithm ? We write step-by-step solution and then we verify that the algorithm solves the problem as intended. 1 START 3 a