faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/Python/PythonTop-DownDesign…  · Web...

20
Top-Down Design Pictures A picture o is worth a thousand words o can say more than words language independent o works in Java, Python, C++, etc… Overall Steps for Application Completion 0. Determine application needs from description a. Here is where we get the scope of work b. Have to be very defined here so the client doesn’t add later 1. Design a. What you are about to do b. Top-Down and/or UML 2. Research 3. Coding 4. Debugging 5. Testing the live application on staff/client 6. Production 7. Follow up and updating

Transcript of faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/Python/PythonTop-DownDesign…  · Web...

Page 1: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/Python/PythonTop-DownDesign…  · Web viewworks in Java, Python, C++, etc… Overall Steps for Application Completion. Determine

Top-Down DesignPictures

A picture o is worth a thousand wordso can say more than words

language independento works in Java, Python, C++, etc…

Overall Steps for Application Completion0. Determine application needs from description

a. Here is where we get the scope of workb. Have to be very defined here so the client doesn’t add later

1. Designa. What you are about to dob. Top-Down and/or UML

2. Research3. Coding4. Debugging5. Testing the live application on staff/client6. Production7. Follow up and updating

Page 2: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/Python/PythonTop-DownDesign…  · Web viewworks in Java, Python, C++, etc… Overall Steps for Application Completion. Determine

Top-Down Design Ex. #1

Creating a Box Plot with a set of Data

1. What is the first function to be called from main()?2. What is the LAST function to be called? (doesn’t have to be from main())3. How many functions does getInputFromUser call?4. What does an arrow down mean?5. What does an arrow up mean? Answerb:

Page 3: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/Python/PythonTop-DownDesign…  · Web viewworks in Java, Python, C++, etc… Overall Steps for Application Completion. Determine

Top-Down Example #2

Game of hangman

Top-Down Example #3

Page 4: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/Python/PythonTop-DownDesign…  · Web viewworks in Java, Python, C++, etc… Overall Steps for Application Completion. Determine

World Traveler

Page 5: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/Python/PythonTop-DownDesign…  · Web viewworks in Java, Python, C++, etc… Overall Steps for Application Completion. Determine

If-Else in a Top-Down Design Meant for a menu, not just any if/else statement broken down just like the code each option is a “branch” “choice” is the menu variable

If-Else Top-Down Example

Program that runs several times uses a loop, but all functions run WITHIN that loop quit is used

Big While loop Top-Down Example

A function that has a loop INSIDE it still need to show the function the “loop” is placed inside with details on how it ends

Inner Loop Top-Down Example

Which functions are called within the loop?Constants

Page 6: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/Python/PythonTop-DownDesign…  · Web viewworks in Java, Python, C++, etc… Overall Steps for Application Completion. Determine

you could start identifying constants you could use now!! make sure you

o name them properlyo variable name is in CAPS with _ as spaces

list them ABOVE the main line

Constants in a Top-Down Example

Validation Loop you know is belong in a loop!! “try” will not appear make sure you show and determine HOW the validation loop will end

Page 7: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/Python/PythonTop-DownDesign…  · Web viewworks in Java, Python, C++, etc… Overall Steps for Application Completion. Determine

Lupoli's (& Evans’) Words of Wisdom on Top-Down DesignGeneral thoughts

In top-down design, you break down a problem into sub-problems with functions. Then, you break these sub-problems into sub-sub-problems, and so forth. Eventually, you get to a place where you can start actual implementation. This design process helps you understand the sequence of events. It helps to segment the problem into understandable pieces. This helps to organize your code and makes it easier to read.

When give an application follow these steps, at any time you can update these!!1. break up code into methods that follow a natural division of work

a. break them down as far as you canb. this may mean making other VERY small methods

i. this helps since we can test!!!c. for now, place a print statement inside the empty function, displaying the name of the function

i. called a stub2. spell out in detail what each function is to accomplish

a. as a comment in the function header3. think about what each function should input/output/return4. Remember, user dumb, you smart. Determine what the valid input should be.5. (Repeated), You may find some methods have smaller parts. Repeat steps 1 through 5.6. Only when exhausted, begin coding. (below)

Begin the steps above using the Drywall Calculator(just list methods, with headers and stubs)

Begin Coding1. finish one function at a time, yes easiest is at least a start!!2. test each function w/ values that you can calculate!!3. After determining what the valid input should be, create if/else's to check.

Begin the steps above using the Drywall Calculator(add code to your methods)

Page 8: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/Python/PythonTop-DownDesign…  · Web viewworks in Java, Python, C++, etc… Overall Steps for Application Completion. Determine

Drywall Installation CalculatorDrywall is the wall inside your house that you hang pictures on. Drywall contractors work inside the house to install, mud and sand to make the wall look smooth. Each drywall piece called a "sheet" that is 4ft x 8ft. The sheet can be cut, but the less cuts the better. For outlets along the wall, the drywall has a "hole" cut into it before installed. You can learn more viewing the URL: https://www.youtube.com/watch?v=MB1YVOCOyeU (way too perky for me)

