Presentation is loading. Please wait.

Presentation is loading. Please wait.

Algorithms Practice Topics In-Class Project: Tip Calculator

Similar presentations


Presentation on theme: "Algorithms Practice Topics In-Class Project: Tip Calculator"— Presentation transcript:

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

2 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

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

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

5 Group Code Examples

6 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

7 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

8 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>

9 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”

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

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


Download ppt "Algorithms Practice Topics In-Class Project: Tip Calculator"

Similar presentations


Ads by Google