2008/09/22: Lecture 6 CMSC 104, Section 0101 John Y. Park

Slides:



Advertisements
Similar presentations
Algorithms 10 IST – Topic 6.
Advertisements

CMSC 104, Version 9/011 The while Looping Structure Topics The while Loop Program Versatility o Sentinel Values and Priming Reads Checking User Input Using.
CS101: Introduction to Computer programming
ITEC113 Algorithms and Programming Techniques
1 Chapter 2 Problem Solving Techniques INTRODUCTION 2.2 PROBLEM SOLVING 2.3 USING COMPUTERS IN PROBLEM SOLVING : THE SOFTWARE DEVELOPMENT METHOD.
ALGORITHMS AND FLOW CHARTS 1 Adapted from the slides Prepared by Department of Preparatory year Prepared by: lec. Ghader Kurdi.
Algorithms IV: Top-Down Design
Adapted from slides by Marie desJardins
CMSC 104, Version 9/01 1 The Box Problem: Write an interactive program to compute and display the volume and surface area of a box. The program must also.
Pseudocode algorithms using sequence, selection and repetition
Algorithmic Problem Solving CMSC 201 Adapted from slides by Marie desJardins (Spring 2015 Prof Chang version)
© 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.
CMSC 1041 Algorithms III Problem Solving and Pseudocode.
ITEC113 Algorithms and Programming Techniques
CMSC 104: Peter Olsen, Fall 99Lecture 9:1 Algorithms III Representing Algorithms with pseudo-code.
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
CMSC 104, Version 9/01 1 Functions, Part 3 of 3 Topics: Coding Practice o In-Class Project: The Box o In-Class Project: Drawing a Rectangle Reading: None.
1 Algorithms Practice Topics In-Class Project: Tip Calculator In-Class Project: Drawing a Rectangle.
Algorithms, Part 3 of 3 Topics In-Class Project: The Box
Algorithms and Pseudocode
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
1 Structured Programming Arab Academy for Science and Technology CC112 Dr. Sherif Mohamed Tawfik The Course.
Introduction to Problem Solving Programming is a problem solving activity. When you write a program, you are actually writing an instruction for the computer.
CMSC 104, Version 8/061L05Algorithms2.ppt Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode Control Structures Reading Section 3.1.
Chapter 2: Input, Processing, and Output
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Algorithms and Flowcharts
Pseudocode Upsorn Praphamontripong CS 1110 Introduction to Programming
Chapter 5: Control Structure
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Algorithm Algorithm is a step-by-step procedure or formula or set of instruction for solving a problem Its written in English language or natural language.
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
UMBC CMSC 104 – Section 01, Fall 2016
Programming Fundamentals
Algorithm and Ambiguity
2008/09/24: Lecture 6b CMSC 104, Section 0101 John Y. Park
Designing and Debugging Batch and Interactive COBOL Programs
The while Looping Structure
Unit# 9: Computer Program Development
2008/11/12: Lab 5/Lecture 17 CMSC 104, Section 0101 John Y. Park
Pseudocode algorithms using sequence, selection and repetition
2008/09/22: Lecture 5 CMSC 104, Section 0101 John Y. Park
1) C program development 2) Selection structure
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
3 Control Statements:.
The while Looping Structure
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Introduction to Algorithms and Programming
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
Algorithm and Ambiguity
Understanding Problems and how to Solve them by using Computers
Algorithms, Part 3 of 3 Topics In-Class Project: The Box
Algorithms Practice Topics In-Class Project: Tip Calculator
Click to add Text Computers & Instructions. Computers are given instructions in the form of computer programs that are created through the development.
CHAPTER 4 Iterative Structure.
Flowcharts and Pseudo Code
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Chapter 2: Input, Processing, and Output
Loops.
Basic Concepts of Algorithm
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
UMBC CMSC 104 – Section 01, Fall 2016
The while Looping Structure
The while Looping Structure
Algorithms, Part 3 of 3 Topics In-Class Project: Tip Calculator
Functions, Part 3 of 4 Topics: Coding Practice Reading: None
Presentation transcript:

