Introduction to Programming

Slides:



Advertisements
Similar presentations
Chapter 2: Modularization
Advertisements

COMPUTER PROGRAMMING I Understand Problem Solving Tools to Design Programming Solutions.
Repetition Control Structures School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 9, Friday 3/07/2003)
1.4 Programming Tools Flowcharts Pseudocode Hierarchy Chart
Programming TBE 540 Farah Fisher. Objectives After viewing this presentation, the learner will be able to… Given a task, create pseudocode Given pseudocode,
Programming Logic and Design Fourth Edition, Introductory
ALGORITHMS THIRD YEAR BANHA UNIVERSITY FACULTY OF COMPUTERS AND INFORMATIC Lecture two Dr. Hamdy M. Mousa.
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
Chapter 2 - Problem Solving
Chapter 2 - Problem Solving
Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University.
Programming Logic and Design, Third Edition Comprehensive
ITEC113 Algorithms and Programming Techniques
Program Design and Development
Pseudocode and Algorithms
Modules, Hierarchy Charts, and Documentation
Programming Fundamentals (750113) Ch1. Problem Solving
Chapter 3 Planning Your Solution
PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve.
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
Chapter 2: Developing a Program Prelude to Programming Concepts and Design Copyright © 2001 Scott/Jones, Inc.. All rights reserved. 1 Chapter 2 Developing.
Sw development1 Software Development 1.Define the problem (Analysis) 2.Plan the solution 3.Code 4.Test and debug 5.Maintain and Document.
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
Designing and Debugging Batch and Interactive COBOL Programs Chapter 5.
Describe the Program Development Cycle. Program Development Cycle The program development cycle is a series of steps programmers use to build computer.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
BACS 287 Programming Logic 1. BACS 287 Programming Basics There are 3 general approaches to writing programs – Unstructured – Structured – Object-oriented.
6 Chapter 61 Looping Programming Logic and Design, Second Edition, Comprehensive 6.
An Object-Oriented Approach to Programming Logic and Design Chapter 1 An Overview of Computers and Logic.
Review, Pseudocode, Flow Charting, and Storyboarding.
1 Program Planning and Design Important stages before actual program is written.
1 Programming Tools Flowcharts Pseudocode Hierarchy Chart Direction of Numbered NYC Streets Algorithm Class Average Algorithm.
The Hashemite University Computer Engineering Department
Chapter 2 - VB 2005 by Schneider- modified by S. Jane '081 Chapter 2 - Problem Solving 2.1 Program Development Cycle 2.2 Programming Tools.
CSE 110: Programming Language I Matin Saad Abdullah UB 404.
Programming Logic and Design Seventh Edition Chapter 1 An Overview of Computers and Programming.
Understand Problem Solving Tools to Design Programming Solutions
DDC 1023 – Programming Technique
Chapter 2- Visual Basic Schneider
ALGORITHMS AND FLOWCHARTS
Programming Mehdi Bukhari.
Understand Problem Solving Tools to Design Programming Solutions
Lecture 2 Introduction to Programming
Introduction To Flowcharting
Computer Programming.
ALGORITHMS AND FLOWCHARTS
Print slides for students reference
Designing and Debugging Batch and Interactive COBOL Programs
Unit# 9: Computer Program Development
Problem Solving Techniques
Programming Fundamentals (750113) Ch1. Problem Solving
Programming Fundamentals (750113) Ch1. Problem Solving
ALGORITHMS AND FLOWCHARTS
Chapter 2- Visual Basic Schneider
Introduction to Algorithms and Programming
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
Faculty of Computer Science & Information System
Algorithm and Ambiguity
Understanding Problems and how to Solve them by using Computers
Programming Fundamentals (750113) Ch1. Problem Solving
CSC 110 PROGRAMMING LOGIC CHAPTER 2
CHAPTER 4 Iterative Structure.
ICT Gaming Lesson 2.
COMPUTATIONAL THINKING COMPUTATIONAL THINKING IN PROGRAMMING
Programming Fundamentals (750113) Ch1. Problem Solving
Basic Concepts of Algorithm
CSC 110 PROGRAMMING LOGIC CHAPTER 2
Programming Logic and Design Eighth Edition
Presentation transcript:

Introduction to Programming ENGR 112 Introduction to Programming

Outline Software and Programming Program Structure Tools for Designing Software Programming Languages Introduction to Visual Basic (VBA)

Software Written in a programming language Every language has a syntax Language rules dictate writing program code Syntax must be perfect for the program to work What kinds of language rules? Spelling Punctuation Placement of words in an instruction

Properly Working Program Specific sequence of instructions Don’t leave anything out Don’t add in things that are not needed

Importance of Structure Making a cake Stir Add two eggs Add a gallon of gasoline Bake at 350 degrees for 45 minutes Add three cups of flour BUT Instructions are Out of order Missing Belong to another procedure

Running a Program The program can ONLY be run or executed once syntax errors are removed if the program appears to be written in a logical order

Program Elements Input- data, facts Process – organize, check for accuracy, or do some calculations Output – send results to printer, monitor, or speaker Storage – send results to file to be used for input later

Program Structure Large programs are never written as one huge series of steps. Programs are broken down into units called modules. Modules are also referred to as: subroutines functions procedures methods

Why Modularize? Allows multiple people to work on a problem Enables reuse Makes it easier to identify structures Makes it easier to debug

Tools for Program Design ENGR 112 Tools for Program Design

