Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Programming

Similar presentations


Presentation on theme: "Introduction to Programming"— Presentation transcript:

1 Introduction to Programming
ENGR 112 Introduction to Programming

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

3 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

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

5 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

6 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

7 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

8 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

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

10 Tools for Program Design
ENGR 112 Tools for Program Design

11 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

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

13 ENGR 112 Flowchart Examples

14 Flow Chart for Determining the best way home

15 Flow Chart for Running a Bath

16 Payroll Program Flow Chart for Determining Payroll Amount without Modules

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

18 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.

19 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.

20 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”.

21 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

22 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

23 Hierarchy Chart Examples
ENGR 112 Hierarchy Chart Examples

24 Hierarchy Chart Example

25 Value-Averaging Program

26 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.

27 Pseudocode Definition
An outline of a program, written in a form that can easily be converted into real programming statements. Definition from

28 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.

29 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.

30 ENGR 112 Pseudocode Examples

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

32 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) = ...–

33 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

34 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

35 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.

36 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

37 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

38 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?

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

40 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

41 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”.

42 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


Download ppt "Introduction to Programming"

Similar presentations


Ads by Google