Algorithms Practice Topics In-Class Project: Tip Calculator

Slides:



Advertisements
Similar presentations
Program Design and Development
Advertisements

Loops – While, Do, For Repetition Statements Introduction to Arrays
FIT Objectives By the end of this lecture, students should: understand iteration statements understand the differences of for and while understand.
Computer Science 1620 Programming & Problem Solving.
Chapter 3 Planning Your Solution
Algorithms IV: Top-Down Design
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.
EGR 2261 Unit 5 Control Structures II: Repetition  Read Malik, Chapter 5.  Homework #5 and Lab #5 due next week.  Quiz next week.
General Programming Introduction to Computing Science and Programming I.
Loops: Handling Infinite Processes CS 21a: Introduction to Computing I First Semester,
Input, Output, and Processing
CMSC 104, Section 301, Fall Lecture 06, 9/18/02 Algorithms, Part 3 of 3 Topics Disk Quota Exceeded. Using Pine. More Algorithms Reading Read.
27/05/ Iteration Loops Nested Loops & The Step Parameter.
© 2006 Pearson Education 1 More Operators  To round out our knowledge of Java operators, let's examine a few more  In particular, we will examine the.
JavaScript, Fourth Edition
Program Development C# Programming January 30, 2007 Professor J. Sciame.
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.
 In this chapter you will learn about:  Introduction to Problem Solving  Software development method (SDM)  Specification of needs  Problem analysis.
Algorithms, Part 3 of 3 Topics In-Class Project: The Box
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
Algorithms and Pseudocode
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
Loops & More 1.Conditionals (review) 2.Running totals and Running products 3.the for loop, examples 4.Nesting for loops, examples 5.Common errors 1.
© 2006 Pearson Education Chapter 3 Part 2 More about Strings and Conditional Statements Loops (for and while) 1.
Repetition statements
Introduction to Computing Science and Programming I
Chapter 2 Variables.
Topics Designing a Program Input, Processing, and Output
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
CHAPTER 4 REPETITION CONTROL STRUCTURE / LOOPING
2008/09/22: Lecture 6 CMSC 104, Section 0101 John Y. Park
Chapter 2: Input, Processing, and Output
Loop Structures.
Printing Lines of Asterisks
The Selection Structure
Chapter 5: Control Structure
Teaching design techniques to design efficient solutions to problems
Programming Problem steps must be able to be fully & unambiguously described Problem types; Can be clearly described Cannot be clearly described (e.g.
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.
Chapter 4 – Control Structures Part 1
Selected Topics From Chapter 6 Iteration
2008/09/24: Lecture 6b CMSC 104, Section 0101 John Y. Park
Loops CS140: Introduction to Computing 1 Savitch Chapter 4 Flow of Control: Loops 9/18/13 9/23/13.
CSI 121 Structure Programming Language Lecture 10: Iteration (Part 1)
2008/11/12: Lab 5/Lecture 17 CMSC 104, Section 0101 John Y. Park
Chapter 7 Additional Control Structures
3 Control Statements:.
Chapter 6: Repetition Statements
Nested Loops & The Step Parameter
Chapter 5: Control Structure
Computing Fundamentals
Algorithms, Part 3 of 3 Topics In-Class Project: The Box
Solutions to In-Class Problems
Exercise Solution First questions What's output What's input
Functions, Part 4 of 4 Topics: Coding Practice Reading: None
Topics Designing a Program Input, Processing, and Output
Building Java Programs
Java Programming Loops
Topics Designing a Program Input, Processing, and Output
Chapter 2: Input, Processing, and Output
Chapter 2 Variables.
Functions, Part 3 of 3 Topics: Coding Practice Reading: None
UMBC CMSC 104 – Section 01, Fall 2016
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
Controlling Program Flow
Software Development Techniques
Algorithms, Part 3 of 3 Topics In-Class Project: Tip Calculator
Functions, Part 3 of 4 Topics: Coding Practice Reading: None
Control Structures.
Presentation transcript:

Algorithms Practice Topics In-Class Project: Tip Calculator In-Class Project: Drawing a Rectangle

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 Develop the pseudocode

Tip Calculator Problem: Write an interactive program to calculate the dollar amount of tip on a restaurant bill given the percentage of tip. You should allow for changes in the total price of the bill and the tip percentage. Error checking should be done to be sure that the amount of the bill is greater than 0.

Drawing a Rectangle Problem: Write an interactive program that will draw a solid rectangle of asterisks (*). You should allow for changes in the height and width of the rectangle. Error checking must be done to be sure that the dimensions are greater than zero.

Group Code Examples

Comments: [General remark: it was a bit unfair of us to make you use loops, which we don’t get to for several weeks—but you guys did great!] Use parentheses around the test parts of selection and repetition structures This explicit syntax gives us leeway in formatting our code Note nested loops – a very important concept Innermost loop varies fastest –counterintuitive

Comments: Note this group chose to count down instead of up—in this case, your choice In other situations, there is natural preference Note re-initialization of inner loop start value Slightly more elegant to put at start of repetition

Comments: This was the only group that did the required error-checking on the input—good for them! I think your “<width>=0” was supposed to be for <width2>

Comments: Generally, best not to use I, j –type variable names You are leaving realm of pseudocode for real code with declarations like “integer” here… Note alternative syntax of using “{…}” to denote the nested part of the repetition block Can also use with selection blocks Just be consistent!! Why 4 levels of nested loops? 2nd and 4th repetition structures will loop infinitely I think you meant to use “if”, but actually, neither is necessary Inote consistency w/semantics of “Display”—good. n future assignments, you can assume “Display” will put in a newline at the end of each request If you don’t want this behavior, for some reason, just explain at the top… or can use special keyword, like “Display_without_newline”

Drawing a Triangle - Advanced Problem: Write an interactive program that will draw a solid isosceles triangle of asterisks (*). You should allow for changes in the height of the triangle. Error checking must be done to be sure that the dimension is greater than zero.

Student Voluteerizer Problem: Write a generic algorithm for helping call on student “volunteers” in a “fair” manner <obviously underspecified…>