COSC 235: Programming and Problem Solving
March 16, 2009

Joseph D. Sloan
sloanjd @ wofford.edu


Class Management Issues

Please report the amount of time spent on programming assignments -- planning, coding, debugging
Be sure to include appropriate comments in your code including your name and appropriate acknowledgements
Submit in the format as assigned
Email attachments should have your name as part of the file attachment's name
Submit Complete assignments for full credit
Submit whatever you have for partial credit
Be sure to acknowledge any help or outside sources you use
Be sure to pledge your work

Finish Extended Example

Extended Example

Graphics and GUI's

Review of Functions

Reasons to Use:
1. Organization & Design—Divide and Conquer
2. Replace Duplicated Actions—karaoke examples

Parameters
1. Formal and actual
2. Must pass everything you need (unless using global variable which you shouldn't)

Global variables
1, Very bad programming style
2. Don't use in this course
3. Typically, used only for very large data structures you don't want to copy

Returns
1. Last line of function & only one per function
2. In Python, can return single or multiple values as tuples
3. Used to change values

Aside 1: Tuples
Like list but immutable and uses parentheses rather than brackets

Aside 2: Update operators
1. +=, -=, *=, /=, and %=
2. Examples—x += 1 or y *= y + 2
3. Fully evaluate right side before applying to update
E.g., x *= 2 + 3 IS x = x * (2 + 3), NOT x = x * 2 + 3

Homework

Due Wednesday: update operator assignment & MC P192

Due Friday: Energy density calculator: The energy density of a food is the number of calories in a serving divided by the number of grams in a serving. For example, if a serving is 40 grams and has 150 calories, then the energy density is 3.75, (i.e., floating point division with 150 divided by 40). If you are trying to lose weight, you should eat foods with lower energy densities. Conversely, if you want to gain weight, then you should eat foods with higher energy densities. Write code to calculate energy densities using a GUI interface. Use the Celsius Converter in Section 5.7.2 as a model.


This page was created by Joe Sloan.
It was last modified around: 16 March 2009
Send mail to: sloanjd@wofford.edu