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

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

Dec 31, 2015

Download

Documents

Norah Jefferson
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CIS 338: Problem Solving Dr. Ralph D. Westfall April, 2011.

CIS 338: Problem Solving

Dr. Ralph D. WestfallApril, 2011

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

Programming Problems

need to translate a problem into language a computer can understandtranslate from specifications written, verbal

translate into an idea in your head what are we really trying to do here?

translate into objects and code

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

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/fieldsnetwork connections (if necessary)

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

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.

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

Translating

write pseudocode list of steps (recipe in human

language) to solve problem pidgin code: mix of different

computer languages

write code translate pseudocode (or pidgin code)

into computer code for one language

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

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

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

Exercise

follow the above steps with a programming problemfor 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

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

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

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

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

Index Item Calories0 BRAN FLAKES 90 1 ALFALFA SEEDS 102 ANGEL FOOD CAKE 1253 etc.

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

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

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

Random Problem Creation

use the Random Phrase Generator to generate adjectives and nouns 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

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

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.

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

Random Problem Example

words: unhappy spiderdata: 3 parallel 20-item arrays with species, color and unhappiness of person bitten (0-9, 9 is unhappiest)problems (data):1. count red spiders with ratings of 2 or less2. average unhappiness for each color

also see Discussion Board Midterm topic