Introduction to Programming

Slides:



Advertisements
Similar presentations
More on Algorithms and Problem Solving
Advertisements

How Are Algorithms Developed?
COMPUTER PROGRAMMING I Understand Problem Solving Tools to Design Programming Solutions.
Program Flowchart, Pseudocode & Algorithm development
Chapter 3 IFTHENELSE Control Structure © 2008 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved. Marilyn Bohl/Maria Rynn Tools for Structured.
CHAPTER 1: AN OVERVIEW OF COMPUTERS AND LOGIC. Objectives 2  Understand computer components and operations  Describe the steps involved in the programming.
Chapter 1 - An Introduction to Computers and Problem Solving
Introduction to Programming
Reference :Understanding Computers
زبانهای برنامه سازی برنامه سازی پیشرفته ارائه دهنده دکتر سيد امين حسيني E.mail: Home page:
 Control structures  Algorithm & flowchart  If statements  While statements.
ITEC113 Algorithms and Programming Techniques
Chapter 3 - Structured Program Development
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
Pseudocode and Algorithms
Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved.
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Structured Program Development in C
Chapter 2: Algorithm Discovery and Design
Pseudocode.
Chapter 3 Planning Your Solution
The Program Design Phases
PRE-PROGRAMMING PHASE
DCT 1123 Problem Solving & Algorithms
Flow Charting. Goals Create Algorithms using Flow Charting procedures. Distinguish between Flow Charting and Pseudocode. Top-Down Design Bottom-up Design.
PROGRAMMING LANGUAGES Prof. Lani Cantonjos. PROGRAM - set of step-by-step instructions that tells or directs the computer what to do. PROGRAMMING LANGUAGE.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Structural Program Development: If, If-Else Outline.
Introduction to Programming Design School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 1, Friday 01/17/2003) (Continued)
Structured Program Development Outline 2.1Introduction 2.2Algorithms 2.3Pseudo code 2.4Control Structures 2.5The If Selection Structure 2.6The If/Else.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts.
CSE 102 Introduction to Computer Engineering What is an Algorithm?
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
BACS 287 Programming Logic 1. BACS 287 Programming Basics There are 3 general approaches to writing programs – Unstructured – Structured – Object-oriented.
C Lecture Notes 1 Structured Program Development.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
Flowcharts and Algorithms. Review of Terms  A computer is a machine that can represent and manipulate data –Ultimately the data and the instructions.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 4 Looping.
Dale Roberts 1 Program Control - Algorithms Department of Computer and Information Science, School of Science, IUPUI CSCI N305.
Structured Program Development Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010.
1 Program Planning and Design Important stages before actual program is written.
`. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart.
Software Development. Software Development Loop Design  Programmers need a solid foundation before they start coding anything  Understand the task.
WHAT IS THIS? Clue…it’s a drink SIMPLE SEQUENCE CONTROL STRUCTURE Introduction A computer is an extremely powerful, fast machine. In less than a second,
Algorithms and Pseudocode
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Flow Charts And Pseudo Codes Grade 12. An algorithm is a complete step-by- step procedure for solving a problem or accomplishing a task.
Victoria Ibarra Mat:  Generally, Computer hardware is divided into four main functional areas. These are:  Input devices Input devices  Output.
Programming Logic and Design Seventh Edition Chapter 1 An Overview of Computers and Programming.
Algorithms and Flowcharts
Software Development.
Understand Problem Solving Tools to Design Programming Solutions
Algorithms and Flowcharts
Understand Problem Solving Tools to Design Programming Solutions
Lecture 2 Introduction to Programming
Introduction To Flowcharting
Programming Fundamentals
Algorithm and Ambiguity
Structured Program
1) C program development 2) Selection structure
Chapter 3 - Structured Program Development
Introduction to Algorithms and Programming
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
Chapter 3 - Structured Program Development
Algorithm and Ambiguity
Understanding Problems and how to Solve them by using Computers
Programming Logic and Design Eighth Edition
Structural Program Development: If, If-Else
Presentation transcript:

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