Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Programming Enter Created by N. Nembhard.

Similar presentations


Presentation on theme: "Introduction to Programming Enter Created by N. Nembhard."— Presentation transcript:

1

2 Introduction to Programming Enter Created by N. Nembhard

3 Main Menu What is a Computer Program? Basic Elements of Any Program The Main Steps in Developing a Program Basic Control Structures Types of Errors End Previous PageNext PageHome Page Created by N. Nembhard

4 Pseudocode Pseudocode consists of English like statements that describe the processing steps of a program in paragraph form. It is an informal language that is easy and user friendly to use. It is not an actual programming language and are not executed on computers. They can help you think out a program before attempting to write it in a programming language. End Next Previous Home Created by N. Nembhard

5 Home Algorithms A computer is only a tool that can do what it is specifically told to do. We can direct the computer to do what we want by specifying our needs in a discrete step-by-step manner. An algorithm must be developed, which is a step-by-step procedure to solve a problem. End Next Previous Created by N. Nembhard

6 An algorithm must meet the following requirements: –Use operations from only a given set of basic operations –Produce the problem solution, or answer, in a finite number of such operations. Algorithms Home End Next Previous Created by N. Nembhard

7 High Level Languages There are many programming languages – some examples are Basic, c, c++, Visual Basic, Java, Pascal. These are high level languages which are closer to human languages. Programs can also be written in low level languages such as assembly language and is closer to the language of the computer. End Next Previous Home Created by N. Nembhard

8 Exit Home Next Previous What is a computer Program? A program is an organized list of instructions that when executed causes the computer to behave in a predetermined manner. It is a step-by-step list of instructions written in a particular computer programming language. Without programs, computers are useless. Created by N. Nembhard

9 End Home Next Previous Main Steps in Developing a Program 1.Define the problem 2.Outline the solution 3.Develop the outline into an algorithm 4.Test the algorithm for correctness 5.Code the algorithm into a specific programming language 6. Run the program on the computer 7.Document and maintain the program Created by N. Nembhard

10 Exit Home Next Previous The Basic Elements of any Program Input Processing Output The basic elements of any program are: Created by N. Nembhard

11 End Home Next Previous Input This is entering or sending data to the computer. The most frequent way of entering data is by using the keyboard. Created by N. Nembhard

12 End Home Next Previous Processing The processor or microprocessor is the part of the computer that reads, interprets and executes the program instructions. Processors are integrated circuits that contain transistors and other electronic components. It is a small chip that functions as the brain of the computer. The processor is also called the Central Processing Unit (C.P.U) Created by N. Nembhard

13 End Home Next Previous Output Sending or displaying data to the user. Common output devices includes the monitor and the printer. Created by N. Nembhard

14 What Have You Learnt? Previous PageHome PageNext Page End Created by N. Nembhard

15 Quiz Click on the correct answer: A set of English like statements that is used as an informal language is called: Algorithm Psuedocode Computer program A B C Previous PageHome PageNext Page end Created by N. Nembhard

16 Quiz Click on the correct answer: Which of the following is NOT a high level language? Basic Assembly C++ A B C Previous PageHome PageNext Page end

17 Quiz Click on the correct answer: The basic elements of any program are: Input, storing, processing Input, storing,output Input, processing, output A C B Previous PageHome PageNext Page end Created by N. Nembhard

18 Quiz Is the following statement true or false? Click on true if the statement is correct or false if it is incorrect. A computer program is a step-by-step list of instructions written in a particular computer programming language. Previous PageHome PageNext Page end TrueFalse Created by N. Nembhard

19 End of Quiz! Previous PageHome PageNext Page end Created by N. Nembhard

20 Errors that programmers usually make includes: Semantic Errors Syntax Errors Logic Errors End Next PageHome PagePrevious Page Types of Errors Created by N. Nembhard

21 Semantic Errors This is where meaning of the language is not obeyed. For example, what the words really say or what functions are requested in the command. Previous PageHome PageNext Page End Created by N. Nembhard

22 Syntax Errors Violations of the language. Syntax error refers to the spelling and grammar of a programming language. The particular programming language used expects words entered in a specific form. The expected form is called the syntax. Each program defines its own syntactical rules that control which words the computer understands, which combinations of words are meaningful and what punctuation is necessary. Previous Page Home PageNext Page End Created by N. Nembhard

