10
Lab 8 Basic Design and Documentation

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

Embed Size (px)

Citation preview

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

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

• 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

• 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

• 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

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

• 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

 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

• 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

• 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

• 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