Flowcharts Used to structure logical flow of program Create BEFORE you start creating code Can help prevent errors in logic Can speed up coding process since flow of program has been developed

Flowchart Symbols Flow of logic Connector I/O Processing Decision Start/End Flow of logic Connector

ENGR 112 Flowchart Examples

Flow Chart for Determining the best way home

Flow Chart for Running a Bath

Payroll Program Flow Chart for Determining Payroll Amount without Modules

Payroll Program with Modules Flow Chart for Determining Payroll Amount with Modules

Creating Flowcharts #1 Read records from a file containing the name and batting average of all players in the league.  Write out the name and average of every player with an average of .200 or greater.

Creating Flowcharts #2 Read a file containing the high temperature of each day in December.  Write out the average high temperature for the month.  You can assume the input file includes only the 31 temperatures for December.

Creating Flowcharts #3 Design a program to create a graduation list given an input file of graduates including name and GPA for each graduate.  Any graduate with a GPA that is greater or equal to 3.8 should have "Dean's List" written next to his/her name. All others should have “ Graduate”  written next to his/her name. Finally  print “End of Graduation List -2002”.

Hierarchy Charts You can use a hierarchy chart to illustrate modules’ relationships A hierarchy chart does not tell you what tasks are to be performed within a module; it does not tell you when or how a module executes

Hierarchy Charts Used to break down “tasks” associated with a program into sub-tasks Illustrates relationship between tasks/subtasks Useful in guiding structure of events in Visual Basic

Hierarchy Chart Examples ENGR 112 Hierarchy Chart Examples

Hierarchy Chart Example

Value-Averaging Program

Hierarchy Chart Exercises Allow a user to enter 5 numbers in any order, return and ordered list of numbers. Allow a user to enter a word of any length, and return a count of the number of vowels. Allow a user to enter any number, tell the user if a number is a prime number and if the number is odd or even. Allow a user to enter a shape type and dimensions, tell the user which of two shapes has the largest area.

Pseudocode Definition An outline of a program, written in a form that can easily be converted into real programming statements. Definition from http://www.webopaedia.com/

Writing Pseudocode Before you start typing your program, sit down and think about what you want to do. You might just run through in your head the steps you think you need, or you might jot some things down. THIS is what your pseudocode is.

Writing Pseudocode When you decide how you are going to tackle the program, your ideas go through several levels of refinement. Similarly, the pseudocode can be more or less detailed depending on exactly what you want to put down.

ENGR 112 Pseudocode Examples

General Pseudocode Example Build a matrix – Put 1’s on main diagonal, – Put 0.5’s on off diagonals – Put numbers in corners

Detail Pseudocode Example Build a matrix Do “loop from 1 to size” A(i,i) = 1 A(i+1,i) = -0.5 A(i,i+1) = -0.5 end Do A(1,1) = ...–

Guess the Number Program Get random number Do ! loop until number is guessed Prompt for user's guess Get user guess Compare against actual number: If guess is higher, print "too high!" ElseIf guess is lower, print "too low!" Else print "you guessed it!" and exit the program Endif End Loop ! go back for another guess

Bubble Sort Pseudocode While not at end of list compare adjacent elements if second is greater than first switch them Else get next two elements if elements were switched repeat for entire list

Important Points Pseudocode does use loops or If/Then/Else statements, where needed. You should not use exact syntax in your pseudocode, because someone should be able to look at your pseudocode and write a program in ANY language. Pseudocode should be specific enough to give an idea of what type of program-flow you are thinking of. Pseudocode shouldn't need comments but sometimes it helps to tell what the loops are for.

Generate Pseudocode Given a classroom full of people: find the average height the number of people the height of the tallest person the height of the smallest person

What Processes do we have? getting a height determining how many people are in the class calculating an average determining the tallest height determining the smallest height

Decisions to be Made? Is this the last person? Is the current height we have measured greater than  the current tallest height? Is the current height we have measured smaller than  the current smallest height?

What Variables are Needed? Current_Height (the height we have just measured) Tallest Smallest Number_Of_Persons Average_Height

Number_Of_Persons = 0 Average_Height = 0 Sum_Of_Heights = 0 Tallest = 0 Smallest = 10 DOWHILE NOT Last_Person INPUT Current_Height   Number_Of_Persons = Number_Of_Persons + 1   Sum_Of_Heights = Sum_Of_Heights + Current_Height    IF Current_Height > Tallest   THEN Tallest = Current_Height   IF Current_Height < Smallest  THEN Smallest = Current_Height END DOWHILE Average_Height = Sum_Of_Heights / Number_Of_Persons

Pseudocode Examples Example #1. Read records from a file containing the name and batting average of all players in the league.  Write out the name and average of every player with an average of .200 or greater. Example#2 Read a file containing the high temperature of each day in December.  Write out the average high temperature for the month.  You can assume the input file includes only the 31 temperatures for December. Example #3 Design a program to create a graduation list given an input file of graduates including name and GPA for each graduate.  Any graduate with a GPA that is greater or equal to 3.8 should have "Dean's List" written next to his/her name. All others should have “ Graduate”  written next to his/her name. Finally  print “End of Graduation List -2002”.

Pseudocode Exercises Determine the average age of patrons during an evening at Clodfelters Determine the greatest amount of money spent by a single customer during a day at Dari Mart Determine the average amount of money spent on text books at the OSU bookstore on the first day of the term