Introduction to Programming Enter Created by N. Nembhard END
Main Menu What is a Computer Program? The Main Steps in Developing a Program Basic Elements of Any Program Types of Errors Basic Control Structures Created by N. Nembhard End Previous Page Home Page Next Page
Home 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. Created by N. Nembhard End Next Previous
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. Created by N. Nembhard End Next Previous
Algorithms Home 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. Created by N. Nembhard End Next Previous
Home 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. Created by N. Nembhard End Next Previous
What is a computer Program? Home 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 Exit Next Previous
Main Steps in Developing a Program Home Main Steps in Developing a Program Define the problem Outline the solution Develop the outline into an algorithm Test the algorithm for correctness Code the algorithm into a specific programming language 6. Run the program on the computer Document and maintain the program Created by N. Nembhard End Next Previous
Home The Basic Elements of any Program The basic elements of any program are: Input Processing Output Created by N. Nembhard Exit Next Previous
Home 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 End Next Previous
Home 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 End Next Previous
Home Output Sending or displaying data to the user. Common output devices includes the monitor and the printer. Created by N. Nembhard End Next Previous
What Have You Learnt? End Previous Page Home Page Next Page Created by N. Nembhard End Previous Page Home Page Next Page
Click on the correct answer: 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 Created by N. Nembhard C end Previous Page Home Page Next Page
Click on the correct answer: Quiz Click on the correct answer: Which of the following is NOT a high level language? Basic Assembly C++ A B C end Previous Page Home Page Next Page
Click on the correct answer: Quiz Click on the correct answer: The basic elements of any program are: Input, storing, processing Input, storing,output Input, processing, output A B C Created by N. Nembhard end Previous Page Home Page Next Page
Is the following statement true or false? 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. True False Created by N. Nembhard end Previous Page Home Page Next Page
End of Quiz! end Previous Page Home Page Next Page Created by N. Nembhard end Previous Page Home Page Next Page
Types of Errors Semantic Errors Syntax Errors Logic Errors Errors that programmers usually make includes: Semantic Errors Syntax Errors Logic Errors Created by N. Nembhard End Previous Page Home Page Next Page
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. Created by N. Nembhard End Previous Page Home Page Next Page
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. Created by N. Nembhard End Home Page Next Page Previous Page
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. Created by N. Nembhard End Previous Page Home Page Next Page
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. Created by N. Nembhard End Previous Page Home Page Next Page
Simple Sequence Programs Created by N. Nembhard End Previous Page Home Page Next Page
Simple Sequence Control Structure Represents the computer’s ability to execute instructions in step-by-step, sequential manner. It is the simplest and most frequently used of the three basic control structures. Created by N. Nembhard End Previous Page Home Page Next Page
FLOWCHARTS End Previous Page Home Page Next Page
Simple Sequence End Proceed down Orange Street for two miles. Turn right on Duke Street. Proceed on Duke Street. At fork, take Main Street to the left. Proceed two blocks. Store is on the left (77 Main Street. 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. Created by N. Nembhard End Previous Page Home Page Next Page
Flowchart A program flowchart is a pictorial representation of an algorithm. Start Proceed down orange street for two miles Turn right on duke street Stop At fork, take main street to the left Store is on the left (77 Main Street) Created by N. Nembhard Proceed two blocks End Previous Page Home Page Next Page
Simple Sequence A simple wake up algorithm: Get out of bed Brush teeth Program Flowchart A simple wake up algorithm: Get out of bed Brush teeth Eat breakfast Take shower Get dressed Start Brush teeth Eat Breakfast Take shower Get dressed Stop Created by N. Nembhard End Previous Page Home Page Next Page
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 Created by N. Nembhard Stop End Previous Page Home Page Next Page
Flowchart Symbols Input/output Symbol – Reading data from an input medium or writing data to an output medium. Created by N. Nembhard End Previous Page Home Page Next Page
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. Created by N. Nembhard End Previous Page Home Page Next Page
Flowchart Symbols Flow Line - shows sequence of operations arrowheads are required if linkage is not top-to-bottom or left-to-right. Created by N. Nembhard End Home Page Next Page Previous Page
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. Created by N. Nembhard End Home Page Next Page Previous Page
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. FROM PAGE 3 B3 c2 Created by N. Nembhard End Previous Page Home Page Next Page
Annotation symbol – Gives additional explanation; comments. Flowchart Symbols Annotation symbol – Gives additional explanation; comments. ------- Created by N. Nembhard End Previous Page Home Page Next Page
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. Created by N. Nembhard End Previous Page Home Page Next Page
Flowchart Symbols Predefined Process – Used to identify a series of steps shown another flowchart. Created by N. Nembhard End Previous Page Home Page Next Page
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 Created by N. Nembhard End Previous Page Home Page Next Page
Variable Names Choose variable names that are appropriate and gives an indication of what will be stored. Shorten names where possible. Created by N. Nembhard End Previous Page Home Page Next Page
Simple Sequence Structure The Simple Sequence Structure represents the computer’s ability to execute instructions in a step-by-step, sequential manner. Created by N. Nembhard End Previous Page Home Page Next Page
Solution – Example 1 End Program Flowchart Pseudocode Start Print “Enter FARENHEIT value” Read farenht celsius = (fareneht – 32) * 5/9 Print farenht, celsius stop Print “Enter FARENHEIT value” Read farenht celsius = fareneht – 32) * 5/9 Print farenht, celsius Stop End Previous Page Home Page Next Page
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 Created by N. Nembhard End Previous Page Home Page Next Page
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 customer’s monthly bill after a 10 per cent discount is taken before taxes and a 5 % sales tax is added. Created by N. Nembhard End Previous Page Home Page Next Page
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 Created by N. Nembhard End Previous Page Home Page Next Page
End Solution – Example 2 Program Flowchart Previous Page Home Page subbill = amtod - discount Start Print “Enter name item, quantity and price” discount = amtod * 0.10 taxes = subbill * 0.05 Read name item, qty, price amtod = qty * price bill =subbill + taxes Print name, item, bill Stop End Previous Page Home Page Next Page
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 Created by N. Nembhard End Previous Page Home Page Next Page
Selection Control Structure If-Then- Else End Previous Page Home Page Next Page 48
IF-THEN-ELSE CONTROL STRUCTURE 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. Created by N. Nembhard End Previous Page Home Page Next Page
IF-THEN-ELSE CONTROL STRUCTURE Example 1 - Flowchart Example 1 - Pseudocode If rain is falling then take umbrella Endif Start Rain is falling? No Yes Take Umbrella Created by N. Nembhard Stop End Previous Page Home Page Next Page
IF-THEN-ELSE CONTROL STRUCTURE Example 2 - Flowchart Example 2 - Pseudocode If rain is falling then take umbrella Else don’t take umbrella Endif Start Rain is falling? No Yes Don’t take Umbrella Take Umbrella Created by N. Nembhard Stop End Previous Page Home Page Next Page
Selection Control Structure Do while Control Structure Else Created by N. Nembhard End Previous Page Home Page Next Page
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. Created by N. Nembhard End Previous Page Home Page Next Page
End Do While Control Structure Previous Page Home Page Next Page Print “Enter two numbers, (Enter 999 to end program): Start Read x Read y Do While Control Structure X = 999 ? Yes Stop No X > y ? Print “The first number is greater” No Yes Read x Read y Print “The second number is greater” Print “Enter next two numbers, (Enter 999 to end program): Created by N. Nembhard Print x, y End Previous Page Home Page Next Page
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):” Enddo Stop Click to Run Program in Basic Created by N. Nembhard End Previous Page Home Page Next Page
Very Good. That is Correct! Back to Quiz End Home Page
Sorry! That is not Correct. Back to Quiz End Home Page
Created By: Natalee N. Nembhard Thanks for Using the Program Created By: Natalee N. Nembhard Thanks for Using the Program! © Copyright 2010 EXIT Previous Page Home Page