2008/09/22: Lecture 6 CMSC 104, Section 0101 John Y. Park Algorithms Part 3 of 3 2008/09/22: Lecture 6 CMSC 104, Section 0101 John Y. Park [db-fall06, modified significantly]

Algorithms, Part 3 of 3 Topics Algorithms: Brief Review In-Class Project: Tip Calculator In-Class Project: Drawing a Rectangle Reading None

Definition of an Algorithm [Review] Our final definition: An algorithm is a finite set of unambiguous, executable instructions that directs a terminating activity.

A Generic Algorithm [Review] What is a generic algorithm for a given problem? An algorithm for solving the problem, that has been generalized to work with a variety of possible input parameters to produce input-specific solutions.

Pseudocode: Control Structures Any problem can be solved using only three logical control structures: Sequence Selection Repetition

Sequence A series of steps or statements that are executed in the order they are written. Example: Display “Enter two numbers: “ Read <number1> Read <number2> <sum> = <number1> + <number2> Display “sum = “, <sum>

Selection Defines one or more courses of action depending on the evaluation of a condition. Synonyms: conditional, branching, decision Examples: If (condition is true) If (condition is true) do this do this End_if Else do that End_if

Repetition Allows one or more statements to be repeated as long as a given condition is true. Synonyms: looping, iteration Example: While (condition is true) do this End_while

Pseudocode Style Any user prompts should appear exactly as you wish the programmer to code them. The destination of any output data should be stated, such as in “Display”, which implies the screen. Make the data items clear (e.g., surround them by < and > ) and give them descriptive names. Use formulas wherever possible for clarity and brevity. Use keywords (such as Read and While) and use them consistently. Accent them in some manner.

Pseudocode (con’t) [Review] Use indentation for clarity of logic. Avoid using code. Pseudocode should not be programming language-specific. Always keep in mind that you may not be the person translating your pseudocode into programming language code. It must, therefore, be unambiguous. You may make up your own pseudocode guidelines, but you MUST be consistent.

Pseudocode Example Display “Enter the number of children: “ Read <number of children> Display “Enter the number of cookies remaining: “ Read <cookies remaining> <original cookies> = <cookies remaining> While (<number of children> > 0) <original cookies> = <original cookies> X 2 <number of children> = <number of children> - 1 End_While Display “Original number of cookies = “, <original cookies>

Writing Algorithms from Scratch Given a problem statement, we are going to write the corresponding generic algorithm for the solution. We will use the following procedure: Determine the algorithm inputs and outputs Complete the pseudocode

Simple Tip Calculator Problem: Write an interactive program to calculate the dollar amount of tip on a restaurant bill at the standard 15% rate. You should allow for changes in the total price of the bill.

Drawing a Rectangle Problem: Write an interactive program that will draw a solid rectangle of asterisks (*) of user-specified dimensions. The program must also display the dimensions of the rectangle. Error checking must be done to be sure that the dimensions are greater than zero.

General Tip Calculator Problem: Write an interactive program to calculate a table of dollar amounts of tip on a restaurant bill. You should allow for changes in the total price of the bill. You should also ask the user for the range of tipping rates to calculate (i.e., low and high ends). Error checking should be done to be sure that the amount of the bill is greater than 0.

Group Exercise Drawing a Rectangle: Tip Calculator: Write an interactive program that will draw a solid rectangle of asterisks (*) of user-specified dimensions. The program must also display the dimensions of the rectangle. Error checking must be done to be sure that the dimensions are greater than zero Tip Calculator: Write an interactive program to calculate a table of dollar amounts of tip on a restaurant bill. You should allow for changes in the total price of the bill. You should also ask the user for the range of tipping rates to calculate (i.e., low and high ends). Error checking should be done to be sure that the amount of the bill is greater than 0.