23 Logic Errors A logic error occurs when a step in the program logic is incorrect e.g. an average program will produce a wrong answer if the sum of the numbers is divided by a number other than the total count of the numbers. Previous PageHome PageNext Page End Created by N. Nembhard

24 Basic Control Structures The basic control structures are: Simple Sequence If-Then-Else Do While The ability to express a problem solution using only three basic patterns of control is called structured programming. Previous PageHome PageNext Page End Created by N. Nembhard

25 Simple Sequence Programs Previous PageHome PageNext Page End Created by N. Nembhard

26 Simple Sequence Control Structure Represents the computers ability to execute instructions in step-by-step, sequential manner. It is the simplest and most frequently used of the three basic control structures. Previous PageHome PageNext Page End Created by N. Nembhard

27 FLOWCHARTS Previous PageHome PageNext Page End

28 Simple Sequence An example of a simple sequence set of instructions not involving the use of a computer is the steps you might give a friend to get to a store. The steps must be followed in a sequential manner otherwise your friend may get lost and never find the store. 1.Proceed down Orange Street for two miles. 2.Turn right on Duke Street. 3.Proceed on Duke Street. 4.At fork, take Main Street to the left. 5.Proceed two blocks. 6.Store is on the left (77 Main Street. Previous PageHome PageNext Page End Created by N. Nembhard

29 Flowchart Start Proceed down orange street for two miles Turn right on duke street At fork, take main street to the left Proceed two blocks Store is on the left (77 Main Street) Stop A program flowchart is a pictorial representation of an algorithm. Previous PageHome PageNext Page End Created by N. Nembhard

30 Simple Sequence A simple wake up algorithm: 1.Get out of bed 2.Brush teeth 3.Eat breakfast 4.Take shower 5.Get dressed Start Brush teeth Eat Breakfast Take shower Get dressed Stop Program Flowchart Previous PageHome PageNext Page End Created by N. Nembhard

31 Flowchart Symbols Start – Every algorithm must have one entry point (Start) and one exit point (stop). These are indicated by the ellipsis symbols, called terminal interrupt symbols. Start Stop Previous PageHome PageNext Page End Created by N. Nembhard

32 Flowchart Symbols Input/output Symbol – Reading data from an input medium or writing data to an output medium. Previous PageHome PageNext Page End Created by N. Nembhard

33 Flowchart Symbols Process symbol – Shows any processing steps. It represents an operation or group of operations causing change in value, form or location of data. Previous PageHome PageNext Page End Created by N. Nembhard

34 Flowchart Symbols Flow Line - shows sequence of operations arrowheads are required if linkage is not top-to-bottom or left-to- right. Previous Page Home PageNext Page End Created by N. Nembhard

35 Flowchart Symbols Decision Symbol – shows decision- making operation, usually based on a comparison, that determines which of two or more alternative paths should be followed. Previous Page Home PageNext Page End Created by N. Nembhard

36 Flowchart Symbols Connector - Shows exit to, or entry from, another part of the flowchart; if the to or from step is another page, a page reference should be stated. B3c2 FROM PAGE 3 Previous PageHome PageNext Page End Created by N. Nembhard

37 Flowchart Symbols Annotation symbol – Gives additional explanation; comments. ------- Previous PageHome PageNext Page End Created by N. Nembhard

38 Flowchart Symbols Preparation symbol – An operation performed on the program itself for control, initialization, overhead, or cleanup. E.g. to set a switch, to place a limit value in the loop control variable and to initialize an accumulator. Previous PageHome PageNext Page End Created by N. Nembhard

39 Flowchart Symbols Predefined Process – Used to identify a series of steps shown another flowchart. Previous PageHome PageNext Page End Created by N. Nembhard

40 Variables Variables are data items whose values may change, or vary, during processing. Variable names are created to represent, or refer to, these data items. They are used to give names to lactations where data should be stored. Click for Hint Previous PageHome PageNext Page End Created by N. Nembhard

41 Variable Names Choose variable names that are appropriate and gives an indication of what will be stored. Shorten names where possible. Home PageNext Page End Previous Page Created by N. Nembhard

42 Simple Sequence Structure The Simple Sequence Structure represents the computers ability to execute instructions in a step-by-step, sequential manner. Home PageNext Page End Previous Page Created by N. Nembhard

43 Solution – Example 1 Pseudocode Start Print Enter FARENHEIT value Read farenht celsius = (fareneht – 32) * 5/9 Print farenht, celsius stop Start Print Enter FARENHEIT value Program Flowchart Read farenht Print farenht, celsius Stop celsius = fareneht – 32) * 5/9 Home PageNext Page End Previous Page

