1 / 12

UW CSE 190p Section

UW CSE 190p Section. 8 /9, Summer 2012 Dun-Yu Hsiao. Outlines. Data Abstraction Course Review Questions. Data Abstraction. Representing the essential features of something without including background or inessential detail.

arien
Download Presentation

UW CSE 190p Section

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. UW CSE 190p Section 8/9, Summer 2012 Dun-Yu Hsiao

  2. Outlines • Data Abstraction • Course Review • Questions

  3. Data Abstraction • Representing the essential features of something without including background or inessential detail. • The process of deciding which parts of the implementation that should be hidden.

  4. Ex1-Plotting Points • Given points data (‘euclidean’, x, y) in a text file, you want to plot the points: • Save each point as a tuple • Make all the points as a list • Print all the points • Plot them • What are the necessary functions?

  5. Plotting Points • Now the supplied input file changes its format, (‘euclidean’, x, y)  (‘polar’, r, theta) • Which part of the code will break?

  6. Plotting Points • Modify your code to accept the new type of data. • Note how many parts you need to change!

  7. Plotting Points • Now says your clients take the point data and implement the plot function by themselves. • You don’t want to bother them every time the input format is changed. • Can we reduce the amount of modification? • Evaluate the necessary components of each function. • What data can be abstract to concept?

  8. Plotting Points • Now the data format changes again: (‘polar’, r, theta)  (color, ‘polar’, r, theta) • Modify your code to accept the new type of data. • Note how many parts you need to change!

  9. Ex2-Fraction Operation • Input: tuples of (n,d) • You want to implement some basic fraction operation such as plus, product, and equal. • How would you plan the data and function to increase maintainability?

  10. Course Review • Manipulation with basic data types: • List, set, dictionary, number • List slice and comprehension • Integer/floating point calculation • If, for, function • English to code • Sequence of expression evaluation • Visualize stack environment • How do you test the program?

  11. Ex3-Calculate STD • English to code • Sequence of expression evaluation • Visualize stack environment • How do you test the program? import math Import numpy as np data = [ 1, 2, 3, 4, 3, 2, 3, 4] defmean ( input ): return sum(input)/float(len(input)) defsqr ( x ): return x*x defstd( input ): m = mean( input ) var = [ sqr(i-m) for i in input ] return math.sqrt( sum(var)/float(len(var)) ) mean(data) std(data) assert std(data) == np.std(data)

  12. Questions?

More Related