Download presentation
Presentation is loading. Please wait.
Published byCollin Owens Modified over 8 years ago
1
Visual Basic Programming Introduction to Computers Programming
2
Programming – Why? Computers are used for many different purposes in many different situations. But, how can they be so versatile? Answer: They can be programmed The ability for a computer to be programmed allows it to do whatever their programs tell them what to do. A program is a set of instructions that tell a computer what to do. A computer cannot do anything unless it has a program to tell it what to do. In this class, we will focus on writing these programs.
3
Programming – What? Programs are used to operate the components of a computer, solve problems or satisfy a want/need. How long will it take me to get home if I drive x miles per hour? I want to be able to tell my friends what I am doing right now. Computer Programming is both an Art and a Science Every aspect of a program must be carefully designed As an art, programming takes creativity and problem solving. There is often no one correct way to solve a problem. As a science, there are formal and proven methods to go about creating a programming. In this course, you will learn both the art and science of programming.
4
Hardware and Software Programs can also be called software. Software refers to the computer programs that a computer uses to complete a task. Hardware refers to the physical components that a computer is made of. A computer is not one device, but a system of devices working in tandem. Each device plays a part. Major components: Central Processing Unit Main Memory Secondary Storage Devices Input Devices Output Devices
5
Central Processing Unit (CPU) The CPU is the heart and brain of the computer. The CPU continuously does the following things: 1. Fetch an instruction 2. Follow the instruction 3. Produce some resulting data The CPU has two parts: Control Unit Coordinates the computer’s operations Determines where to get the next instruction Regulates the other major components of the computer Arithmetic and Logic Unit (ALU) Designed to perform mathematical operations
6
Main Memory Main memory holds information that the CPU needs to access quickly. Namely, the instructions to be executed. When a program is running, some or all of its instructions are in main memory. Memory is divided into sections called bytes that hold equal amount of data. Each section is made up of 8 bits. A Bit is the most basic unit of information a computer can hold. It is a switch that is either on (1) or off (0) Each byte is assigned and can be accessed by its address. A Memory Address is a unique identifying number associated with a byte in memory. Main memory typically is volatile. Volatile Memory – is memory that when it loses power, the contents are erased.
7
Secondary Storage Secondary Storage is memory that can hold data for a long period of time. Programs are usually stored in secondary storage and loaded into main memory as needed. This forms a hierarchy typically called the memory hierarchy. Common forms of secondary storage: Hard Drive Disk Drive Solid State Drive Removable Storage Floppy Disk CD-ROM USB Drives Other files can be stored in secondary storage: Documents Pictures Whatever else you save on your computer
8
Input Devices Input is any data the computer collects from the outside world. An Input Device is anything that collects data and sends it to the computer. Common Input Devices: Keyboard Mouse Scanner Digital Camera Disk Drive USB Drive
9
Output Devices Output is any data the computer sends to the outside world. An Output Device formats data and presents it to the outside world. Common Output Devices: Monitor Printer Disk Drive USB Drive
10
Software Software refers to the programs that run on a computer. Two main categories (for this class): Operating System (OS) A set of programs that manages a computer’s hardware devices and controls their processes. Most modern operating systems are capable of running multiple programs at once. UNIX, Linux, Mac OS X, and Windows are examples Application Software Programs that make the computer useful for the user Solve specific problems or supply a service Word processors, spreadsheets, databases, etc. This is what we will be developing in this class.
11
What is a Programming Language? At the lowest level we have Machine Language.
12
What is a Programming Language? At the lowest level we have Machine Language. Machine Language is a system of instructions and data executed directly by a computer's central processing unit.
13
What is a Programming Language? At the lowest level we have Machine Language. Machine Language is a system of instructions and data executed directly by a computer's central processing unit. What we will be using is a Higher-Level Language
14
What is a Programming Language? At the lowest level we have Machine Language. Machine Language is a system of instructions and data executed directly by a computer's central processing unit. What we will be using is a Higher-Level Language Higher-Level Languages consists of instruction that people can understand.
15
What is a Programming Language? At the lowest level we have Machine Language. Machine Language is a system of instructions and data executed directly by a computer's central processing unit. What we will be using is a Higher-Level Language Higher-Level Languages consists of instruction that people can understand. Examples of Higher-Level Languages: C C++ Java Python Visual Basic
16
Visual Basic Visual Basic – a third generation event-driven and integrated development environment from Microsoft.
17
Visual Basic Visual Basic – a third generation event-driven and integrated development environment from Microsoft. Third generation programming languages were created in the 1950s and are arguably the most popular kind of programming languages. They were created to be much more programmer- friendly than the previous generation.
18
Visual Basic Visual Basic – a third generation event-driven and integrated development environment from Microsoft. Third generation programming languages were created in the 1950s and are arguably the most popular kind of programming languages. They were created to be much more programmer- friendly than the previous generation. Event-driven programming is a paradigm in which the flow of programs are determined by events User Actions Messages from Other Programs
19
Visual Basic Visual Basic – a third generation event-driven and integrated development environment from Microsoft. Third generation programming languages were created in the 1950s and are arguably the most popular kind of programming languages. They were created to be much more programmer- friendly than the previous generation. Event-driven programming is a paradigm in which the flow of programs are determined by events User Actions Messages from Other Programs Integrated Development Environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development.
20
So how do we get from VB to a Running Program? First, write program.
21
So how do we get from VB to a Running Program? First, write program. A program is a collection of instructions.
22
So how do we get from VB to a Running Program? First, write program. A program is a collection of instructions. Then, we use a compiler.
23
So how do we get from VB to a Running Program? First, write program. A program is a collection of instructions. Then, we use a compiler. A compiler is a computer program that translates high-level language such as VB in Machine Language.
24
So how do we get from VB to a Running Program? First, write program. A program is a collection of instructions. Then, we use a compiler. A compiler is a computer program that translates high-level language such as VB in Machine Language. The VB compiler also detects certain types of errors during the translation process.
25
So how do we get from VB to a Running Program? First, write program. A program is a collection of instructions. Then, we use a compiler. A compiler is a computer program that translates high-level language such as VB in Machine Language. The VB compiler also detects certain types of errors during the translation process. Finally, we can run the program.
26
So how do we get from VB to a Running Program? First, write program. A program is a collection of instructions. Then, we use a compiler. A compiler is a computer program that translates high-level language such as VB in Machine Language. The VB compiler also detects certain types of errors during the translation process. Finally, we can run the program. Executing the instructions given in the instructions is called running the program.
27
Review Machine Language
28
Review Machine Language is a system of instructions and data executed directly by a computer's central processing unit.
29
Review Machine Language is a system of instructions and data executed directly by a computer's central processing unit. Higher-Level Languages
30
Review Machine Language is a system of instructions and data executed directly by a computer's central processing unit. Higher-Level Languages consists of instruction that people can understand.
31
Review Machine Language is a system of instructions and data executed directly by a computer's central processing unit. Higher-Level Languages consists of instruction that people can understand. Event-driven programming
32
Review Machine Language is a system of instructions and data executed directly by a computer's central processing unit. Higher-Level Languages consists of instruction that people can understand. Event-driven programming is a paradigm in which the flow of programs are determined by events.
33
Review Machine Language is a system of instructions and data executed directly by a computer's central processing unit. Higher-Level Languages consists of instruction that people can understand. Event-driven programming is a paradigm in which the flow of programs are determined by events. A program
34
Review Machine Language is a system of instructions and data executed directly by a computer's central processing unit. Higher-Level Languages consists of instruction that people can understand. Event-driven programming is a paradigm in which the flow of programs are determined by events. A program is a collection of instructions.
35
Review Machine Language is a system of instructions and data executed directly by a computer's central processing unit. Higher-Level Languages consists of instruction that people can understand. Event-driven programming is a paradigm in which the flow of programs are determined by events. A program is a collection of instructions. A compiler
36
Review Machine Language is a system of instructions and data executed directly by a computer's central processing unit. Higher-Level Languages consists of instruction that people can understand. Event-driven programming is a paradigm in which the flow of programs are determined by events. A program is a collection of instructions. A compiler is a computer program that translates high- level language such as VB in Machine Language.
37
Review Machine Language is a system of instructions and data executed directly by a computer's central processing unit. Higher-Level Languages consists of instruction that people can understand. Event-driven programming is a paradigm in which the flow of programs are determined by events. A program is a collection of instructions. A compiler is a computer program that translates high- level language such as VB in Machine Language. Running a program
38
Review Machine Language is a system of instructions and data executed directly by a computer's central processing unit. Higher-Level Languages consists of instruction that people can understand. Event-driven programming is a paradigm in which the flow of programs are determined by events. A program is a collection of instructions. A compiler is a computer program that translates high- level language such as VB in Machine Language. Running a program is executing the instructions given a program.
39
Programming Languages and Problem Solving In this class we will be using Visual Basic, but there are many things it shares with most programming languages.
40
Programming Languages and Problem Solving In this class we will be using Visual Basic, but there are many things it shares with most programming languages. Namely, 3 things:
41
Programming Languages and Problem Solving In this class we will be using Visual Basic, but there are many things it shares with most programming languages. Namely, 3 things: Takes in data
42
Programming Languages and Problem Solving In this class we will be using Visual Basic, but there are many things it shares with most programming languages. Namely, 3 things: Takes in data Manipulates the data
43
Programming Languages and Problem Solving In this class we will be using Visual Basic, but there are many things it shares with most programming languages. Namely, 3 things: Takes in data Manipulates the data Produces some information
44
Programming Languages and Problem Solving In this class we will be using Visual Basic, but there are many things it shares with most programming languages. Namely, 3 things: Takes in data Manipulates the data Produces some information If you can break a problem down into these steps, you can create a program to solve it.
45
Programming Languages and Problem Solving In this class we will be using Visual Basic, but there are many things it shares with most programming languages. Namely, 3 things: Takes in data Manipulates the data Produces some information If you can break a problem down into these steps, you can create a program to solve it. But do we start writing code as soon as we run into a problem?
46
Programming Languages and Problem Solving In this class we will be using Visual Basic, but there are many things it shares with most programming languages. Namely, 3 things: Takes in data Manipulates the data Produces some information If you can break a problem down into these steps, you can create a program to solve it. But do we start writing code as soon as we run into a problem? Answer: No.
47
Algorithms vs. Programs An Algorithm is
48
Algorithms vs. Programs An Algorithm is a step-by-step procedure devised for the purpose of taking in data and producing the correct output.
49
Algorithms vs. Programs An Algorithm is a step-by-step procedure devised for the purpose of taking in data and producing the correct output. A program is the actual implementation of an algorithm in a programming language.
50
Algorithms vs. Programs An Algorithm is a step-by-step procedure devised for the purpose of taking in data and producing the correct output. A program is the actual implementation of an algorithm in a programming language. Before writing a program, you must develop an algorithm to solve a problem.
51
Algorithms vs. Programs An Algorithm is a step-by-step procedure devised for the purpose of taking in data and producing the correct output. A program is the actual implementation of an algorithm in a programming language. Before writing a program, you must develop an algorithm to solve a problem. Very Important: It is highly recommended to think about the problem first, then develop an algorithm, then write the program.
52
Program Development Cycle When Developing a program in both the real world AND in this class, there are 6 steps:
53
Program Development Cycle When Developing a program in both the real world AND in this class, there are 6 steps: 1) Analyze the problem
54
Program Development Cycle When Developing a program in both the real world AND in this class, there are 6 steps: 1) Analyze the problem 2) Plan a solution
55
Program Development Cycle When Developing a program in both the real world AND in this class, there are 6 steps: 1) Analyze the problem 2) Plan a solution 3) Design an interface
56
Program Development Cycle When Developing a program in both the real world AND in this class, there are 6 steps: 1) Analyze the problem 2) Plan a solution 3) Design an interface 4) Write the code
57
Program Development Cycle When Developing a program in both the real world AND in this class, there are 6 steps: 1) Analyze the problem 2) Plan a solution 3) Design an interface 4) Write the code 5) Test and debug
58
Program Development Cycle When Developing a program in both the real world AND in this class, there are 6 steps: 1) Analyze the problem 2) Plan a solution 3) Design an interface 4) Write the code 5) Test and debug 6) Document the program
59
Program Development Cycle When Developing a program in both the real world AND in this class, there are 6 steps 1) Analyze the problem 2) Plan a solution 3) Design an interface 4) Write the code 5) Test and debug 6) Document the program 7) (Not done in this class) Maintain the program
60
Program Development Cycle When Developing a program in both the real world AND in this class, there are 6 steps 1) Analyze the problem 2) Plan a solution 3) Design an interface 4) Write the code 5) Test and debug 6) Document the program 7) (Not done in this class) Maintain the program To be successful in this class, you must perform each of these steps.
61
Analyze the Problem Understand what the problem is and what the solution should be
62
Analyze the Problem Understand what the problem is and what the solution should be Keep in mind what the End User should be able to see and do.
63
Analyze the Problem Understand what the problem is and what the solution should be Keep in mind what the End User should be able to see and do. User –
64
Analyze the Problem Understand what the problem is and what the solution should be Keep in mind what the End User should be able to see and do. User – Anyone who uses the program.
65
Analyze the Problem Understand what the problem is and what the solution should be Keep in mind what the End User should be able to see and do. User – Anyone who uses the program. End User –
66
Analyze the Problem Understand what the problem is and what the solution should be Keep in mind what the End User should be able to see and do. User – Anyone who uses the program. End User – The person whom the program was designed for him/her to use.
67
Analyze the Problem Understand what the problem is and what the solution should be Keep in mind what the End User should be able to see and do. User – Anyone who uses the program. End User – The person whom the program was designed for him/her to use. Also keep in mind what the CORRECT solution to the problem is.
68
Analyze the Problem Understand what the problem is and what the solution should be Keep in mind what the End User should be able to see and do. User – Anyone who uses the program. End User – The person whom the program was designed for him/her to use. Also keep in mind what the CORRECT solution to the problem is. This needs to be done before ANY of the following steps can take place.
69
Analyze the Problem Understand what the problem is and what the solution should be Keep in mind what the End User should be able to see and do. User – Anyone who uses the program. End User – The person whom the program was designed for him/her to use. Also keep in mind what the CORRECT solution to the problem is. This needs to be done before ANY of the following steps can take place. People have this job in real life: http://en.wikipedia.org/wiki/Software_analyst
70
Analyze the Problem Understand what the problem is and what the solution should be Keep in mind what the End User should be able to see and do. User – Anyone who uses the program. End User – The person whom the program was designed for him/her to use. Also keep in mind what the CORRECT solution to the problem is. This needs to be done before ANY of the following steps can take place. People have this job in real life: http://en.wikipedia.org/wiki/Software_analyst http://en.wikipedia.org/wiki/Software_analyst
71
Plan a Solution Once you understand the problem, you can develop an algorithm.
72
Plan a Solution Once you understand the problem, you can develop an algorithm. Create precise steps for the entire flow of the program. Usually in the form of:
73
Plan a Solution Once you understand the problem, you can develop an algorithm. Create precise steps for the entire flow of the program. Usually in the form of: Get Input
74
Plan a Solution Once you understand the problem, you can develop an algorithm. Create precise steps for the entire flow of the program. Usually in the form of: Get Input Validate Input
75
Plan a Solution Once you understand the problem, you can develop an algorithm. Create precise steps for the entire flow of the program. Usually in the form of: Get Input Validate Input Manipulate Input
76
Plan a Solution Once you understand the problem, you can develop an algorithm. Create precise steps for the entire flow of the program. Usually in the form of: Get Input Validate Input Manipulate Input Output Solution
77
Plan a Solution Once you understand the problem, you can develop an algorithm. Create precise steps for the entire flow of the program. Usually in the form of: Get Input Validate Input Manipulate Input Output Solution Every detail should be covered in the algorithm.
78
Plan a Solution Once you understand the problem, you can develop an algorithm. Create precise steps for the entire flow of the program. Usually in the form of: Get Input Validate Input Manipulate Input Output Solution Every detail should be covered in the algorithm. Consider what is logical and illogical for the control flow.
79
Plan a Solution Once you understand the problem, you can develop an algorithm. Create precise steps for the entire flow of the program. Usually in the form of: Get Input Validate Input Manipulate Input Output Solution Every detail should be covered in the algorithm. Consider what is logical and illogical for the control flow. Think about what situations can happen in the problem.
80
Plan a Solution Once you understand the problem, you can develop an algorithm. Create precise steps for the entire flow of the program. Usually in the form of: Get Input Validate Input Manipulate Input Output Solution Every detail should be covered in the algorithm. Consider what is logical and illogical for the control flow. Think about what situations can happen in the problem. There are many tools programmers use to model the flow of a program.
81
Plan a Solution Once you understand the problem, you can develop an algorithm. Create precise steps for the entire flow of the program. Usually in the form of: Get Input Validate Input Process Input Output Solution Every detail should be covered in the algorithm. Consider what is logical and illogical for the control flow. Think about what situations can happen in the problem. There are many tools programmers use to model the flow of a program. In real-world software projects, this is often done by committee
82
Design the Interface An interface is how two component interact with each other.
83
Design the Interface An interface is how two component interact with each other. User Interface – How the user interact with your program.
84
Design the Interface An interface is how two component interact with each other. User Interface – How the user interact with your program. Think about how you allow the end user to interact with you program.
85
Design the Interface An interface is how two component interact with each other. User Interface – How the user interact with your program. Think about how you allow the end user to interact with you program. Consider how the user inputs data and views results.
86
Design the Interface An interface is how two component interact with each other. User Interface – How the user interact with your program. Think about how you allow the end user to interact with you program. Consider how the user inputs data and views results. Think about what makes sense to the end user.
87
Design the Interface An interface is how two component interact with each other. User Interface – How the user interact with your program. Think about how you allow the end user to interact with you program. Consider how the user inputs data and views results. Think about what makes sense to the end user. Visual Basic is good for this.
88
Design the Interface An interface is how two component interact with each other. User Interface – How the user interact with your program. Think about how you allow the end user to interact with you program. Consider how the user inputs data and views results. Think about what makes sense to the end user. Visual Basic is good for this. For this course, this includes windows, buttons, text boxes, etc.
89
Design the Interface An interface is how two component interact with each other. User Interface – How the user interact with your program. Think about how you allow the end user to interact with you program. Consider how the user inputs data and views results. Think about what makes sense to the end user. Visual Basic is good for this. For this course, this includes windows, buttons, text boxes, etc. Again, this is a job in real life: http://en.wikipedia.org/wiki/User_interface_design http://en.wikipedia.org/wiki/User_interface_design
90
Write the Code Writing code is a process of translating the algorithm you developed into a programming language.
91
Write the Code Writing code is a process of translating the algorithm you developed into a programming language. Coding – technical word for writing code.
92
Write the Code Writing code is a process of translating the algorithm you developed into a programming language. Coding – technical word for writing code. This is where knowledge of a programming language (VB in our case) is used.
93
Write the Code Writing code is a process of translating the algorithm you developed into a programming language. Coding – technical word for writing code. This is where knowledge of a programming language (VB in our case) is used. Again, this is a real-world job: http://en.wikipedia.org/wiki/Software_developer http://en.wikipedia.org/wiki/Software_engineer http://en.wikipedia.org/wiki/Software_developer http://en.wikipedia.org/wiki/Software_engineer
94
Testing and Debugging Bug -
95
Testing and Debugging Bug - an error, flaw, mistake, failure, or fault in a computer program Even experienced software engineers make mistakes, so it is important to test your program for errors.
96
Testing and Debugging Bug - an error, flaw, mistake, failure, or fault in a computer program Even experienced software engineers make mistakes, so it is important to test your program for errors. Two Kinds (of many) of Errors:
97
Testing and Debugging Bug - an error, flaw, mistake, failure, or fault in a computer program Even experienced software engineers make mistakes, so it is important to test your program for errors. Two Kinds (of many) of Errors: Syntax Error – Error in typing the program.
98
Testing and Debugging Bug - an error, flaw, mistake, failure, or fault in a computer program Even experienced software engineers make mistakes, so it is important to test your program for errors. Two Kinds (of many) of Errors: Syntax Error – Error in typing the program. Logical Error – Inconsistency between what you want the program to do and what it actually does.
99
Testing and Debugging Bug - an error, flaw, mistake, failure, or fault in a computer program Even experienced software engineers make mistakes, so it is important to test your program for errors. Two Kinds (of many) of Errors: Syntax Error – Error in typing the program. Logical Error – Inconsistency between what you want the program to do and what it actually does. It’s important to consider all normal and abnormal inputs for the program.
100
Testing and Debugging Bug - an error, flaw, mistake, failure, or fault in a computer program Even experienced software engineers make mistakes, so it is important to test your program for errors. Two Kinds (of many) of Errors: Syntax Error – Error in typing the program. Logical Error – Inconsistency between what you want the program to do and what it actually does. It’s important to consider all normal and abnormal inputs for the program. Actual Job: http://en.wikipedia.org/wiki/Software_testerhttp://en.wikipedia.org/wiki/Software_tester
101
Complete the Documentation Documentation – Organizing all the material that describes the program.
102
Complete the Documentation Documentation – Organizing all the material that describes the program. Documentation includes:
103
Complete the Documentation Documentation – Organizing all the material that describes the program. Documentation includes: Comments inside of the code document that describes to whoever reads it what specific sections do.
104
Complete the Documentation Documentation – Organizing all the material that describes the program. Documentation includes: Comments inside of the code document that describes to whoever reads it what specific sections do. Comments inside of the code that describe the who the author is, when it was written, and any other relevant information
105
Complete the Documentation Documentation – Organizing all the material that describes the program. Documentation includes: Comments inside of the code document that describes to whoever reads it what specific sections do. Comments inside of the code that describe the who the author is, when it was written, and any other relevant information In commercial settings (industry) this includes user manuals that describe how to use the program.
106
Complete the Documentation Documentation – Organizing all the material that describes the program. Documentation includes: Comments inside of the code document that describes to whoever reads it what specific sections do. Comments inside of the code that describe the who the author is, when it was written, and any other relevant information In commercial settings (industry) this includes user manuals that describe how to use the program. This may seem annoying, but it is a very important requirement for this course.
107
Complete the Documentation Documentation – Organizing all the material that describes the program. Documentation includes: Comments inside of the code document that describes to whoever reads it what specific sections do. Comments inside of the code that describe the who the author is, when it was written, and any other relevant information In commercial settings (industry) this includes user manuals that describe how to use the program. This may seem annoying, but it is a very important requirement for this course. It is easiest to document code WHILE writing it, as well as completing it once finished writing code.
108
Modeling Tools To help understand the steps of an algorithm, programmers use a variety of tools.
109
Modeling Tools To help understand the steps of an algorithm, programmers use a variety of tools to model the algorithm. Three that will help us in this class are:
110
Modeling Tools To help understand the steps of an algorithm, programmers use a variety of tools Three that will help us in this class are: Flowcharts – Graphically depict the logical steps to carry out a task and show how the steps relate to each other
111
Modeling Tools To help understand the steps of an algorithm, programmers use a variety of tools Three that will help us in this class are: Flowcharts – Graphically depict the logical steps to carry out a task and show how the steps relate to each other Pseudocode – English-like phrases with some Visual Basic terms to outline the task
112
Modeling Tools To help understand the steps of an algorithm, programmers use a variety of tools Three that will help us in this class are: Flowcharts – Graphically depict the logical steps to carry out a task and show how the steps relate to each other Pseudocode – English-like phrases with some Visual Basic terms to outline the task Hierarchy Charts – Show how the different parts of a program relate to each other.
113
Developing an Algorithm Consider the problem of finding out how many stamps you need to put on an envelope to mail it.
114
Developing an Algorithm Consider the problem of finding out how many stamps you need to put on an envelope to mail it. The rule here is that you need 1 stamp for every 5 sheets of paper in the envelope.
115
Developing an Algorithm Consider the problem of finding out how many stamps you need to put on an envelope to mail it. The rule here is that you need 1 stamp for every 5 sheets of paper in the envelope. So the algorithm looks something like this:
116
Developing an Algorithm Consider the problem of finding out how many stamps you need to put on an envelope to mail it. The rule here is that you need 1 stamp for every 5 sheets of paper in the envelope. So the algorithm looks something like this: 1. Get the number of sheets from the user.
117
Developing an Algorithm Consider the problem of finding out how many stamps you need to put on an envelope to mail it. The rule here is that you need 1 stamp for every 5 sheets of paper in the envelope. So the algorithm looks something like this: 1. Get the number of sheets from the user. 2. Divide the number of sheets by 5
118
Developing an Algorithm Consider the problem of finding out how many stamps you need to put on an envelope to mail it. The rule here is that you need 1 stamp for every 5 sheets of paper in the envelope. So the algorithm looks something like this: 1. Get the number of sheets from the user. 2. Divide the number of sheets by 5 3. Round the result from step 2 the highest whole number
119
Developing an Algorithm Consider the problem of finding out how many stamps you need to put on an envelope to mail it. The rule here is that you need 1 stamp for every 5 sheets of paper in the envelope. So the algorithm looks something like this: 1. Get the number of sheets from the user. 2. Divide the number of sheets by 5 3. Round the result from step 2 the highest whole number 4. Output the number of stamps
120
Developing an Algorithm Consider the problem of finding out how many stamps you need to put on an envelope to mail it. The rule here is that you need 1 stamp for every 5 sheets of paper in the envelope. So the algorithm looks something like this: 1. Get the number of sheets from the user. 2. Divide the number of sheets by 5 3. Round the result from step 2 the highest whole number 4. Output the number of stamps Let’s see how the three modeling tools work here
121
Developing an Algorithm Consider the problem of finding out how many stamps you need to put on an envelope to mail it. The rule here is that you need 1 stamp for every 5 sheets of paper in the envelope. So the algorithm looks something like this: 1. Get the number of sheets from the user. 2. Divide the number of sheets by 5 3. Round the result from step 2 the highest whole number 4. Output the number of stamps Let’s see how the three modeling tools work here
122
Developing an Algorithm Consider the problem of finding out how many stamps you need to put on an envelope to mail it. The rule here is that you need 1 stamp for every 5 sheets of paper in the envelope. So the algorithm looks something like this: 1. Get the number of sheets from the user. (Input) 2. Divide the number of sheets by 5 (Process) 3. Round the result from step 2 the highest whole number (Process) 4. Output the number of stamps (Output) Let’s see how the three modeling tools work here
123
Developing an Algorithm So a specific example looks like
124
Developing an Algorithm So a specific example looks like 1. The user inputs 16 sheets of paper
125
Developing an Algorithm So a specific example looks like 1. The user inputs 16 sheets of paper 2. Dividing 16 by 5 results in 3.2
126
Developing an Algorithm So a specific example looks like 1. The user inputs 16 sheets of paper 2. Dividing 16 by 5 results in 3.2 3. Rounding 3.2 up results in 4
127
Developing an Algorithm So a specific example looks like 1. The user inputs 16 sheets of paper 2. Dividing 16 by 5 results in 3.2 3. Rounding 3.2 up results in 4 4. Output 4 stamps
128
Developing an Algorithm So a specific example looks like 1. The user inputs 16 sheets of paper 2. Dividing 16 by 5 results in 3.2 3. Rounding 3.2 up results in 4 4. Output 4 stamps Simple enough, right? What could go wrong?
129
Developing an Algorithm So a specific example looks like 1. The user inputs 16 sheets of paper 2. Dividing 16 by 5 results in 3.2 3. Rounding 3.2 up results in 4 4. Output 4 stamps Simple enough, right? What could go wrong? What if the user inputs “Banana” sheets of paper?
130
Developing an Algorithm Revised Algorithm: 1. Get the number of sheets from the user. (Input)
131
Developing an Algorithm Revised Algorithm: 1. Get the number of sheets from the user. (Input) 2. Check to see if the input is a positive number. (Validate)
132
Developing an Algorithm Revised Algorithm: 1. Get the number of sheets from the user. (Input) 2. Check to see if the input is a positive number. (Validate) 3. Divide the number of sheets by 5 (Process) 4. Round the result from step 2 the highest whole number (Process) 5. Output the number of stamps (Output) Now that our algorithm is set, lets see how the modeling tools work.
133
Developing an Algorithm Revised Algorithm: 1. Get the number of sheets from the user. (Input) 2. Check to see if the input is a positive number. (Validate) 3. Divide the number of sheets by 5 (Process)
134
Developing an Algorithm Revised Algorithm: 1. Get the number of sheets from the user. (Input) 2. Check to see if the input is a positive number. (Validate) 3. Divide the number of sheets by 5 (Process) 4. Round the result from step 2 the highest whole number (Process)
135
Developing an Algorithm Revised Algorithm: 1. Get the number of sheets from the user. (Input) 2. Check to see if the input is a positive number. (Validate) 3. Divide the number of sheets by 5 (Process) 4. Round the result from step 2 the highest whole number (Process) 5. Output the number of stamps (Output)
136
Developing an Algorithm Revised Algorithm: 1. Get the number of sheets from the user. (Input) 2. Check to see if the input is a positive number. (Validate) 3. Divide the number of sheets by 5 (Process) 4. Round the result from step 2 the highest whole number (Process) 5. Output the number of stamps (Output) Now that our algorithm is set, lets see how the modeling tools work.
137
Hierarchy Charts Postage Stamp Program
138
Hierarchy Charts Postage Stamp Program Read SheetsCalculate StampsDisplay Stamps
139
Hierarchy Charts Postage Stamp Program Read SheetsCalculate StampsDisplay Stamps Get sheets Make sure sheets is a positive integer.
140
Hierarchy Charts Postage Stamp Program Read SheetsCalculate StampsDisplay Stamps Get sheets Make sure sheets is a positive integer. Must be number Must be positive Must be integer
141
Hierarchy Charts Postage Stamp Program Read SheetsCalculate StampsDisplay Stamps Get sheets Make sure sheets is a positive integer. Set stamps = sheets / 5 Round stamps up to next whole number Must be number Must be positive Must be integer
142
Hierarchy Charts Postage Stamp Program Read SheetsCalculate StampsDisplay Stamps Get sheets Make sure sheets is a positive integer. Display: "You will need: " # of stamps Set stamps = sheets / 5 Round stamps up to next whole number Must be number Must be positive Must be integer
143
Hierarchy Charts Good for showing the structure of the algorithm
144
Hierarchy Charts Good for showing the structure of the algorithm Good at breaking down the algorithm into components
145
Hierarchy Charts Good for showing the structure of the algorithm Good at breaking down the algorithm into components Not too great at showing the order of events
146
Hierarchy Charts Good for showing the structure of the algorithm Good at breaking down the algorithm into components Not too great at showing the order of events Flow Charts are better at showing the order in which the components execute.
147
Flow Charts Components
148
Flow Charts Components Flow Line - indicates the flow of logic
149
Flow Charts Components Flow Line - indicates the flow of logic Terminal – indicates the start or end of a task
150
Flow Charts Components Flow Line - indicates the flow of logic Terminal – indicates the start or end of a task Input/Output – used for input or output operations. What is to be input or output should be in the figure.
151
Flow Charts Processing - used to show a processing step. The instructions are displayed in the figure.
152
Flow Charts Processing - used to show a processing step. The instructions are displayed in the figure. Decision – used to show when a decision needs to be made. Lines for yes and no come out of it. The question is displayed in the figure.
153
Flow Charts Processing - used to show a processing step. The instructions are displayed in the figure. Decision – used to show when a decision needs to be made. Lines for yes and no come out of it. The question is displayed in the figure. Connector – Used to join flow lines.
154
Flow Charts Start
155
Flow Charts Start Read sheets
156
Flow Charts Start Read sheets Is sheets positive number? No Yes
157
Flow Charts Start Set stamps = sheets / 5 Read sheets Is sheets positive number? No Yes
158
Flow Charts Start Set stamps = sheets / 5 Read sheets Is sheets positive number? Round stamps up to next whole number No Yes
159
Flow Charts Start Set stamps = sheets / 5 Read sheets Is sheets positive number? Round stamps up to next whole number Display: "You will need: " #stamps No Yes
160
Flow Charts Start Set stamps = sheets / 5 Read sheets Is sheets positive number? Round stamps up to next whole number Display: "You will need: " #stamps End No Yes
161
Flow Charts Start Set stamps = sheets / 5 Read sheets Is sheets positive number? Round stamps up to next whole number Display: "You will need: " #stamps End Display error message No Yes
162
Flow Charts Start Set stamps = sheets / 5 Read sheets Is sheets positive number? Round stamps up to next whole number Display: "You will need: " #stamps End Display error message No Yes
163
Pseudocode This will become more clear when you understand VB terms better.
164
Pseudocode This will become more clear when you understand VB terms better. Pseudocode is good for listing the steps of an algorithm in a form that is easier to translate into VB.
165
Pseudocode This will become more clear when you understand VB terms better. Pseudocode is good for listing the steps of an algorithm in a form that is easier to translate into VB. Important: There is NO SPECIFIC FORM to pseudocode, it can look as much like VB or English as you want. The more VB you learn, the more VB-like pseudocode you can write.
166
Pseudocode Program: Determine the proper number of steps for a letter Read sheets if sheets is a positive integer Stamps = Sheets/5 Whole Stamps = Stamps rounded to next whole number Output Whole Stamps else Display Error
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.