You are hired to create a quick calculator for them to give the customers a quick quote. The quote is calculated by:

Required costs per job $100 for materials (tape, mud) $10 per outlet (for labor)

Costs determine by size of job: each sheet

o takes 15 minutes to install o and 45 minutes to mud, and sand (1 hr total)

$100 per hour

Single run program (won’t loop) must ask for:1. Current price per sheet of drywall (program will add 6% tax and assuming 4’x8’ sheet)2. height of room3. length (all walls added together) of room4. number of outlets in room

Program needs to display:1. number of sheets of drywall required2. Time needed to mud and sand3. Total cost for drywall4. Total cost for labor (hanging drywall, cutting out for outlets)5. Total overall cost

Scenario #1 $5.47 per 4’x8’ sheet, can only tax on the sheets bought

Cost Calculation:

Page 9: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/Python/PythonTop-DownDesign…  · Web viewworks in Java, Python, C++, etc… Overall Steps for Application Completion. Determine

$100 Required Costs$20 outlets$17.39 =$300 = Labor$437.39 total

Total Area = 12x8 = 96Sheets needed (round up) = 96 / (4x8) = 3Labor (3 sheets * $100) = $300(outlets x 2)Total for Drywall = $17.39 = $5.47 (per sheet) x 3 x 1.06

Scenario #2

(ignore the doorway, still need to cover it!)

Page 10: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/Python/PythonTop-DownDesign…  · Web viewworks in Java, Python, C++, etc… Overall Steps for Application Completion. Determine

Cost Calculations:

$100 Required Costs$50 outlets$34.78 total cost of drywall$600 = Labor$784.78 total

Total Area = 24 x8 = 192Sheets needed (round up) = 192 / (4x8) = 6Labor (6 sheets * $100) = $600$50 (outlets x 5)Total for Drywall = $34.78 = 6 x 5.47 x 1.06

Scenario #331' x 12' with 5 outletsCost Calculations:

$100 Required Costs$50 outlets$69.58 total cost of drywall (12 sheets, 11.6 rounded up)$1200 = Labor$1419.58 total

Total Area = 31 x 12 = ??Sheets needed (round up) = 12Labor (12 sheets * $100) = $1200$50 (outlets x 5)Total for Drywall = $34.78 = 12 x 5.47 x 1.06

You WOULD need to find information on (if you were coding this):1. Output formatting

You WOULD be graded on (if you were coding this):1. Simplicity and attractiveness of data entry2. Simplicity and attractiveness of data output3. Correct calculations4. Document Professionalism (Document submitted should look like a Professional Document advertising yourself!)

Page 11: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/Python/PythonTop-DownDesign…  · Web viewworks in Java, Python, C++, etc… Overall Steps for Application Completion. Determine

TDD Spaghetti Code your TDD design is the perfect time to develop independent functions that can

be tested separately Spaghetti Code is a stretch of functions that require one another

Looking for a good designSpaghetti Independently testable functions

Watch your designSpaghetti Independently testable functions

Easy to follow

Easier to code

Easier to independently test

Page 12: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/Python/PythonTop-DownDesign…  · Web viewworks in Java, Python, C++, etc… Overall Steps for Application Completion. Determine

Steps for success1. Understand the problem2. Solve a sample problem3. Identify your functions (sub problems)4. break it up in a Top-Down Design5. Determine what the functions need (parameters)6. Determine what the functions will return 7. Combine into a final Top-Down Design8. Code!

Draw a Top-Down design for the Drywall Calculator

Required costs per job $100 for materials (tape, mud) $10 per outlet (for labor)

Costs determine by size of job: each sheet

o takes 15 minutes to install o and 45 minutes to mud, and sand (1 hr total)

$100 per hour

Single run program (won’t loop) must ask for:1. Current price per sheet of drywall (program will add 6% tax and assuming 4’x8’ sheet)2. height of room3. length (all walls added together) of room4. number of outlets in room

Program needs to display:1. number of sheets of drywall required2. Time needed to mud and sand3. Total cost for drywall4. Total cost for labor (hanging drywall, cutting out for outlets)5. Total overall cost

Page 13: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/Python/PythonTop-DownDesign…  · Web viewworks in Java, Python, C++, etc… Overall Steps for Application Completion. Determine

Formatting the top-down design into code of course there will be changes, but the overall design should still be there!! samples (drywall)

o sample 1 o sample 2

Answers1. printGreeting 2. printBoxPlot3. 24. functionCall5. Return from a function

Page 14: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/Python/PythonTop-DownDesign…  · Web viewworks in Java, Python, C++, etc… Overall Steps for Application Completion. Determine

Top-Down Design Example #1:

Page 15: faculty.cse.tamu.edufaculty.cse.tamu.edu/slupoli/notes/Python/PythonTop-DownDesign…  · Web viewworks in Java, Python, C++, etc… Overall Steps for Application Completion. Determine

Top-Down Design Example #2