lab 8 basic design and documentation. learn about top-down design and how to document your code...
TRANSCRIPT
![Page 1: Lab 8 Basic Design and Documentation. Learn about top-down design and how to document your code properly. Look at a design diagram to figure out how to](https://reader036.vdocuments.net/reader036/viewer/2022083007/56649e8f5503460f94b9285c/html5/thumbnails/1.jpg)
Lab 8
Basic Design and Documentation
![Page 2: Lab 8 Basic Design and Documentation. Learn about top-down design and how to document your code properly. Look at a design diagram to figure out how to](https://reader036.vdocuments.net/reader036/viewer/2022083007/56649e8f5503460f94b9285c/html5/thumbnails/2.jpg)
• Learn about top-down design and how to document your code properly.
• Look at a design diagram to figure out how to break a large problem down into manageable sub-problems.
• Be able to program incrementally.
Goals
![Page 3: Lab 8 Basic Design and Documentation. Learn about top-down design and how to document your code properly. Look at a design diagram to figure out how to](https://reader036.vdocuments.net/reader036/viewer/2022083007/56649e8f5503460f94b9285c/html5/thumbnails/3.jpg)
• Change into the lab8 folder in your cs201/labs directory and create a lab8.py
cd 201/labscd lab8emacs lab8.py &
Step 0: Setup
![Page 4: Lab 8 Basic Design and Documentation. Learn about top-down design and how to document your code properly. Look at a design diagram to figure out how to](https://reader036.vdocuments.net/reader036/viewer/2022083007/56649e8f5503460f94b9285c/html5/thumbnails/4.jpg)
• Create a program which simulates a vending machine.
• Inventory:– Pepsi - Tortilla Chips - Mint Gum– Sprite - Knives - Bubble Gum– KoolAid - Forks - Doritos
• All inventory start at 5 items each.
Program Objectives
![Page 5: Lab 8 Basic Design and Documentation. Learn about top-down design and how to document your code properly. Look at a design diagram to figure out how to](https://reader036.vdocuments.net/reader036/viewer/2022083007/56649e8f5503460f94b9285c/html5/thumbnails/5.jpg)
Design Diagram
![Page 6: Lab 8 Basic Design and Documentation. Learn about top-down design and how to document your code properly. Look at a design diagram to figure out how to](https://reader036.vdocuments.net/reader036/viewer/2022083007/56649e8f5503460f94b9285c/html5/thumbnails/6.jpg)
• Write top-level functions• These are functions that are easy to take
care of without testing– printGreeting()– getValidInt ()
• On next slide– Write stubs for other necessary functions
Step 1
![Page 7: Lab 8 Basic Design and Documentation. Learn about top-down design and how to document your code properly. Look at a design diagram to figure out how to](https://reader036.vdocuments.net/reader036/viewer/2022083007/56649e8f5503460f94b9285c/html5/thumbnails/7.jpg)
def getValidInt(question, min, max):
# use a bad value to enter the loopvalue = max + 1
# compose the promptprompt = question + " (" + str(min) + "-" + str(max) + "): "
# continue to get values until the user enters a valid onewhile value == "" or value < min or value > max:
value = input(prompt)if len(value) != 0:
value = int(value)
# return a valid valuereturn value
getValidInt()
# Filename: getValidInt.py# Author: Sue Evans# Date: 8/9/09# Section: All# Email: [email protected]# Description: This program illustrates use of a while# loop to get values from the user within# a specified range, rejecting all bad input.# The function uses a post-test loop.
![Page 8: Lab 8 Basic Design and Documentation. Learn about top-down design and how to document your code properly. Look at a design diagram to figure out how to](https://reader036.vdocuments.net/reader036/viewer/2022083007/56649e8f5503460f94b9285c/html5/thumbnails/8.jpg)
• Go through the design diagram and determine the required functions along with the function parameters.
• Since each function is separate, independent testing can be (and should be) preformed before integrating it into the main program.
• Not all functions need to be complete to be able to run lab8.py– You accomplish this via a function stub.– At the end of the function, return nothing.
Filling in the Other Functions
![Page 9: Lab 8 Basic Design and Documentation. Learn about top-down design and how to document your code properly. Look at a design diagram to figure out how to](https://reader036.vdocuments.net/reader036/viewer/2022083007/56649e8f5503460f94b9285c/html5/thumbnails/9.jpg)
• 201 coding standards must be present for full credit.
# findCircleArea() calculates the area of a circle with the # radius passed in
# Input: the circle's radius# Output: the circle's areafindCircleArea():
return
Documentation: Function Headers
![Page 10: Lab 8 Basic Design and Documentation. Learn about top-down design and how to document your code properly. Look at a design diagram to figure out how to](https://reader036.vdocuments.net/reader036/viewer/2022083007/56649e8f5503460f94b9285c/html5/thumbnails/10.jpg)
• Fill in the other functions to make the rest of the vending machine to work appropriately.
• Correctly document your code with function headers and inline comments
• Lab completion will be based on how well designed your code is, not how complete it is
Completing the lab