Presentation is loading. Please wait.

Presentation is loading. Please wait.

CIS 338: Problem Solving Dr. Ralph D. Westfall April, 2011.

Similar presentations


Presentation on theme: "CIS 338: Problem Solving Dr. Ralph D. Westfall April, 2011."— Presentation transcript:

1 CIS 338: Problem Solving Dr. Ralph D. Westfall April, 2011

2 Programming Problems need to translate a problem into language a computer can understand translate from specifications written, verbal translate into an idea in your head what are we really trying to do here? translate into objects and code

3 Decompose the Problem identify application tiers and functions User Interface (UI) tier  inputs by/outputs to user, printer, etc. Data tier (if necessary)  files/layouts, database tables/fields  network connections (if necessary)

4 Decompose the Problem - 2 Business rules tier control structures – loops, decisions, etc. data structures: arrays, collections, etc. variables – inputs, outputs, temporary (with meaningful variable names) operations/processing: math (+,-, etc.), logical (compare), assignment (=), etc.

5 Translating write pseudocodepseudocode list of steps (recipe in human language) to solve problem pidgin code: mix of different computer languages pidgin code write code translate pseudocode (or pidgin code) into computer code for one language

6 Testing hand check your code go through with pencil and paper  1 line at a time with sample data look for harmful side effects does code destroy other data or disrupt a loop?'notes revise code and test again

7 Exercise follow the above steps with a programming problem for loops: 1. load 20 names in an array into a ListBox 2. calculate GPA multiply corresponding items in 2 parallel arrays (units and grade points) divide total grade points by total units

8 Exercise – 2: If Structures 1. display "low mileage car" when mileage is less than 50,000 2.display "low mileage" when less than 50,000, "OK mileage" for others 3. display the following "low" when mileage less than 50,000 "OK": between 50,000 and 99,999 "high": mileage 100,000 or more

9 Exercise - 3 if and loop together only prints item(s) from a 100-item array that have less than 100 calories in another array print the Index before the item to identify it IndexItem Calories 0BRAN FLAKES 90 1ALFALFA SEEDS 10 2ANGEL FOOD CAKE125 3etc.

10 Exercise - 4 do Exercise 3 again, using a 2- dimensional array with 100 rows and 2 columns assume that calories are Strings and either all have three digits or are left padded so that numeric comparisons are accurate

11 Random Problem Creation use the Random Phrase Generator to generate adjectives and nounsRandom Phrase Generator create a problem that selects subjects based on values of attributes partially (all?) random Google searches BananaSLUG takes your word and adds to it a word—randomly chosen from a selected category—to do a Google search BananaSLUG

12 Creating Random Problems what are the subjects (nouns) people: athletes, students, politicians, etc. dogs: guard, guide, working, toy, etc. what are the attributes (adjectives) people: age, height, gender, money, etc. dogs: weight, color, how much hair, etc. how many subjects have attributes: count, average, more than, etc.

13 Random Problem Example words: unhappy spider data: 3 parallel 20-item arrays with species, color and unhappiness of person bitten (0-9, 9 is unhappiest)colorbitten problems (data):data 1. count red spiders with ratings of 2 or less 2. average unhappiness for each color also see Discussion Board Midterm topic


Download ppt "CIS 338: Problem Solving Dr. Ralph D. Westfall April, 2011."

Similar presentations


Ads by Google