1 / 13

CIS 338: Problem Solving

CIS 338: Problem Solving. Dr. Ralph D. Westfall April, 2011. 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?

Télécharger la présentation

CIS 338: Problem Solving

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 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

  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: • load 20 names in an array into a ListBox • 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 • display "low mileage car" when mileage is less than 50,000 • display "low mileage" when less than 50,000, "OK mileage" for others • 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 Index Item Calories 0 BRAN FLAKES 90 1 ALFALFA SEEDS 10 2 ANGEL FOOD CAKE 125 3 etc.

  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 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

  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) • problems (data): • count red spiders with ratings of 2 or less • average unhappiness for each color • also see Discussion Board Midterm topic

More Related