44 Example 1 – In Basic Language Print Enter FARENHEIT value input farenht celsius = (fareneht – 32) * 5/9 Print The farenheit temperature is: ; farenht Print The celsius temperature is: ; celsius End Click to Run Program Home PageNext Page End Previous Page Created by N. Nembhard

45 Problem- Using Simple Sequence Example 2 A store needs a computer program to prepare a monthly bill for each customer. For simplicity, assume that each customer purchases (at most) one type of item each month. For each purchase, there will be four inputs: customer name, item, quantity purchased, and price. The output will be the customers monthly bill after a 10 per cent discount is taken before taxes and a 5 % sales tax is added. Home PageNext Page End Previous Page Created by N. Nembhard

46 Solution – Example 2 Pseudocode Start Print Enter name, item, quantity, and price Read name, item, qty, price amtod = qty * price discount = amtod * 0.10 subbill = amtod – discount taxes = subbill * 0.05 bill = subbill * taxes Print name, item, bill stop Home PageNext Page End Previous Page Created by N. Nembhard

47 Solution – Example 2 Start Print Enter name item, quantity and price Read name item, qty, price discount = amtod * 0.10 amtod = qty * price Program Flowchart subbill = amtod - discount taxes = subbill * 0.05 bill =subbill + taxes Print name, item, bill Stop Home PageNext Page End Previous Page

48 Program in Basic Print Enter name, item, quantity, and price Input name, item, qty, price amtod = qty * price discount = amtod * 0.10 subbill = amtod – discount taxes = subbill * 0.05 bill = subbill * taxes Print name, item, bill end Click to Run Program Home PageNext Page End Previous Page Created by N. Nembhard

49 Selection Control Structure If-Then- Else Previous PageHome PageNext Page End

50 Previous PageHome PageNext Page End The IF-THEN- ELSE control structure indicates that at a particular time in processing, a choice between alternative paths, or sequence of instructions is to be made. It is a conditional statement that causes execution of some statement depending on the truth value of a certain condition. If the condition is true, then the statement (s) after then are executed. If the statement is false then the statement (s) after else are executed provided that the else clause is present. IF-THEN-ELSE CONTROL STRUCTURE Created by N. Nembhard

51 Previous PageHome PageNext Page End Example 1 - Pseudocode If rain is falling then take umbrella Endif IF-THEN-ELSE CONTROL STRUCTURE Rain is falling? Take Umbrella Start Stop Example 1 - Flowchart Yes No Created by N. Nembhard

52 Previous PageHome PageNext Page End Example 2 - Pseudocode If rain is falling then take umbrella Else dont take umbrella Endif IF-THEN-ELSE CONTROL STRUCTURE Rain is falling? Take Umbrella Start Yes No Dont take Umbrella Stop Example 2 - Flowchart Created by N. Nembhard

53 Selection Control Structure Do while Control Structure Else Previous PageHome PageNext Page End Created by N. Nembhard

54 Do While Control Structure The Do While structure is a repetition statement that allows you to specify that an action is to be repeated while some condition remains true. For example: while there are more items on my shopping list Purchase next item and cross it off my list. Previous PageHome PageNext Page End Created by N. Nembhard

55 Previous PageHome PageNext Page End Start Print Enter two numbers, (Enter 999 to end program): Read x Read y X = 999 ? Yes No X > y ? Print The first number is greater Yes No Print The second number is greater Print x, y Stop Do While Control Structure Print Enter next two numbers, (Enter 999 to end program): Read x Read y Created by N. Nembhard

56 Do While Control Structure Start Print Enter two numbers, (Enter 999 to end program): Read x Read y do while x not equal to 999 if x > y then print The first number is greater else print The second number is greater endif Print x, y Print Enter next two numbers, (Enter 999 to end program): Read x Read y Enddo Stop Previous PageHome PageNext Page End Click to Run Program in Basic Created by N. Nembhard

57 Very Good. That is Correct! Back to Quiz Home Page End

58 Sorry! That is not Correct. Back to Quiz Home Page End

59 Created By: Natalee N. Nembhard Thanks for Using the Program! © Copyright 2010 Home PagePrevious Page EXIT


Download ppt "Introduction to Programming Enter Created by N. Nembhard."

Similar presentations


Ads by Google